通过WSDL/SOAP使用Fedex Webservice的问题

Par*_*ris 10 php api soap wsdl fedex

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

处理事务时出错.
ERROR
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);        
}

?>
Run Code Online (Sandbox Code Playgroud)

我不太清楚为什么它不起作用,我读过关于使用代理,但我不太确定在这种情况下我会如何使用它?使用SOAP和WSDL是不是要避免使用CURL,Direct Connect类型的东西?

小智 7

同意Aditya Kumar,或在底部签入您的wsdl文件.有一个代码

<s1:address location="https://wsbeta.fedex.com:443/web-services/ship"/>
Run Code Online (Sandbox Code Playgroud)

改为

<s1:address location="https://ws.fedex.com:443/web-services/ship"/>
Run Code Online (Sandbox Code Playgroud)


Raj*_*PHP 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
Run Code Online (Sandbox Code Playgroud)


Jim*_*ter 2

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

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

  • 显然,联邦快递密码和测试帐户存在一定的传播期。我获得了一个生产密钥(也必须注册我自己的联邦快递帐户),然后经过一番搜索,我发现我必须将网关更改为:https://gateway.fedex.com/web-services 有点令人困惑,因为这些都没有记录。无论如何,现在它可以工作了。现在我只需要解析这个令人讨厌的 XML 响应! (4认同)