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

如何使用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>';
    }   
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况