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


send soap request for dpd.com in php

我正在尝试从dpd.com获取发货标签。为此,我需要使用soap来完成任务。我已经完成了登录验证并获得了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;
?>