[英]SOAP PHP request error
我正在使用第三方API來請求余額。 我在不同的嘗試中遇到許多錯誤,但我知道我已經接近了。 這是我的通話代碼...
<?php
try {
$wsdl_url = 'https://www.domain.com/SOAP?wsdl';
$UserID = 'UserID';
$Pwd= 'Password';
$client = new SOAPClient($wsdl_url);
$headerbody = array(
'UsernameToken'=>array('Username'=>$UserID,
'Password'=>$Pwd));
//Create Soap Header.
$header = new SOAPHeader('wsse', 'Security', $headerbody);
//set the Headers of Soap Client.
$client->__setSoapHeaders($header);
//$client->__getLastResponse();
$BalanceInquiryRequest->AccountNo="7777700020";
$BalanceInquiryRequest->RetailerId="0123";
$getBalance = $client->balanceInquiry($BalanceInquiryRequest);
print_r($getBalance);
} catch (SoapFault $fault) {
echo $fault->faultcode . "-" . $fault->faultstring;
//echo "REQUEST:\n" . htmlentities($client->__getLastRequest()) . "\n";
}
?>
輸出是...
env:Server-java.lang.NullPointerException
這是請求的xml ...
<soapenv:Envelope xmlns:req="http://domain.com" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="0" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-1">
<wsse:Username>Username</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">Password</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">5Ht+O9hKvAEXhNJZSTLg==</wsse:Nonce>
<wsu:Created>2012-03-27T15:31:01.792Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<req:BalanceInquiryRequest>
<req:AccountNo>7777700020</req:AccountNo>
<req:RetailerId>0123</req:RetailerId>
</req:BalanceInquiryRequest>
</soapenv:Body>
</soapenv:Envelope>
好的,問題是我的代碼中的WSSE是一個標准,不適用於PHP SOAPClient。 我做了一些研究,發現有幾種方法可以使這兩個很好地配合使用。 我要做的是首先確定名稱空間,用戶名和密碼...
$username = 'USERNAME';
$password = 'PASSWORD';
$strWSSENS = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
接下來是創建兩個處理此信息的類(在線獲得幫助)...
class clsWSSEAuth {
private $Username;
private $Password;
function __construct($username, $password) {
$this->Username=$username;
$this->Password=$password;
}
}
class clsWSSEToken {
private $UsernameToken;
function __construct ($innerVal){
$this->UsernameToken = $innerVal;
}
}
然后調用這幾個函數來設置標題等...
$objWSSEAuth = new clsWSSEAuth($objSoapVarUser, $objSoapVarPass);
$objSoapVarWSSEAuth = new SoapVar($objWSSEAuth, SOAP_ENC_OBJECT, NULL, $strWSSENS, 'UsernameToken', $strWSSENS);
$objWSSEToken = new clsWSSEToken($objSoapVarWSSEAuth);
$objSoapVarWSSEToken = new SoapVar($objWSSEToken, SOAP_ENC_OBJECT, NULL, $strWSSENS, 'UsernameToken', $strWSSENS);
$objSoapVarHeaderVal=new SoapVar($objSoapVarWSSEToken, SOAP_ENC_OBJECT, NULL, $strWSSENS, 'Security', $strWSSENS);
$objSoapVarWSSEHeader = new SoapHeader($strWSSENS, 'Security', $objSoapVarHeaderVal,true, 'http://abce.com');
然后剩下的一切都照常進行...使用SOAPClient ...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.