我正在尝试使用嵌套参数制作一个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'可能问题是Authentification中的参数用户和signature没有前缀,这会导致SoapFault异常,但它们是自动添加的,所以我不得不做某种嵌套的SoapHeader。
发布于 2017-06-26 12:03:20
我也有同样的问题。Authorization Required用于HTTP。您需要将授权值添加到$options数组的SoapClient::__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不是邮件地址。你可以在“我的账户”(我的账户)里找到它。
https://stackoverflow.com/questions/39752669
复制相似问题