Ответ API myDHL - PullRequest
       20

Ответ API myDHL

0 голосов
/ 22 апреля 2020

Я работаю с myDHL API и получаю странный ответ от их API. Их поддержка бесполезна, поэтому нужна помощь здесь.

Мой запрос XML:

<?xml version="1.0" encoding="UTF-8"?>
<ShipmentRequest xsi:noNamespaceSchemaLocation="ShipmentMsgRequest.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <shipreq:ShipmentRequest>
        <RequestedShipment>
            <ShipmentInfo>
                <DropOffType>REGULAR_PICKUP</DropOffType>
                <ServiceType>U</ServiceType>
                <Account>12345</Account>
                <Currency>USD</Currency>
                <UnitOfMeasurement>SI</UnitOfMeasurement>
                <PackagesCount >1</PackagesCount>
                <LabelType>PDF</LabelType>
                <LabelTemplate>ECOM26_84_001</LabelTemplate>
            </ShipmentInfo>
            <ShipTimestamp></ShipTimestamp>
            <PaymentInfo>DAP</PaymentInfo>
            <InternationalDetail>
                <Commodities>
                    <NumberOfPieces>1</NumberOfPieces>
                    <Description>1</Description>
                    <Quantity>1</Quantity>
                    <CustomsValue>1.00</CustomsValue>
                </Commodities>
                <Content>1</Content>
            </InternationalDetail>
            <Ship>
                <Shipper>
                    <Contact>
                        <PersonName>test</PersonName>
                        <CompanyName>test1</CompanyName>
                        <PhoneNumber>34324324</PhoneNumber>
                    </Contact>
                    <Address>
                        <StreetLines>address test/StreetLines>
                        <City>Singapore</City>
                        <PostalCode>343333</PostalCode>
                        <CountryCode>SG</CountryCode>
                    </Address>
                </Shipper>
                <Recipient>
                    <Contact>
                        <PersonName>John</PersonName>
                        <CompanyName>ABC Worldwide</CompanyName>
                        <PhoneNumber>1234567</PhoneNumber>
                    </Contact>
                    <Address>
                        <StreetLines>Private Bag 92019.Auckland Mail Centre.</StreetLines>
                        <City>Auckland</City>
                        <PostalCode>1011</PostalCode>
                        <CountryCode>NZ</CountryCode>
                    </Address>
                </Recipient>
            </Ship>
            <Packages><RequestedPackages number=1>
                    <InsuredValue>1.00</InsuredValue>
                    <Weight>1.00</Weight>
                    <Dimensions>
                        <Length>1</Length>
                        <Width>1</Width>
                        <Height>1</Height>
                    </Dimensions>
                    <CustomerReferences>2313700</CustomerReferences>
                </RequestedPackages></Packages>
        </RequestedShipment>
    </shipreq:ShipmentRequest>

Я также помещаю заголовок как

             <wsse:UsernameToken wsu:Id="Example">
             <wsse:Username>test</wsse:Username>
            <wsse:Password Type="wsse:PasswordText">test1</wsse:Password>
            <wsu:Created>2020-04-21T14:10:50Z</wsu:Created>';
            </wsse:UsernameToken>

URL я использую это https://wsbexpress.dhl.com: 443 / sndpt / expressRateBook

Я использую curl и помещаю запрос и заголовок как

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
curl_setopt($ch,CURLOPT_HEADER,true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $strRequest)
$result = curl_exec($ch);

Я получаю ответ как

HTTP/1.1 100 Continue

HTTP/1.1 500 Internal Server Error
Date: Tue, 21 Apr 2020 11:18:38 GMT
Server: 
Content-Length: 2122
Connection: close
X-CorrelationID: Id-8ed69e5e114fd399f8bb6d1d 0
Accept: */*
ClientSide: 202.47.35.205
Content-Type: application/x-www-form-urlencoded
Set-Cookie: BIGipServer~WSB~pl_wsb-express-chd.dhl.com_443=292047013.64288.0000; path=/; Httponly; Secure

<?xml version="1.0" encoding="UTF-8"?>
<ShipmentRequest xsi:noNamespaceSchemaLocation="ShipmentMsgRequest.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <shipreq:ShipmentRequest>
        <RequestedShipment>
            <ShipmentInfo>
                <DropOffType>REGULAR_PICKUP</DropOffType>
                <ServiceType>U</ServiceType>
                <Account>12345</Account>
                <Currency>USD</Currency>
                <UnitOfMeasurement>SI</UnitOfMeasurement>
                <PackagesCount >1</PackagesCount>
                <LabelType>PDF</LabelType>
                <LabelTemplate>ECOM26_84_001</LabelTemplate>
            </ShipmentInfo>
            <ShipTimestamp></ShipTimestamp>
            <PaymentInfo>DAP</PaymentInfo>
            <InternationalDetail>
                <Commodities>
                    <NumberOfPieces>1</NumberOfPieces>
                    <Description>1</Description>
                    <Quantity>1</Quantity>
                    <CustomsValue>1.00</CustomsValue>
                </Commodities>
                <Content>1</Content>
            </InternationalDetail>
            <Ship>
                <Shipper>
                    <Contact>
                        <PersonName>test</PersonName>
                        <CompanyName>test1</CompanyName>
                        <PhoneNumber>34324324</PhoneNumber>
                    </Contact>
                    <Address>
                        <StreetLines>address test/StreetLines>
                        <City>Singapore</City>
                        <PostalCode>343333</PostalCode>
                        <CountryCode>SG</CountryCode>
                    </Address>
                </Shipper>
                <Recipient>
                    <Contact>
                        <PersonName>John</PersonName>
                        <CompanyName>ABC Worldwide</CompanyName>
                        <PhoneNumber>1234567</PhoneNumber>
                    </Contact>
                    <Address>
                        <StreetLines>Private Bag 92019.Auckland Mail Centre.</StreetLines>
                        <City>Auckland</City>
                        <PostalCode>1011</PostalCode>
                        <CountryCode>NZ</CountryCode>
                    </Address>
                </Recipient>
            </Ship>
            <Packages><RequestedPackages number=1>
                    <InsuredValue>1.00</InsuredValue>
                    <Weight>1.00</Weight>
                    <Dimensions>
                        <Length>1</Length>
                        <Width>1</Width>
                        <Height>1</Height>
                    </Dimensions>
                    <CustomerReferences>2313700</CustomerReferences>
                </RequestedPackages></Packages>
        </RequestedShipment>
    </shipreq:ShipmentRequest>

Я даже пытался использовать класс Soap, используя запрос ниже

$request=<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
   <soap:Header><wsse:Security soapenv:mustunderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
         <wsse:UsernameToken wsu:id = "UsernameToken-5" xmlns:wsu = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" >   
            <wsse:Username > test</wsse:Username >           
            <wsse:Password type = "PasswordText" >test</wsse:Password>
            <wsse:Nonce encodingtype = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" > eUYebYfsjztETJ4Urt8AJw ==</wsse:Nonce >
            <wsu:Created > 2020 - 04 - 24 20:17:21 </wsu:Created >
         </wsse:UsernameToken >
      </wsse:Security >
</soap:Header>
   <soap:Body>
      <ShipmentRequest xmlns="http://scxgxtt.phx-dc.dhl.com/euExpressRateBook/ShipmentMsgRequest">
         <MessageId xmlns="">c68d7150bbd611e2b09ad103c98eed12</MessageId>
         <ClientDetail xmlns=""/>
         <RequestedShipment xmlns="">
            <ShipmentInfo>
               <DropOffType>REGULAR_PICKUP</DropOffType>
               <ServiceType>P</ServiceType>
               <Account>4324324324</Account>
               <Currency>EUR</Currency>
               <UnitOfMeasurement>SI</UnitOfMeasurement>
            </ShipmentInfo>
            <ShipTimestamp>2019-10-24T14:01:22GMT+00:00</ShipTimestamp>
            <PaymentInfo>DDU</PaymentInfo>
            <InternationalDetail>
               <Commodities>
                  <NumberOfPieces>1</NumberOfPieces>
                  <Description>Documents</Description>
                  <CustomsValue>10</CustomsValue>
                  <CountryOfManufacture>ES</CountryOfManufacture>
               </Commodities>
            </InternationalDetail>
            <Ship>
               <Shipper>
                  <Contact>
                     <PersonName>Karlos Espana</PersonName>
                     <CompanyName>SHIPING LTD</CompanyName>
                     <PhoneNumber>3848211</PhoneNumber>
                  </Contact>
                  <Address>
                     <StreetLines>DEL STREETO 9</StreetLines>
                     <City>SANT CUGAT DEL VALLES</City>
                     <PostalCode>08173</PostalCode>
                     <CountryCode>ES</CountryCode>
                  </Address>
               </Shipper>
               <Recipient>
                  <Contact>
                     <PersonName>Martin Soltys</PersonName>
                     <CompanyName>DHL</CompanyName>
                     <PhoneNumber>731731731</PhoneNumber>
                  </Contact>
                  <Address>
                     <StreetLines>V Parku 2308/10</StreetLines>
                     <City>Prague</City>
                     <PostalCode>14800</PostalCode>
                     <CountryCode>CZ</CountryCode>
                  </Address>
               </Recipient>
            </Ship>
            <Packages>
               <RequestedPackages number="1">
                  <Weight>1</Weight>
                  <Dimensions>
                     <Length>35</Length>
                     <Width>25</Width>
                     <Height>1</Height>
                  </Dimensions>
                  <CustomerReferences>LC MAGIC NUMBER 0037</CustomerReferences>
               </RequestedPackages>
            </Packages>
         </RequestedShipment>
      </ShipmentRequest>
   </soap:Body>
</soap:Envelope>



$url = 'https://wsbexpress.dhl.com:443/sndpt/expressRateBook';
    $action = 'createShipmentRequest';
    try {
        $client = new SoapClient($path_to_wsdl);
        $response =$client->createShipmentRequest($request);
    } catch (SoapFault $fault) {
        echo "<h2>SOAP Fault!</h2><p>";
        echo "FaultCode: {$fault->faultcode} <br/>";
        echo "FaultString: {$fault->faultstring} <br/>";
        echo"</p/>";
    }

Ответы [ 2 ]

0 голосов
/ 25 апреля 2020

Решена проблема. Я должен был установить Тип содержимого на текст / xml

$opts = array(
            'header'=> "Content-Type:text/xml"
        );
        $options = array(
            'encoding' => 'UTF-8',
            'verifypeer' => false,
            'verifyhost' => false,
            'soap_version' => SOAP_1_2,
            'trace' => 1,
            'exceptions' => 1,
            'connection_timeout' => 180,
            'stream_context' => stream_context_create($opts),
            'cache_wsdl' => WSDL_CACHE_NONE,
        );
            $client = new SoapClient($path_to_wsdl,$options);
0 голосов
/ 24 апреля 2020

Ваш запрос искажен. Вам следует отправить отчет об ошибке в DHL о том, что они ответили HTTP 500 Internal Server Error на неправильно сформированном XML, потому что правильный ответ HTTP 400 Bad Request

выглядит ли это как действительный XML для вас?

                <Address>
                    <StreetLines>address test/StreetLines>
                    <City>Singapore</City>
                    <PostalCode>343333</PostalCode>
                    <CountryCode>SG</CountryCode>
                </Address>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...