2016-09-28 70 views
1

我試圖做一個SOAPHEADER嵌套參數示例中顯示它由DHL的開發人員門戶:使得SOAPHEADER爲DHL

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
      xmlns:cis="http://dhl.de/webservice/cisbase" 
      xmlns:bcs="http://dhl.de/webservices/businesscustomershipping" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
<soap:Header> 
    <cis:Authentification> 
     <cis:user>2222222222_01</cis:user> 
     <cis:signature>pass</cis:signature> 
    </cis:Authentification> 
</soap:Header> 

的方式我做的頭:

class DhlSoapClient { 
public $apiUrl = 'https://cig.dhl.de/cig-wsdls/com/dpdhl/wsdl/geschaeftskundenversand-api/1.0/geschaeftskundenversand-api-1.0.wsdl'; 
public $dhlSandboxUrl = 'https://cig.dhl.de/services/sandbox/soap'; 
public $soapClient; 
public $credentials; 

public function buildClient($credentials, $sandbox = false) 
{ 
    $this->soapClient = new \SoapClient($this->apiUrl, ['trace' => 1]); 
    $this->credentials = $credentials; 
    $this->buildAuthHeader(); 
    return $this->soapClient; 
} 

public function buildAuthHeader() 
{ 
    $authParams = [ 
     'user' => $this->credentials['user'], 
     'signature' => $this->credentials['signature'], 
     'type' => 0 
    ]; 
    $authvalues = new \SoapVar(new \SoapVar($authParams, SOAP_ENC_OBJECT), SOAP_ENC_OBJECT); 
    $soapHeader = new \SoapHeader($this->dhlSandboxUrl, 'Authentification', $authvalues); 
    $this->soapClient->__setSoapHeaders($soapHeader); 
}} 

所以我得到這個客戶:

object(SoapClient) { 
trace => (int) 1 
_soap_version => (int) 1 
sdl => resource 
__default_headers => [ 
    (int) 0 => object(SoapHeader) { 
     namespace => 'https://cig.dhl.de/services/sandbox/soap' 
     name => 'Authentification' 
     data => object(SoapVar) { 
      enc_type => (int) 301 
      enc_value => object(SoapVar) { 
       enc_type => (int) 301 
       enc_value => [ 
        'user' => '2222222222_01', 
        'signature' => 'pass' 
       ]}}mustUnderstand => false}]} 

而作爲一個結果我得到這樣的標題:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
       xmlns:ns1="http://dhl.de/webservice/cisbase" 
       xmlns:ns2="http://de.ws.intraship" 
       xmlns:ns3="https://cig.dhl.de/services/sandbox/soap"> 
<SOAP-ENV:Header> 
    <ns3:Authentification> 
     <user>2222222222_01</user> 
     <signature>pass</signature> 
    </ns3:Authentification> 
</SOAP-ENV:Header> 

當我試圖讓$response = $this->client->CreateShipmentDD($shipmentInfo); 我得到這個:

object(SoapFault) { 
faultstring => 'Authorization Required' 
faultcode => 'HTTP' 
[protected] message => 'Authorization Required' 

也許問題是,參數用戶簽名身份驗證沒有前綴,因爲它必須是,它會導致SoapFault異常,但他們正在添加aut所以我必須做出一種嵌套SoapHeader

回答

0

我有同樣的問題。 Authorization Required用於HTTP身份驗證。您需要將授權值添加到SoapClient::__construct($wsdlUri, $options)中的$options陣列。

$this->soapClient = new \SoapClient($this->apiUrl, 
    ['trace' => 1, 
    'login' => <DHL_DEVELOPER_ID>, 
    'password' => <DHL_DEVELOPER_PASSWD>, 
    ] 
); 

您可以添加位置選擇沙箱:

$this->soapClient = new \SoapClient($this->apiUrl, 
    ['trace' => 1, 
    'login' => <DHL_DEVELOPER_ID>, 
    'password' => <DHL_DEVELOPER_PASSWD>, 
    'location' => <DHL_SANDBOX_URL>|<DHL_PRODUCTION_URL>, 
    'soap_version' => SOAP_1_1, 
    'encoding' => 'utf-8', 
    ] 
); 

DHL_DEVELOPER_ID不是郵件地址。你在「Mein Konto」(我的帳戶)中找到它。