【问题标题】:How to call soap api using php?如何使用php调用soap api?
【发布时间】:2014-04-26 05:53:48
【问题描述】:

我有以下肥皂响应。我如何使用 php.Any Idea 调用肥皂。提前致谢。

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Header xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/07/secext">
         <wsse:UsernameToken>
            <wsse:Username>XXXXXXXXXXXX</wsse:Username>
            <wsse:Password>XXXXXXXXXXXXXXXXX</wsse:Password>
         </wsse:UsernameToken>
      </wsse:Security>
   </soap:Header>
   <soapenv:Body>
      <cus1:GetCustomerDetailsRequest xmlns:cus1="XXXXXXXXXXXXXXXXXXXXXXX" xmlns:com="XXXXXXXXXXXXXXXXXXXXXXXX" xmlns:cus="XXXXXXXXXXXXXXXXX">
         <cus:GetCustomerDetails>
            <AccountMSISDN>1234567890</AccountMSISDN>
         </cus:GetCustomerDetails>
      </cus1:GetCustomerDetailsRequest>
   </soapenv:Body>
</soapenv:Envelope>

【问题讨论】:

标签: php xml web-services soap wsdl


【解决方案1】:

您应该能够通过使用这样的免费在线soap工具来玩转所需的字段、参数和方法:

http://www.soapclient.com/soaptest.html

另外,你应该看看这个答案:SOAP request in PHP with CURL

【讨论】:

    【解决方案2】:
    $soapUrl = "http://www.example.com/masterdata/masterdata.asmx?wsdl";
    
    $soapUser = "username";  //  username
    
    $soapPassword = "password"; // password
    
    // xml post structure
    
    $xml_post_string = 'soap string';   // data from the form, e.g. some ID number
    
    $headers = array(
              "Content-type: text/xml;charset=\"utf-8\"",
              "Accept: text/xml",
              "Cache-Control: no-cache",
              "Pragma: no-cache",
              "SOAPAction: http://tempuri.org/GetMasterData", 
              "Content-length: ".strlen($xml_post_string),
          ); //SOAPAction: your op URL
    
    $url = $soapUrl;
    
    // PHP cURL  for https connection with auth
    $ch = curl_init();
    
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
    
    curl_setopt($ch, CURLOPT_URL, $url);
    
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
    curl_setopt($ch, CURLOPT_USERPWD, $soapUser.":".$soapPassword); // username and password - declared at the top of the doc
    
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
    
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    
    curl_setopt($ch, CURLOPT_POST, true);
    
    curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request
    
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    
    // converting
    $response = curl_exec($ch); 
    
    curl_close($ch);
    
        // a new dom object 
     $dom = new domDocument('1.0', 'utf-8'); 
    
     // load the html into the object 
     $dom->loadXml($response);         
    
     $array = json_decode($dom->textContent,TRUE);
    
      print_r($array);
    

    【讨论】:

    • 我已经尝试过您的方法,但无法获得想要的结果,您可以看看我的question吗?
    猜你喜欢
    • 2012-10-28
    • 2023-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-26
    相关资源
    最近更新 更多