0
我需要使用PHP中的wsdl將請求數據發送到SOAP API。我已經安裝了soapclient擴展爲PHP,它工作正常。下面是該腳本:使用wsdl無法正常工作的PHP SOAP請求,它給了我一個錯誤「SOAP-ERROR:編碼:對象沒有'phoneNumber'屬性」
<?php
$client = new SoapClient($wsdlUrl, array('username' => USER_NAME, 'password' => PASSWORD,'trace'=>'1','exception'=>0));
$method = "templateSMS";
$xmlr = new SimpleXMLElement("<Sms></Sms>");
$xmlr->addChild("phoneNumber",PHONE_NUMBER);
$xmlr->addChild('message', 'Hi how are you');
$xmlr->addChild('unicodeMessage', 0);
$xmlr->addChild('sms_type_id', 1);
$xmlr->addChild('senderId', SENDER_ID);
$xmlr->addChild('notify', 0);
$xmlr->addChild('priority', 1);
$xmlr->addChild('vbApp', 'SoapRequest');
$xmlr->addChild('vbIdTime', time());
$params = new stdClass();
$params->xml = $xmlr->asXML();
try {
$data = $client->$method($params);
var_dump($data);
}catch (SoapFault $e) {
echo "<pre> Exceptions Break :";
print_r($e);
echo "</pre>";
}
?>
當我在瀏覽器上面的代碼運行它給我一個錯誤「SOAP的錯誤:編碼:對象沒有‘phoneNumber的’屬性」
以下是錯誤日誌,可能更有益的解決我的問題:
Exceptions Break :SoapFault Object
(
[message:protected] => SOAP-ERROR: Encoding: object has no 'phoneNumber' property
[string:Exception:private] =>
[code:protected] => 0
[file:protected] => C:\xampp\htdocs\soapDemo\opt3.php
[line:protected] => 18
[trace:Exception:private] => Array
(
[0] => Array
(
[file] => C:\xampp\htdocs\soapDemo\opt3.php
[line] => 18
[function] => __call
[class] => SoapClient
[type] => ->
[args] => Array
(
[0] => templateSMS
[1] => Array
(
[0] => stdClass Object
(
[xml] =>
Hi how are you0101SoapRequest1480835353
)
)
)
)
[1] => Array
(
[file] => C:\xampp\htdocs\soapDemo\opt3.php
[line] => 18
[function] => templateSMS
[class] => SoapClient
[type] => ->
[args] => Array
(
[0] => stdClass Object
(
[xml] =>
Hi how are you0101SoapRequest1480835353
)
)
)
)
[previous:Exception:private] =>
[faultstring] => SOAP-ERROR: Encoding: object has no 'phoneNumber' property
[faultcode] => Client
[faultcodens] => http://schemas.xmlsoap.org/soap/envelope/
)
支持團隊給了我一個示例XML代碼傳遞請求格式,這裏是示例XML請求格式,請求應該是相同的,如下:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:templateSMS" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="urn:ElbaridTNS" xmlns:ns3="namespace" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Header>
<ns3:AuthHeader>
<username>username </username>
<password>password</password>
</ns3:AuthHeader>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:templateSMS>
<Sms xsi:type="ns2:Sms"><phoneNumber xsi:type="xsd:string">xxxxxx</phoneNumber>
<message xsi:type="xsd:string">test SMS </message>
<unicodeMessage xsi:type="xsd:string">test SMS</unicodeMessage>
<sms_type_id xsi:type="xsd:string">1</sms_type_id>
<notify xsi:type="xsd:string">0</notify>
<senderId xsi:type="xsd:string">SenderId</senderId>
<priority xsi:type="xsd:string">2</priority>
<vbApp xsi:type="xsd:string">SoapRequest</vbApp>
<vbIdTime xsi:type="xsd:string">20161130101112</vbIdTime>
<destinationPort xsi:type="xsd:string">-1</destinationPort></Sms>
</ns1:templateSMS>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
響應應該是這樣的:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:templateSMS" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:templateSMSResponse>
<templateSMSResponse xsi:type="xsd:string">0#!#200#!#http://198.101.210.203/Soap/service/elbarid|http://212.98.137.180/Soap/service/elbarid#!#SenderId </templateSMSResponse>
</ns1:templateSMSResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
誰能幫助我解決我的問題?我也嘗試與捲曲,但我得到相同的錯誤迴應。
謝謝:)
感謝迴應.... 不過還是我收到同樣的錯誤:SOAP的錯誤:編碼:對象沒有「phoneNumber的」屬性 – JGandhi