2013-03-14 25 views
0

我有這個代碼連接到USPS API,並獲得詳細的響應長信息列表,然後,服務名稱和費率。如何獲得送貨服務的名稱和費率只使用美國郵政PHP API

我怎樣才能使響應只爲服務名稱和利率(|)彼此分開?

<?php 
$devurl = "http://Production.ShippingAPIs.com/ShippingAPI.dll"; 
$puburl = "http://Production.ShippingAPIs.com/ShippingAPI.dll"; 
$service = "IntlRateV2"; 
$userid = "xxxxx"; 
$xml = rawurlencode('<IntlRateV2Request USERID="xxxxx"> 
<Package ID="1ST"> 
    <Pounds>15</Pounds> 
    <Ounces>0</Ounces> 
    <MailType>Package</MailType> 
    <ValueOfContents>50</ValueOfContents> 
    <Country>Jordan</Country> 
    <Container>RECTANGULAR</Container> 
    <Size>LARGE</Size> 
    <Width>10</Width> 
    <Length>15</Length> 
    <Height>10</Height> 
    <Girth>0</Girth> 
    <CommercialFlag>N</CommercialFlag> 
    </Package> 
</IntlRateV2Request>'); 
$request = $devurl . "?API=" . $service . "&xml=" . $xml; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $request); 
curl_setopt($ch, CURLOPT_HEADER, false); 
curl_setopt($ch, CURLOPT_HTTPGET, true); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
$response = curl_exec($ch); 
curl_close($ch); 
echo "<pre>"; 
print_r($response); 
echo "</pre>"; 

回答

0

我知道它的舊帖子,但它可能有助於其他人找到解決方案。

USPS最近更改他們的服務名稱。 你可以從這個API

希望它得到所有更新的名字幫助..

0

USPS發送在其預定的形式迴應。您必須將響應轉換爲xml,然後使用循環將其轉換爲您所需的格式。

響應包括許多不同的成本和交付時間的服務。這裏我使用「xml2array」函數將xml轉換爲數組。你可以在網上找到它或與我聯繫。轉換成數組後,我們可以解析服務。

也訪問了解更多信息 - http://uspsship.blogspot.in/

相關問題