php - 在 php 中为 dpd.com 发送 soap 请求

标签 php xml soap-client dpd

我正在尝试从 dpd.com 获取运输标签。为此,我需要使用肥皂来完成任务。我已经完成登录认证并获得了AuthToken。 这是相关代码。

<?php
$c = new SoapClient('https://public-ws-stage.dpd.com/services/LoginService/V2_0/?WSDL');
$res = $c->getAuth(array(
    'delisId' => 'username',
    'password' => 'password',
    'messageLanguage' => 'en-us',
));
$authToken = $res->return->authToken;

现在,问题是我想通过发送请求并使用此 AuthToken 来获取发货标签。 soap 请求的格式是这样的。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                  xmlns="http://dpd.com/common/service/types/Authentication/2.0"
                  xmlns1="https://public-ws-stage.dpd.com/services/ShipmentService/V3_2/?wsdl">
    <soapenv:Header>
        <ns:authentication>
            <delisId>username</delisId>
            <authToken>AuthToken From Above</   authToken>
            <messageLanguage>en-us</messageLanguage>
        </ns:authentication>
    </soapenv:Header>
    <soapenv:Body>
        <ns1:storeOrders>
            <paperFormat>A4</paperFormat>
            <order>
                <generalShipmentData>
                    <sendingDepot>'.$depot_num.'</sendingDepot>
                    <product>CL</product>
                    <mpsCompleteDeliver>false</mpsCompleteDeliver>
                    <sender>
                        <name1>Fritz</name1>
                        <street>Mustergasse</street>
                        <houseNo>1</houseNo>
                        <state>BY</state>
                        <country>DE</country>
                        <zipCode>53950</zipCode>
                        <city>Maibach</city>
                    </sender>
                    <recipient>
                        <name1></name1>
                        <street></street>
                        <houseNo></houseNo>
                        <state></state>
                        <country></country>
                        <zipCode></zipCode>
                        <city></city>
                        </recipient>
                </generalShipmentData>
                <parcels>
                    <parcelLabelNumber></parcelLabelNumber>
                </parcels>
                <productAndServiceData>
                    <orderTyp></orderType>
                </productAndServiceData>
            </order>
        </ns1:storeOrdes>
    </soapenv:Body> 
</soapenv:Envelope>

但我不知道如何发送这个请求并在 pdfData 标签中获得响应。

最佳答案

我看到这个问题很旧,但其他人也可以搜索它。 来自http://labor.99grad.de/2014/10/05/deutscher-paket-dienst-dpd-soap-schnittstelle-mit-php-nutzen-um-versandetikett-als-pdf-zu-generieren/的回答

<?php

   // Einloggen

   $c = new SoapClient('https://public-ws-stage.dpd.com/services/LoginService/V2_0?wsdl');

   $res = $c->getAuth(array(
      'delisId'          => 'your-Id',
      'password'         => 'your-Password',
      'messageLanguage'   => 'de_DE'
   ));

   // ...und das Token merken
   $auth = $res->return;


   // Jetzt das Label generieren:

   $c = new SoapClient('https://public-ws-stage.dpd.com/services/ShipmentService/V3_1?wsdl');

   $token = array(
      'delisId'         => $auth->delisId,
      'authToken'         => $auth->authToken,
      'messageLanguage'   => 'de_DE'
   );

   // Set the header with the authentication token
   $header = new SOAPHeader('http://dpd.com/common/service/types/Authentication/2.0', 'authentication', $token);
   $c->__setSoapHeaders($header);

   try {
      $res = $c->storeOrders( array
         (
            "printOptions" => array(
               "paperFormat" => "A4",
               "printerLanguage" => "PDF"
            ),
            "order" => array(
               "generalShipmentData" => array(
                  "sendingDepot" => $auth->depot,
                  "product" => "CL",
                  "mpsCompleteDelivery" => false,
                  "sender" => array(
                     "name1" => "Sender Name",
                     "street" => "Sender Street 2",
                     "country" => "DE",
                     "zipCode" => "65189",
                     "city" => "Wiesbaden",
                     "customerNumber" => "123456789"
                  ),
                  "recipient" => array(
                     "name1" => "John Malone",
                     "street" => "Johns Street 34",
                     "country" => "DE",
                     "zipCode" => "65201",
                     "city" => "Wiesbaden"
                  )
               ),
               "parcels" => array(
                  "parcelLabelNumber" => "09123829120"
               ),
               "productAndServiceData" => array(
                  "orderType" => "consignment"
               )
            )
         )
      );
   } catch (SoapFault $exception) {
      echo $exception->getMessage();
      die();
   }

   // Et voilà!

   header('Content-type: application/pdf');
   echo $res->orderResult->parcellabelsPDF;
?>

关于php - 在 php 中为 dpd.com 发送 soap 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37065407/

相关文章:

php - 小数点价格到 32 位价格

php - 多个数据库连接的多个数据库用户

javascript - 如何阻止第三方使用的node js服务器地址和端口

php - strtotime 可以处理分数吗?

c# - 如何最小起订量 Amazon MWS 的响应以进行单元测试

javascript - HTML/PHP 表单到 XML

c# - 将 XML 写入内存而不是磁盘

c# - .NET 中的 SOAP 客户端 - 引用或示例?

php - 内存分配失败 : growing buffer on PHP, SoapClient

Bing API 的 Java 应用程序