使用WSDL/SOAP调用Fedex Webservice出现问题

10

我从FedEx的网站下载了请求费率的示例代码... 我将WSDL文件放在正确的位置,我有我的账户号码、密码、计量器号码和密钥。当我运行脚本时,我收到以下错误信息:

处理事务时出错。
错误
prof
1000
验证失败

他们提供的脚本如下, 是的,我确实在脚本中替换了所有出现的XXX和YYY。

<?php

// Copyright 2009, FedEx Corporation. All rights reserved.
// Version 7.0.0

require_once('fedex-common.php5');

$newline = "<br />";
//The WSDL is not included with the sample code.
//Please include and reference in $path_to_wsdl variable.
$path_to_wsdl = "RateService_v7.wsdl";

ini_set("soap.wsdl_cache_enabled", "0");

$client = new SoapClient($path_to_wsdl, array('trace' => 1)); // Refer to http://us3.php.net/manual/en/ref.soap.php for more information

$request['WebAuthenticationDetail'] = array('UserCredential' =>
                                      array('Key' => 'XXX', 'Password' => 'YYY')); // Replace 'XXX' and 'YYY' with FedEx provided credentials 
$request['ClientDetail'] = array('AccountNumber' => 'XXX', 'MeterNumber' => 'YYY');// Replace 'XXX' with your account and meter number
$request['TransactionDetail'] = array('CustomerTransactionId' => ' *** Rate Request v7 using PHP ***');
$request['Version'] = array('ServiceId' => 'crs', 'Major' => '7', 'Intermediate' => '0', 'Minor' => '0');
$request['ReturnTransitAndCommit'] = true;
$request['RequestedShipment']['DropoffType'] = 'REGULAR_PICKUP'; // valid values REGULAR_PICKUP, REQUEST_COURIER, ...
$request['RequestedShipment']['ShipTimestamp'] = date('c');
$request['RequestedShipment']['ServiceType'] = 'FEDEX_GROUND'; // valid values STANDARD_OVERNIGHT, PRIORITY_OVERNIGHT, FEDEX_GROUND, ...
$request['RequestedShipment']['PackagingType'] = 'YOUR_PACKAGING'; // valid values FEDEX_BOX, FEDEX_PAK, FEDEX_TUBE, YOUR_PACKAGING, ...
$request['RequestedShipment']['Shipper'] = array('Address' => array(
                                          'StreetLines' => array('10 Fed Ex Pkwy'), // Origin details
                                          'City' => 'Memphis',
                                          'StateOrProvinceCode' => 'TN',
                                          'PostalCode' => '38115',
                                          'CountryCode' => 'US'));
$request['RequestedShipment']['Recipient'] = array('Address' => array (
                                               'StreetLines' => array('13450 Farmcrest Ct'), // Destination details
                                               'City' => 'Herndon',
                                               'StateOrProvinceCode' => 'VA',
                                               'PostalCode' => '20171',
                                               'CountryCode' => 'US'));
$request['RequestedShipment']['ShippingChargesPayment'] = array('PaymentType' => 'SENDER',
                                                        'Payor' => array('AccountNumber' => 'XXX', // Replace 'XXX' with payor's account number
                                                                     'CountryCode' => 'US'));
$request['RequestedShipment']['RateRequestTypes'] = 'ACCOUNT'; 
$request['RequestedShipment']['RateRequestTypes'] = 'LIST'; 
$request['RequestedShipment']['PackageCount'] = '2';
$request['RequestedShipment']['PackageDetailSpecified'] = true;
$request['RequestedShipment']['PackageDetail'] = 'INDIVIDUAL_PACKAGES';  //  Or PACKAGE_SUMMARY
$request['RequestedShipment']['RequestedPackageLineItems'] = array('0' => array('Weight' => array('Value' => 2.0,
                                                                                    'Units' => 'LB'),
                                                                                    'Dimensions' => array('Length' => 10,
                                                                                        'Width' => 10,
                                                                                        'Height' => 3,
                                                                                        'Units' => 'IN')),
                                                                   '1' => array('Weight' => array('Value' => 5.0,
                                                                                    'Units' => 'LB'),
                                                                                    'Dimensions' => array('Length' => 20,
                                                                                        'Width' => 20,
                                                                                        'Height' => 10,
                                                                                        'Units' => 'IN')));
try 
{
    $response = $client ->getRates($request);

    if ($response -> HighestSeverity != 'FAILURE' && $response -> HighestSeverity != 'ERROR')
    {
        printRequestResponse($client);
    }
    else
    {
        echo 'Error in processing transaction.'. $newline. $newline; 
        foreach ($response -> Notifications as $notification)
        {           
            if(is_array($response -> Notifications))
            {              
               echo $notification -> Severity;
               echo ': ';           
               echo $notification -> Message . $newline;
            }
            else
            {
                echo $notification . $newline;
            }
        } 
    } 

    writeToLog($client);    // Write to log file   

} catch (SoapFault $exception) {
   printFault($exception, $client);        
}

?>

我不太确定为什么它不起作用,我读过使用代理的文章,但是我不知道在这种情况下应该如何使用它? SOAP和WSDL的目的不是避免使用CURL、直连之类的东西吗?

6个回答

7
同意Aditya Kumar的观点,或者在您的wsdl文件底部检查代码。
<s1:address location="https://wsbeta.fedex.com:443/web-services/ship"/>

把它改为:
<s1:address location="https://ws.fedex.com:443/web-services/ship"/>

6

我曾经也有同样的问题,我一直在输入登录时使用的密码,但实际上我们需要输入在注册 FEDEX 测试账户信息后发送到你的电子邮件地址中的密码:

请确保您在下面输入的值是正确的:

if($var == 'shipaccount') Return 'Your Account Number';
if($var == 'meter')       Return 'Your meter number';
if($var == 'key')         Return 'Your key'; //These values wiil be shown in the page after registering for the test account

if($var == 'password')    Return 'Your Password'; // This will be sent to you by Fedex to your mail this is not your account password using to login

2
如果您使用SoapUI(http://www.soapui.org/)联系WSDL,您会得到什么响应?(SoapUI使您能够在不编程的情况下测试SOAP/Wsdl,因此您可以检查调用是否正确,如果是,则问题在于您的代码。)

4
显然,FedEx密码和测试帐户有一定的传播期。我获取了一个生产密钥(也必须注册自己的FedEx帐户),然后经过一番搜索,我发现我必须将网关更改为:https://gateway.fedex.com/web-services。有点令人困惑,因为这些都没有记录在文件中。不管怎样,现在它可以使用了。现在我只需要解析这个糟糕的XML响应! - Parris

1

编辑fedex-common.php5文件,将以下参数中的“XXX”替换为您的信息

if($var == 'shipaccount') Return 'YOUR TEST ACCOUNT NUMBER HERE'; 
if($var == 'billaccount') Return 'YOUR TEST ACCOUNT NUMBER HERE';
if($var == 'meter') Return 'YOUR TEST METER NUMBER HERE';
if($var == 'key') Return 'YOUR TEST KEY HERE';
if($var == 'password') Return 'YOUR TEST PASSWORD HERE';

希望这能帮到某个人。

0

在库文件fedex-common.php5中,将以下字段更改为提供的凭据:

if($var == 'shipaccount') Return '123456';
if($var == 'billaccount') Return '123456';
if($var == 'dutyaccount') Return '123456';
if($var == 'accounttovalidate') Return '123456';
if($var == 'meter') Return '654321';
if($var == 'key') Return 'ASDE324dfe';
if($var == 'password') Return 'K2wedrf4ASDE324dfe';

在 wsdl 文件 ShipService_v*.wsdl 中,更改以下内容:

<s1:address location="https://ws.fedex.com:443/web-services/ship"/>

希望它能对你有用。

0

我之前遇到了这个问题,最终在与联邦快递技术人员讨论后找到了解决方案。看看为什么我们会遇到这样的错误,全部都是因为我们从开发者网站生成的开发者测试账户。有一件事情我们应该记住,以“6”开头的测试账号是生产环境的,而以“5”开头的密钥才是正确的测试密钥。所以当您遇到身份验证问题并出现1000错误代码时,请检查您的测试密钥。

除此之外,可能还有另一个原因,就是您的联邦快递 Web 服务端点不同,例如 "https://wsbeta.fedex.com/web-services/track",这是沙盒模式的 URL,在生产环境中 URL 应该像这样 "https://ws.fedex.com/web-services/track"。在生产环境中没有“beta”模式的 URL,所以请检查端点。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接