通过WSDL / SOAP使用Fedex Web服务的问题

时间:2010-01-06 14:46:15

标签: php api soap wsdl fedex

我下载了示例代码以从fedex的网站请求费率...我将WSDL文件放在正确的位置,我有我的帐号,密码,仪表号和密钥。当我运行脚本时,我收到此错误:

  

处理交易时出错。
  ERROR
  教授
  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,Direct Connect类型的东西?

6 个答案:

答案 0 :(得分:5)

我也遇到了同样的问题,我输入的密码是我用来登录的,但我们需要输入密码,在用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

答案 1 :(得分:5)

同意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"/>

答案 2 :(得分:2)

如果您使用SoapUI(http://www.soapui.org/)联系WSDL,您会得到什么样的响应?

(SoapUI使您无需编程即可测试SOAP / Wsdl,因此您可以检查调用是否正确,如果是,则问题出在您的代码中。)

答案 3 :(得分: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';

希望这有助于某人。

答案 4 :(得分: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';
wsdlfile中的

ShipService_v * .wsdl 更改了以下内容:

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

希望它对你有用。

答案 5 :(得分:0)

我在早些时候面对这个问题并在与FedEx技术人员讨论后最终找到了解决方案。看看为什么我们面临这样的错误都是因为我们从开发者网站生成的开发人员测试帐户。我们应该记住测试帐户的一件事号码以&#34; 6&#34;开头生产与生产重点开始于&#34; 5&#34;是正确的测试密钥。所以当您收到错误代码1000的身份验证问题时,请检查您的测试密钥。

除此之外的另一个原因可能是您的Fedex Webservice端点与ex&#34; https://wsbeta.fedex.com/web-services/track&#34;不同,这是沙盒模式网址,在生产环境中网址应该是这样的&# 34; https://ws.fedex.com/web-services/track&#34 ;.没有&#34; beta&#34;生产URL的模式,请检查端点。