doushou9028
2018-12-21 07:51
浏览 206
已采纳

如何使用PHP发送此SOAP请求

I'm trying to integrate with a third party API and their API accpets only SOAP requests. They have this sample in their documentation. All I need is to replace the agentcode and mpin. Pls I need some one to help me write a PHP code to send the below format to this link http://202.140.50.116/EstelServices/services/EstelServices?wsdl using SOAP request

<soapenv:Envelope 
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:ser="http://services.estel.com" 
xmlns:bal="http://balance.support.services.estel.com">
   <soapenv:Header/>
   <soapenv:Body>
      <ser:getBalance>
         <ser:balanceRequest>
            <bal:agentCode>TPR_CM</bal:agentCode>
            <bal:mpin>EE17F932B3C311E8877F999DD7865E11</bal:mpin>
         </ser:balanceRequest>
      </ser:getBalance>
   </soapenv:Body>
</soapenv:Envelope> 

Heres what I have tried so far

        $xml = '<?xml version="1.0" encoding="utf-8"?>'.
            '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.estel.com" xmlns:bal="http://balance.support.services.estel.com">'.
            '<soapenv:Header/>'.
            '<soapenv:Body>'.
            '<ser:getBalance>'.
                '<ser:balanceRequest>'.
                    '<bal:agentCode>TPR_CM</bal:agentCode>'.
                    '<bal:mpin>EE17F932B3C311E8877F999DD7865E11</bal:mpin>'.
                '</ser:balanceRequest>'.
            '</ser:getBalance>'.
            '</soapenv:Body>'.
        '</soapenv:Envelope>';

    $url = "http://balance.support.services.estel.com";

    $soap_do = curl_init();
    curl_setopt($soap_do, CURLOPT_URL,            $url );
    curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
    curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($soap_do, CURLOPT_POST,           true );
    curl_setopt($soap_do, CURLOPT_POSTFIELDS,    $xml);

    $result = curl_exec($soap_do);
    $err = curl_error($soap_do);
    var_dump($result);
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dpsq8476 2018-12-21 08:34
    已采纳

    Use this simple script, which gives you enough information. Function and type lists will help you to make correct SOAP call:

    <?php
    // SOAP
    $soap = new SoapClient("http://202.140.50.116/EstelServices/services/EstelServices?wsdl");
    
    // List functions
    echo 'Functions: '.'</br>';
    $functions = $soap->__getFunctions();
    foreach($functions as $item) {
        echo $item.'</br>';
    }
    echo '</br>';
    
    // List types
    echo 'Types: '.'</br>';
    $types = $soap->__getTypes();
    foreach($types as $item) {
        echo $item.'</br>';
    }
    echo '</br>';
    
    // Consume SOAP
    $params = array(
        "balanceRequest" => array(
            "agentCode" => "TPR_CM",
            "mpin" => "EE17F932B3C311E8877F999DD7865E11"
        )              
    );   
    
    // Consume SOAP
    $responce = $soap->getBalance($params);
    foreach($responce->getBalanceReturn as $name => $value) {
       echo $name.': '.$value.'<br>';
    }   
    ?>
    
    已采纳该答案
    打赏 评论
  • dqwh1219 2018-12-21 08:25

    Use the PHP native SoapClient along with the service WSDL:

    $atservices_wsdl = "http://202.140.50.116/EstelServices/services/EstelServices?wsdl";
    $atservices_client = new SoapClient($atservices_wsdl);
    
    $balance = $atservices_client->getBalance("TPR_CM","EE17F932B3C311E8877F999DD7865E11");
    
    print_r($balance); // review the returned object converted from SOAP response.
    
    打赏 评论

相关推荐 更多相似问题