首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DHL的SoapHeader制作

DHL的SoapHeader制作
EN

Stack Overflow用户
提问于 2016-09-28 16:11:48
回答 1查看 2.6K关注 0票数 0

我正在尝试使用嵌套参数制作一个soapHeader,如dhl开发人员门户中的一个示例所示:

代码语言:javascript
复制
<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>

我做标题的方式:

代码语言:javascript
复制
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);
}}

所以我得到了这个客户:

代码语言:javascript
复制
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}]}

因此,我得到了这个标题:

代码语言:javascript
复制
<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);时,我得到了这样的信息:

代码语言:javascript
复制
object(SoapFault) {
faultstring => 'Authorization Required'
faultcode => 'HTTP'
[protected] message => 'Authorization Required'

可能问题是Authentification中的参数用户signature没有前缀,这会导致SoapFault异常,但它们是自动添加的,所以我不得不做某种嵌套的SoapHeader

EN

回答 1

Stack Overflow用户

发布于 2017-06-26 12:03:20

我也有同样的问题。Authorization Required用于HTTP。您需要将授权值添加到$options数组的SoapClient::__construct($wsdlUri, $options)中。

代码语言:javascript
复制
$this->soapClient = new \SoapClient($this->apiUrl, 
    ['trace' => 1,
    'login' => <DHL_DEVELOPER_ID>,
    'password' => <DHL_DEVELOPER_PASSWD>,
    ]
);

您可以添加选择沙箱的位置:

代码语言:javascript
复制
$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不是邮件地址。你可以在“我的账户”(我的账户)里找到它。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39752669

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档