duanbei1709 2018-01-01 14:45
浏览 208

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

I am a beginner in programming and have a problem with a soap call.

I would like to get 64based shipment labels from DHL. I usually work with Rest but DHL do only has SOAP in Germany.

I get this error:

SOAP-ENV:ServerUncaught SoapFault exception: [soap:Receiver] UNKNOWN_ERROR in /homepages/12/d573220848/htdocs/beta/dhl/index.php:90 Stack trace: #0 /homepages/12/d573220848/htdocs/beta/dhl/index.php(90): SoapClient->__soapCall('createShipmentO...', Array, Array) #1 {main} thrown

authentication works I think

Here is the php code from me as client

$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>';

I get all the types and functions, but no request. This is from documentary of 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>

What can I do to bring it to work?

  • 写回答

1条回答 默认 最新

  • douyou2234 2018-01-25 18:24
    关注

    I used part from your code, part from example DHL and have result . I hope this help you . I too have task of development SOAP client for DHL API and if you have more example or question about this I will be thankful. Sample data getVersion request 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 "
    
    评论

报告相同问题?

悬赏问题

  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥30 用arduino开发esp32控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题