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

如何使用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条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?