我正在尝试与第三方API集成,并且它们的API仅支持SOAP请求。他们在文档中有此样本。我所需要做的就是替换agentcode和mpin。请我帮我写一个PHP代码,以使用SOAP请求将以下格式发送到此链接http://202.140.50.116/EstelServices/services/EstelServices?wsdl
<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>
这里是我到目前为止所做的尝试
$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);
答案 0 :(得分:2)
使用此简单脚本,可以为您提供足够的信息。函数和类型列表将帮助您进行正确的SOAP调用:
<?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 :(得分:0)
与服务WSDL一起使用PHP本机SoapClient:
$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.