USPS:API授权失败

时间:2012-04-02 01:38:38

标签: php api usps

为什么费率不适用于USPS?我正在使用ratev4,我收到一个错误:

错误:

API Authorization failure. RateV4 is not a valid API name for this protocol.
UspsCom::DoAuth

这是我的代码:

<?php
$devurl = "testing.shippingapis.com/ShippingAPITest.dll";
$puburl = "https://secure.shippingapis.com/ShippingAPITest.dll";

$service = "RateV4";
$userid = "690DEVBL1739";

$xml = rawurlencode('<RateV4Request USERID="xxxxx">
    <Revision/>
    <Package ID="1ST">
        <Service>FIRST CLASS</Service>
        <FirstClassMailType>LETTER</FirstClassMailType>
        <ZipOrigination>44106</ZipOrigination>
        <ZipDestination>20770</ZipDestination>
        <Pounds>1</Pounds>
        <Ounces>0.0</Ounces> 
        <Container/>
        <Size>REGULAR</Size> 
        <Machinable>true</Machinable>
    </Package>
    </RateV4Request>');

    $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>";

3 个答案:

答案 0 :(得分:5)

我遇到了同样的问题。 RateV4对USPS的测试服务器无效,仅适用于生产。我联系了他们的支持人员,并试图获得一个有效的API进行测试,但他们发送的所有内容都是他们文档的链接(仅包含生产API,而不是测试)。最后,我刚要求他们将我的帐户转移到生产中,他们就这样做了。

答案 1 :(得分:5)

我假设您已在此处注册USPS Web Tools:

https://secure.shippingapis.com/registration/

已收到USPS确认您的帐户有效的确认:

如果您需要设置USPS,或者您的客户在结账时收到此错误(请参阅下文),您应确认以下内容

Confirm that our USPS API access is approved

Confirm that it is not in test mode and is in production mode
    If USPS says your account is active, this does not mean it is in production mode, - you need to call USPS and specifically request that it be moved to production mode after your account has been approved. A good idea is to perform this quick test:

使用您自己的USERID将以下内容插入您的浏览器,而不是任何浏览器的网址中的XXXX:

https://secure.shippingapis.com/ShippingAPITest.dll?API=CarrierPick ... USERID =&#34; XXXX&#34;&gt; ABC Corp.Suite 7771390 Market StreetHoustonTX770581234

如果您的USPS帐户处于有效状态,则应接受用户名。

Confirm that your username and password is for this site only. USPS only allows 1 domain per account.

http://production.shippingapis.com/ShippingAPI.dll

问题在于,默认情况下,您无权访问USPS的生产API。他们必须先批准你。请记住,他们只允许您在每个帐户的一个网站上使用它,因此如果您为客户,客户或您自己以外的其他业务实体设置Magento,您应该为他们设置一个单独的USPS帐户

这就是您收到此短信的原因 - &#34; Sample Do Not Mail&#34;超过生成的运输标签。

您可以在此处设置USPS WebTools帐户:

http://www.usps.com/webtools/

设置帐户后,他们会授予您访问测试环境的权限。 USPS测试API的URL为:http://testing.shippingapis.com/ShippingAPITest.dll

我建议要求USPS开启生产模式。当您获得USPS批准用于生产API时,您应使用以下URL:

http://production.shippingapis.com/ShippingAPI.dll

https://secure.shippingapis.com/ShippingAPI.dll

完成测试后,请发送电子邮件至USPS Internet客户服务中心(ICCC)。他们将切换您的个人资料,以允许您访问生产服务器,并为您提供生产URL。

ICCC的工作人员如下:东部时间星期一至星期五上午8:00至晚上8:30星期六美国东部时间周日上午8:00至下午6:00和邮政假期 - 关闭以下假期除外:Martin Luther King;总统日;哥伦布日; &安培;美国东部时间上午9:00至下午6:00的退伍军人日

电子邮件:uspstechsupport@esecurecare.net电话:1-800-344-7779

但请记住,为每个网站(或每个域至少一个)设置一个单独的USPS帐户非常重要。如果您在多个网站上使用您的帐户,USPS将禁止您访问其生产服务器。

要请求访问USPS生产API,请在此处填写表单:http://www.usps.com/webtools/webtoolsapirequestform.htm

USPS不允许您将其API用于批处理或数据清理,因此请务必不要在请求表单上选中这些框。

一旦USPS允许您访问其生产API服务器,一切都应该适用于所有USPS运输选项。如果您仍然遇到问题,请再次检查您是否可以访问USPS的生产API服务器。

答案 2 :(得分:1)

我在测试Ratev4(以及用于国际货运的v2)方面遇到了同样的问题。只是要求他们将您转移到生产中,这很容易,但请确保您使用正确的URL。 除此之外,根据我的理解,你的设置无论如何都不会起作用,因为你要求的是头等舱的费率而且重量是1磅。头等舱只能达到13盎司......

相关问题