使用 PHP WSDL 和 HTTP 身份验证的 SOAP 调用



我是编程初学者,在 soap 调用时遇到了问题。

我想从DHL获得64基货件标签。我通常使用Rest,但DHL在德国只有SOAP。

我收到此错误:

SOAP-ENV:服务器未捕获的 Soap故障异常: [soap:接收器] UNKNOWN_ERROR in/homepages/12/d573220848/htdocs/beta/dhl/index.php:90 堆栈跟踪:#0 /homepages/12/d573220848/htdocs/beta/dhl/index.php(90(: SoapClient->__soapCall('createShipmentO...', Array, Array( #1 {main} 扔

我认为身份验证有效

这是我作为客户端的php代码

$wsdl = 'https://cig.dhl.de/cig-wsdls/com/dpdhl/wsdl/geschaeftskundenversand-api/2.2/geschaeftskundenversand-api-2.2.wsdl';
  $params = array(
      'location' => "https://cig.dhl.de/services/sandbox/soap", 
      'uri' => "https://",
      'login' => "*userid*",
      'password' => "*secret_password*",
      'soap_version' => SOAP_1_2,
      'exceptions' => True,
      'trace' => 1
  );
  $client = new SoapClient($wsdl, $params);
  $header = new SoapHeader("https://cig.dhl.de/services/sandbox/soap", "authentication", "Basic [EDITED]"); 
  use_soap_error_handler(true);
  //Funktionen und Typen anfragen
  echo '<h3>Funktionen</h3>';
  $functions = $client->__getFunctions();
  foreach($functions as $d){
      echo "<br>".$d;
  }
  echo '<br><h3>Types</h3>';
  $types = $client->__getTypes();
  foreach($types as $t){
      echo "<br>".$t;
  }
  echo '<br><br>';

  $request = array(
      'CreateShipmentOrderRequest' => "1",
          'Version' => array(
          'majorRelease' => "2",
          'minorRelease' => "0"),
      'ShipmentOrder' => array(
      'SequenceNumber' => "01",
          'Shipment' => array(
          'ShipmentDetails' => array(
          'product' => "V01PAK",
          'accountNumber' => "22222222220101")))
  );
  //RESPONSE
  $response = $client ->__soapCall("createShipmentOrder", $request, $params);
  var_dump($response);
  echo '<br><br>';

我得到了所有的类型和功能,但没有要求。这是来自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>
    <soap:Body>
    ...
    </soap:Body>
</soap:Envelope>
Die Abrechnungsnummern müssen zusammen mit dem Produkt im SOAP-Body im Type "Shipment Details" eingetragen werden:
</soap:Header>
    <soap:Body>
        <bcs:CreateShipmentOrderRequest>
            <cis:Version>
                <cis:majorRelease>2</cis:majorRelease>
                <cis:minorRelease>0</cis:minorRelease>
            </cis:Version>
            <ShipmentOrder>
                <SequenceNumber>01</SequenceNumber>
                <Shipment>
                    <ShipmentDetails>
                        <product>V01PAK</product>
                        <cis:accountNumber>22222222220101</cis:accountNumber>

我能做些什么来让它投入工作?

我使用了您的代码的一部分,部分来自示例 DHL 并有结果. 我希望这对你有所帮助.我也有责任为DHL API开发SOAP客户端,如果您有更多关于此的示例或问题,我将不胜感激。示例数据获取版本请求 http://prntscr.com/i5jepf

$wsdl =  'https://cig.dhl.de/cig-wsdls/com/dpdhl/wsdl/geschaeftskundenversand-api/2.2/geschaeftskundenversand-api-2.2.wsdl';   
$sandbox = "https://cig.dhl.de/services/sandbox/soap";  
$user = "******";
$password = "*******";  
$options = array(
  'location' => $sandbox, 
  'uri' => "",
  'login' => $user,
  'password' => $password,
  'soap_version' => SOAP_1_1,
  'exceptions' => false,
  'trace' => 1
);  
$client = new SoapClient($wsdl,$options);   
$request ='Sample data getVersion install here';
$result = $client->__doRequest($request,$sandbox, 'getVersion',1);
if (is_soap_fault($result)) {
   trigger_error("Error SOAP: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
}   
var_dump($result);  
string(512) " 2 2 8 "

最新更新