简体   繁体   English

FEDEX Web服务如何运作?

[英]How does FEDEX Web Services work?

Any one help me to find the rate services using FedEx api? 有人帮我找到使用FedEx api的费率服务吗? I have 3 files for finding rate service. 我有3个文件来查找费率服务。

  1. fedex-common.php5 联邦快递common.php5
  2. RateWebServiceClient.php RateWebServiceClient.php
  3. RateService_v14.wsdl RateService_v14.wsdl

I had Download all the three files from https://www.fedex.com/wpor/web/jsp/drclinks.jsp?links=wss/getstarted.html here. 我从这里下载了https://www.fedex.com/wpor/web/jsp/drclinks.jsp?links=wss/getstarted.html中的所有三个文件。 When i run RateWebServiceClient.php file then it shows a error: 当我运行RateWebServiceClient.php文件时,它显示一个错误:

Code: 873 Message: All specified account numbers must match. 代码:873消息:所有指定的帐号必须匹配。

Please Help me to find the rate services. 请帮我查一下价格服务。 Here is the code which i used 这是我使用的代码

1.fedex-common.php5 1.fedex-common.php5

    <?php
// Copyright 2009, FedEx Corporation. All rights reserved.

define('TRANSACTIONS_LOG_FILE', '../fedextransactions.log');  // Transactions log file

/**
 *  Print SOAP request and response
 */
define('Newline',"<br />");

function printSuccess($client, $response) {
    echo '<h2>Transaction Successful</h2>';  
    echo "\n";
    printRequestResponse($client);
}

function printRequestResponse($client){
    echo '<h2>Request</h2>' . "\n";
    echo '<pre>' . htmlspecialchars($client->__getLastRequest()). '</pre>';  
    echo "\n";

    echo '<h2>Response</h2>'. "\n";
    echo '<pre>' . htmlspecialchars($client->__getLastResponse()). '</pre>';
    echo "\n";
}

/**
 *  Print SOAP Fault
 */  
function printFault($exception, $client) {
    echo '<h2>Fault</h2>' . "<br>\n";                        
    echo "<b>Code:</b>{$exception->faultcode}<br>\n";
    echo "<b>String:</b>{$exception->faultstring}<br>\n";
    writeToLog($client);

    echo '<h2>Request</h2>' . "\n";
    echo '<pre>' . htmlspecialchars($client->__getLastRequest()). '</pre>';  
    echo "\n";
}

/**
 * SOAP request/response logging to a file
 */                                  
function writeToLog($client){  
if (!$logfile = fopen(TRANSACTIONS_LOG_FILE, "a"))
{
   error_func("Cannot open " . TRANSACTIONS_LOG_FILE . " file.\n", 0);
   exit(1);
}

fwrite($logfile, sprintf("\r%s:- %s",date("D M j G:i:s T Y"), $client->__getLastRequest(). "\n\n" . $client->__getLastResponse()));
}

/**
 * This section provides a convenient place to setup many commonly used variables
 * needed for the php sample code to function.
 */
function getProperty($var){
    if($var == 'key') Return 'HxxJgDtsmXIZbKik'; 
    if($var == 'password') Return 'ZyZK1pBXkxtwchIYnVBU4Z56R'; 

    if($var == 'shipaccount') Return '510087208'; 
    if($var == 'billaccount') Return '510051408 '; 
    if($var == 'dutyaccount') Return ''; 
    if($var == 'freightaccount') Return '510087208';  
    if($var == 'trackaccount') Return '510087208'; 

    if($var == 'meter') Return '100179026 '; 

    if($var == 'shiptimestamp') Return mktime(10, 0, 0, date("m"), date("d")+1, date("Y"));

    if($var == 'spodshipdate') Return '2013-09-21';
    if($var == 'serviceshipdate') Return '2013-09-26';

    if($var == 'readydate') Return '2010-05-31T08:44:07';
    if($var == 'closedate') Return date("Y-m-d");

    if($var == 'pickupdate') Return date("Y-m-d", mktime(8, 0, 0, date("m")  , date("d")+1, date("Y")));
    if($var == 'pickuptimestamp') Return mktime(8, 0, 0, date("m")  , date("d")+1, date("Y"));
    if($var == 'pickuplocationid') Return 'XXX';
    if($var == 'pickupconfirmationnumber') Return 'XXX';

    if($var == 'dispatchdate') Return date("Y-m-d", mktime(8, 0, 0, date("m")  , date("d")+1, date("Y")));
    if($var == 'dispatchlocationid') Return 'XXX';
    if($var == 'dispatchconfirmationnumber') Return 'XXX';      

    if($var == 'tag_readytimestamp') Return mktime(10, 0, 0, date("m"), date("d")+1, date("Y"));
    if($var == 'tag_latesttimestamp') Return mktime(20, 0, 0, date("m"), date("d")+1, date("Y"));   

    if($var == 'expirationdate') Return '2013-05-24';
    if($var == 'begindate') Return '2013-04-22';
    if($var == 'enddate') Return '2013-04-25';  

    if($var == 'trackingnumber') Return 'XXX';

    if($var == 'hubid') Return 'XXX';

    if($var == 'jobid') Return 'XXX';

    if($var == 'searchlocationphonenumber') Return '5555555555';

    if($var == 'shipper') Return array(
        'Contact' => array(
            'PersonName' => 'Sender Name',
            'CompanyName' => 'Sender Company Name',
            'PhoneNumber' => '1234567890'
        ),
        'Address' => array(
            'StreetLines' => array('Address Line 1'),
            'City' => 'Collierville',
            'StateOrProvinceCode' => 'TN',
            'PostalCode' => '38017',
            'CountryCode' => 'US',
            'Residential' => 1
        )
    );
    if($var == 'recipient') Return array(
        'Contact' => array(
            'PersonName' => 'Recipient Name',
            'CompanyName' => 'Recipient Company Name',
            'PhoneNumber' => '1234567890'
        ),
        'Address' => array(
            'StreetLines' => array('Address Line 1'),
            'City' => 'Herndon',
            'StateOrProvinceCode' => 'VA',
            'PostalCode' => '20171',
            'CountryCode' => 'US',
            'Residential' => 1
        )
    );  

    if($var == 'address1') Return array(
        'StreetLines' => array('10 Fed Ex Pkwy'),
        'City' => 'Memphis',
        'StateOrProvinceCode' => 'TN',
        'PostalCode' => '38115',
        'CountryCode' => 'US'
    );
    if($var == 'address2') Return array(
        'StreetLines' => array('13450 Farmcrest Ct'),
        'City' => 'Herndon',
        'StateOrProvinceCode' => 'VA',
        'PostalCode' => '20171',
        'CountryCode' => 'US'
    );                    
    if($var == 'searchlocationsaddress') Return array(
        'StreetLines'=> array('240 Central Park S'),
        'City'=>'Austin',
        'StateOrProvinceCode'=>'TX',
        'PostalCode'=>'78701',
        'CountryCode'=>'US'
    );

    if($var == 'shippingchargespayment') Return array(
        'PaymentType' => 'SENDER',
        'Payor' => array(
            'ResponsibleParty' => array(
                'AccountNumber' => getProperty('billaccount'),
                'Contact' => null,
                'Address' => array('CountryCode' => 'US')
            )
        )
    );  
    if($var == 'freightbilling') Return array(
        'Contact'=>array(
            'ContactId' => 'freight1',
            'PersonName' => 'Big Shipper',
            'Title' => 'Manager',
            'CompanyName' => 'Freight Shipper Co',
            'PhoneNumber' => '1234567890'
        ),
        'Address'=>array(
            'StreetLines'=>array(
                '1202 Chalet Ln', 
                'Do Not Delete - Test Account'
            ),
            'City' =>'Harrison',
            'StateOrProvinceCode' => 'AR',
            'PostalCode' => '72601-6353',
            'CountryCode' => 'US'
            )
    );
}

function setEndpoint($var){
    if($var == 'changeEndpoint') Return false;
}

function printNotifications($notes){
    foreach($notes as $noteKey => $note){
        if(is_string($note)){    
            echo $noteKey . ': ' . $note . Newline;
        }
        else{
            printNotifications($note);
        }
    }
    echo Newline;
}

function printError($client, $response){
    print_r($client);
    echo Newline;
    print_r($response);
    echo '<h2>Error returned in processing transaction</h2>';
    echo "\n";
    printNotifications($response -> Notifications);
    printRequestResponse($client, $response);
}

function trackDetails($details, $spacer){
    foreach($details as $key => $value){
        if(is_array($value) || is_object($value)){
            $newSpacer = $spacer. '&nbsp;&nbsp;&nbsp;&nbsp;';
            echo '<tr><td>'. $spacer . $key.'</td><td>&nbsp;</td></tr>';
            trackDetails($value, $newSpacer);
        }elseif(empty($value)){
            echo '<tr><td>'.$spacer. $key .'</td><td>'.$value.'</td></tr>';
        }else{
            echo '<tr><td>'.$spacer. $key .'</td><td>'.$value.'</td></tr>';
        }
    }
}
?>

..... .. ...... ..

My 2nd file is : 我的第二个档案是:

2.RateWebServiceClient.php 2.RateWebServiceClient.php

    <?php
// Copyright 2009, FedEx Corporation. All rights reserved.
// Version 12.0.0

require_once('../../library/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 = "../../wsdl/RateService_v14.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' => getProperty('key'), 
        'Password' => getProperty('password')
    )
); 
$request['ClientDetail'] = array(
    'AccountNumber' => getProperty('shipaccount'), 
    'MeterNumber' => getProperty('meter')
);
$request['TransactionDetail'] = array('CustomerTransactionId' => ' *** Rate Request v14 using PHP ***');
$request['Version'] = array(
    'ServiceId' => 'crs', 
    'Major' => '14', 
    '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'] = 'INTERNATIONAL_PRIORITY'; // 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']['TotalInsuredValue']=array(
    'Ammount'=>100,
    'Currency'=>'USD'
);
$request['RequestedShipment']['Shipper'] = addShipper();
$request['RequestedShipment']['Recipient'] = addRecipient();
$request['RequestedShipment']['ShippingChargesPayment'] = addShippingChargesPayment();
$request['RequestedShipment']['RateRequestTypes'] = 'ACCOUNT'; 
$request['RequestedShipment']['RateRequestTypes'] = 'LIST'; 
$request['RequestedShipment']['PackageCount'] = '1';
$request['RequestedShipment']['RequestedPackageLineItems'] = addPackageLineItem1();



try {
    if(setEndpoint('changeEndpoint')){
        $newLocation = $client->__setLocation(setEndpoint('endpoint'));
    }

    $response = $client -> getRates($request);

    if ($response -> HighestSeverity != 'FAILURE' && $response -> HighestSeverity != 'ERROR'){      
        $rateReply = $response -> RateReplyDetails;
        echo '<table border="1">';
        echo '<tr><td>Service Type</td><td>Amount</td><td>Delivery Date</td></tr><tr>';
        $serviceType = '<td>'.$rateReply -> ServiceType . '</td>';
        $amount = '<td>$' . number_format($rateReply->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount,2,".",",") . '</td>';
        if(array_key_exists('DeliveryTimestamp',$rateReply)){
            $deliveryDate= '<td>' . $rateReply->DeliveryTimestamp . '</td>';
        }else if(array_key_exists('TransitTime',$rateReply)){
            $deliveryDate= '<td>' . $rateReply->TransitTime . '</td>';
        }else {
            $deliveryDate='<td>&nbsp;</td>';
        }
        echo $serviceType . $amount. $deliveryDate;
        echo '</tr>';
        echo '</table>';

        printSuccess($client, $response);
    }else{
        printError($client, $response);
    } 

    writeToLog($client);    // Write to log file   
} catch (SoapFault $exception) {
   printFault($exception, $client);        
}



function addShipper(){
    $shipper = array(
        'Contact' => array(
            'PersonName' => 'Sender Name',
            'CompanyName' => 'Sender Company Name',
            'PhoneNumber' => '9012638716'
        ),
        'Address' => array(
            'StreetLines' => array('Address Line 1'),
            'City' => 'Collierville',
            'StateOrProvinceCode' => 'TN',
            'PostalCode' => '38017',
            'CountryCode' => 'US'
        )
    );
    return $shipper;
}
function addRecipient(){
    $recipient = array(
        'Contact' => array(
            'PersonName' => 'Recipient Name',
            'CompanyName' => 'Company Name',
            'PhoneNumber' => '9012637906'
        ),
        'Address' => array(
            'StreetLines' => array('Address Line 1'),
            'City' => 'Richmond',
            'StateOrProvinceCode' => 'BC',
            'PostalCode' => 'V7C4V4',
            'CountryCode' => 'CA',
            'Residential' => false
        )
    );
    return $recipient;                                      
}
function addShippingChargesPayment(){
    $shippingChargesPayment = array(
        'PaymentType' => 'SENDER', // valid values RECIPIENT, SENDER and THIRD_PARTY
        'Payor' => array(
            'ResponsibleParty' => array(
                'AccountNumber' => getProperty('billaccount'),
                'CountryCode' => 'US'
            )
        )
    );
    return $shippingChargesPayment;
}
function addLabelSpecification(){
    $labelSpecification = array(
        'LabelFormatType' => 'COMMON2D', // valid values COMMON2D, LABEL_DATA_ONLY
        'ImageType' => 'PDF',  // valid values DPL, EPL2, PDF, ZPLII and PNG
        'LabelStockType' => 'PAPER_7X4.75'
    );
    return $labelSpecification;
}
function addSpecialServices(){
    $specialServices = array(
        'SpecialServiceTypes' => array('COD'),
        'CodDetail' => array(
            'CodCollectionAmount' => array(
                'Currency' => 'USD', 
                'Amount' => 150
            ),
            'CollectionType' => 'ANY' // ANY, GUARANTEED_FUNDS
        )
    );
    return $specialServices; 
}
function addPackageLineItem1(){
    $packageLineItem = array(
        'SequenceNumber'=>1,
        'GroupPackageCount'=>1,
        'Weight' => array(
            'Value' => 50.0,
            'Units' => 'LB'
        ),
        'Dimensions' => array(
            'Length' => 108,
            'Width' => 5,
            'Height' => 5,
            'Units' => 'IN'
        )
    );
    return $packageLineItem;
}
?>

If you have any other solution using any api in php is also welcome. 如果您有任何其他解决方案使用PHP中的任何api也欢迎。

I'm assuming you have signed up for a test key. 我假设你已经注册了测试密钥。 So once you have that: 一旦你有了这个:

In the fedex-common.php file, you need to put in your key, password, account number, and meter number. 在fedex-common.php文件中,您需要输入密钥,密码,帐号和仪表编号。 You will see that there are multiple account numbers, like billaccount and dutyaccount, etc; 您会看到有多个帐号,例如billaccount和dutyaccount等; just use the same account number on those. 只需在这些帐号上使用相同的帐号。

Then on RateWebServiceClient.php, make sure the WSDL file is in the right place so that it can be loaded into the SoapClient class. 然后在RateWebServiceClient.php上,确保WSDL文件位于正确的位置,以便可以将其加载到SoapClient类中。 Then go to the addShipper() and addRecipient() definition and put real addresses there. 然后转到addShipper()和addRecipient()定义并在其中放置实地址。 Once you have those in place, run RateWebServiceClient.php in your browser and you should be set. 一旦你有了这些,在你的浏览器中运行RateWebServiceClient.php,你应该设置。

"How does FEDEX Web Services work?" “FEDEX Web服务如何运作?”

This is an unanswerable question. 这是一个无法回答的问题。 No one knows. 没人知道。

Error message is very clear: Code: 873 Message: All specified account numbers must match. 错误信息非常明确: Code: 873 Message: All specified account numbers must match.

In your fedex-common.php5 file you have: if($var == 'shipaccount') Return '510087208'; if($var == 'billaccount') Return '510051408 '; 在您的fedex-common.php5文件中,您有: if($var == 'shipaccount') Return '510087208'; if($var == 'billaccount') Return '510051408 '; if($var == 'shipaccount') Return '510087208'; if($var == 'billaccount') Return '510051408 ';

Those account numbers must match. 这些帐号必须匹配。 510087208 and 510051408 account numbers are different. 510087208和510051408帐号不同。 Solution: if($var == 'shipaccount') Return '510087208'; if($var == 'billaccount') Return '510087208'; 解决方案: if($var == 'shipaccount') Return '510087208'; if($var == 'billaccount') Return '510087208'; if($var == 'shipaccount') Return '510087208'; if($var == 'billaccount') Return '510087208';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM