首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在php中发送dpd.com的soap请求

在php中发送dpd.com的soap请求
EN

Stack Overflow用户
提问于 2016-05-06 14:05:41
回答 1查看 2.2K关注 0票数 3

我正在试着从dpd.com那里拿到运输标签。为此,我需要使用soap来完成任务。我已经完成了登录验证并获得了AuthToken。这是它的代码。

代码语言:javascript
复制
<?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请求的格式是这样的。

代码语言:javascript
复制
<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标签中的响应。

EN

回答 1

Stack Overflow用户

发布于 2017-08-02 18:39:58

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

代码语言:javascript
复制
<?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;
?>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37065407

复制
相关文章

相似问题

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