2010-11-03 152 views
0

在我的網站(基於PHP)我想實現DHL的費率計算器。我想添加3個字段 - 1.Origin,2.Destination和3.Weight。這3個值將被髮送到DHL服務器,作爲回報,我希望有速度。我怎樣才能做到這一點?DHL稅率計算

在另一節中,我將添加更多字段(地址,產品hts代碼等)與這3個以獲得速率。它怎麼能做呢?

+0

你可以訪問任何DHL API? – 2010-11-03 07:46:28

+0

不,我沒有訪問權限。我如何獲得訪問權限? – 2010-11-04 03:06:55

+0

我建議你註冊訪問他們的XML API: http://www.dhl-usa.com/xml/index.asp – 2010-11-03 07:47:59

回答

5

以下是DHL費率計算器代碼:您需要使用您的DHL網站ID和密碼更改siteid和密碼。

<?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>123456789</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); 
?> 

更多參考請點擊以下鏈接:

http://xmlpitest-ea.dhl.com/serviceval/jsps/main/Main_menu.jsp

+0

我該怎麼做 Y? – socca1157 2016-03-07 19:30:54