如何获得航运服务名称和费率仅使用USPS PHP API


How to get shipping service name and rates only using USPS PHP API

我有这个代码连接到USPS 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>";

我知道这是一个旧的帖子,但它可能会帮助其他人找到解决方案。

USPS最近更改了他们的服务名称。您将从这个API

获得所有更新过的名称。

USPS以其预定义的格式发送响应。您必须将响应转换为XML,然后使用循环解析该响应,将其转换为所需的格式。

响应包括许多成本和交付时间不同的服务。这里我使用"xml2array"函数将xml转换为数组。你可以在网上找到或者联系我。转换成数组后,我们就可以解析服务了。

也可以访问更多信息- http://uspsship.blogspot.in/