2
我正在嘗試與eWay服務器進行通信,並且一切正常,直到我們需要切換到其他API。問題是SoapClient正在爲頭部(包括身份驗證)創建一個不同的名稱空間,然後從身體,這顯然,沒有得到任何結果。相反,我得到eWay的服務器說它必須有認證信息。爲什麼PHP的SoapClient爲標題創建一個不同於名稱空間的名稱空間?
這裏是我的代碼:
$client = new SoapClient($url.'?WSDL', array('trace'=>TRUE));
// Set our SOAP Headers for authentication
$header_body = array(
'eWAYCustomerID' => $gateway['customer_id'],
'Username' => $gateway['username'],
'Password' => $gateway['password']
);
$header_var = new SoapVar($header_body, SOAP_ENC_OBJECT);
$header = new SOAPHeader('http://www.eway.com.au/gateway/managedpayment', 'eWAYHeader', $header_body);
//$client->__setSoapHeaders($header);
try {
$response = $client->__soapCall($action, $xml, null, $header);
} catch (SoapFault $e)
{
echo 'SOAP Fault: '. $e->getMessage()."<br>\n";
}
正如你所看到的,我已經使用和不使用SoapVar頁眉試了一下,都沒有運氣。
這裏是正在創建XML請求:
<soap-env:envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="https://www.eway.com.au/gateway/managedpayment" xmlns:ns2="http://www.eway.com.au/gateway/managedpayment">
<soap-env:header>
<ns2:ewayheader>
<ewaycustomerid>87654321</ewaycustomerid>
<username>[email protected]</username>
<password>test123</password>
</ns2:ewayheader>
</soap-env:header>
<soap-env:body>
<ns1:createcustomer>...</ns1:createcustomer>
你有解決方案嗎? – 2014-07-23 11:26:37