In my website(php based) I want implement a rate calculator of DHL. I want to add 3 fields-1.Origin, 2.Destination and 3.Weight. These 3 values will be sent to DHL server and in return I want to have the RATE. How can I do that?
In another section, I will add more field (address, product hts code, etc.) with those 3 to get the开发者_JS百科 RATE. How can it be done also??
Below is DHL rate calculator code: You need to change siteid and password with your DHL siteid and password.
<?php
$data = '<?xml version="1.0" encoding="UTF-8"?>
<p:DCTRequest xmlns:p="http://www.dhl.com" xmlns:p1="http://www.dhl.com/datatypes" xmlns:p2="http://www.dhl.com/DCTRequestdatatypes" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.dhl.com DCT-req.xsd ">
<GetQuote>
<Request>
<ServiceHeader>
<MessageTime>'.date('c').'</MessageTime>
<MessageReference>1234567890123456789012345678901</MessageReference>
<SiteID>YOUR_DHL_SITE_ID</SiteID>
<Password>YOUR_DHL_PASSWORD</Password>
</ServiceHeader>
</Request>
<From>
<CountryCode>GB</CountryCode>
<Postalcode>WC1A</Postalcode>
</From>
<BkgDetails>
<PaymentCountryCode>US</PaymentCountryCode>
<Date>2011-06-06</Date>
<ReadyTime>PT10H21M</ReadyTime>
<ReadyTimeGMTOffset>+01:00</ReadyTimeGMTOffset>
<DimensionUnit>CM</DimensionUnit>
<WeightUnit>KG</WeightUnit>
<Pieces><Piece>
<PieceID>1</PieceID>
<Height>20</Height>
<Depth>20</Depth>
<Width>20</Width>
<Weight>19</Weight>
</Piece></Pieces>
<IsDutiable>N</IsDutiable>
<NetworkTypeCode>AL</NetworkTypeCode>
</BkgDetails>
<To>
<CountryCode>US</CountryCode>
<Postalcode>10101</Postalcode>
</To>
</GetQuote>
</p:DCTRequest>';
$tuCurl = curl_init();
curl_setopt($tuCurl, CURLOPT_URL, "https://xmlpitest-ea.dhl.com/XMLShippingServlet");
curl_setopt($tuCurl, CURLOPT_PORT , 443);
curl_setopt($tuCurl, CURLOPT_VERBOSE, 0);
curl_setopt($tuCurl, CURLOPT_HEADER, 0);
curl_setopt($tuCurl, CURLOPT_POST, 1);
curl_setopt($tuCurl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($tuCurl, CURLOPT_POSTFIELDS, $data);
curl_setopt($tuCurl, CURLOPT_HTTPHEADER, array("Content-Type: text/xml","SOAPAction: \"/soap/action/query\"", "Content-length: ".strlen($data)));
$tuData = curl_exec($tuCurl);
curl_close($tuCurl);
$xml = simplexml_load_string($tuData);
print "<pre>";
print_r($xml);
?>
For more reference click on below link:
http://xmlpitest-ea.dhl.com/serviceval/jsps/main/Main_menu.jsp
精彩评论