0

I'm trying to make a soapHeader with nested parameters as it shown in an example from dhl developer portal:

<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>

The way I do the 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);
}}

So I get this client:

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}]}

And as a result I get this header:

<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>

As I try to get $response = $this->client->CreateShipmentDD($shipmentInfo); I get this:

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

Maybe the problem is that parameters user and signature inside Authentification have no prefix as it has to be and it cause the SoapFault exception, but they are adding automatically so I have to make kind of nested SoapHeader.

4

1 回答 1

1

我有同样的问题。Authorization Required用于 HTTP 身份验证。您需要将授权值添加$optionsSoapClient::__construct($wsdlUri, $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”(我的帐户)中找到它。

于 2017-06-26T12:03:20.867 回答