PHP SOAP,如何请求这个

时间:2013-10-16 17:12:25

标签: php soap wsdl

这里是思考,我可以先成功请求,这给了我一个ID,我必须使用这个ID作第二个请求,但第二个怎么办?

 try {
    $clienteSOAP = new SoapClient ( 'someservicehere' );
    $header = array('Username' => 'user', 'Password' => 'pass', 'DeviceType'=> 3,'Platform'=>'1');
    $response = $clienteSOAP->GetSession($header);
    //echo $response->SessionID:
    //15987451
    $header2 = array('Username' => 'user', 'Password' => 'pass','SessionID' => '15987451' , 'DeviceType'=> 3,'Platform'=>'1');
    $clienteSOAP->GetBalance($header2);
    //GetBalance throws error,
 } catch ( SoapFault $e ) {
    var_dump ( $e );
 }

GetSession的xml,这很棒!!!

 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ext="someTextHere">
    <soapenv:Header/>
    <soapenv:Body>
       <ext:GetSessionRequest>
          <ext:Username></ext:Username>
          <ext:Password></ext:Password>
          <ext:DeviceType></ext:DeviceType>
          <!--Optional:-->
          <ext:Platform></ext:Platform>
       </ext:GetSessionRequest>
    </soapenv:Body>
 </soapenv:Envelope>

但为此,怎么样?

 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ext="SomeTextHereToo">
    <soapenv:Header/>
    <soapenv:Body>
       <ext:GetBalanceRequest>
          <ext:AuthenticationData>
             <!--Optional:-->
             <ext:Username></ext:Username>
             <!--Optional:-->
             <ext:Password></ext:Password>
             <!--Optional:-->
             <ext:SessionID></ext:SessionID>
          </ext:AuthenticationData>
          <ext:DeviceType></ext:DeviceType>
          <!--Optional:-->
          <ext:Platform></ext:Platform>
       </ext:GetBalanceRequest>
    </soapenv:Body>
 </soapenv:Envelope>

1 个答案:

答案 0 :(得分:1)

您必须将身份验证数据包装在一个单独的数组中,在第二个定义中,还有一个包含身份验证凭据的附加元素()。

这应该有效:

try {
   $clienteSOAP = new SoapClient ('someservicehere');
   $header = array('Username' => 'user', 'Password' => 'pass', 'DeviceType'=> 3,'Platform'=>'1');
   $response = $clienteSOAP->GetSession($header);
   $header2 = array('AuthenticationData' => array(
                        'Username' => 'user',
                        'Password' => 'pass',
                        'SessionID' => '15987451'
                    ),
                    'DeviceType'=> 3,
                    'Platform'=>'1'
               );
   $clienteSOAP->GetBalance($header2);
} catch (SoapFault $e) {
   var_dump ($e);
}

由于用户名,密码和sessionid都是可选的,我猜您可以使用用户名和密码或sessionid进行身份验证。因此,您可能不必在第二次调用中提供用户名和密码。