doukan4795 2014-04-04 10:32
浏览 42
已采纳

fedex API不能在PHP中正确计算速率

I want to apply FedEx API in PHP website. I did it but my client said that it gives wrong rates . my code is below:

       // FedEx
$services['fedex']['PRIORITYOVERNIGHT'] = 'Priority Overnight';
$services['fedex']['STANDARDOVERNIGHT'] = 'Standard Overnight';
$services['fedex']['FIRSTOVERNIGHT'] = 'First Overnight';
$services['fedex']['FEDEX2DAY'] = '2 Day';
$services['fedex']['FEDEXEXPRESSSAVER'] = 'Express Saver';
$services['fedex']['FEDEXGROUND'] = 'Ground';
$services['fedex']['FEDEX1DAYFREIGHT'] = 'Overnight Day Freight';
$services['fedex']['FEDEX2DAYFREIGHT'] = '2 Day Freight';
$services['fedex']['FEDEX3DAYFREIGHT'] = '3 Day Freight';
$services['fedex']['GROUNDHOMEDELIVERY'] = 'Home Delivery';
$services['fedex']['INTERNATIONALECONOMY'] = 'International Economy';
$services['fedex']['INTERNATIONALFIRST'] = 'International First';
$services['fedex']['INTERNATIONALPRIORITY'] = 'International Priority';

// Config
$config = array(
    // Services
     'services' => $services,
    // Weight
    'weight' => 2, // Default = 1
    'weight_units' => 'lb', // lb (default), oz, gram, kg
    // Size
    'size_length' => 5, // Default = 8
    'size_width' => 6, // Default = 4
    'size_height' => 3, // Default = 2
    'size_units' => 'in', // in (default), feet, cm
    // From
    'from_zip' => 97210,
    'from_state' => "OR", // Only Required for FedEx
    'from_country' => "US",
    // To
    'to_zip' => 55455,
    'to_state' => "MN", // Only Required for FedEx
    'to_country' => "US",

    // Service Logins
    //'ups_access' => '0C2D05F55AF310D0', // UPS Access License Key
    //'ups_user' => 'dwstudios', // UPS Username 
    //'ups_pass' => 'dwstudios', // UPS Password 
    //'ups_account' => '81476R', // UPS Account Number
    //'fedex_account' =>'510087461', // FedEX Account Number
    //'fedex_meter' => '100173462' // FedEx Meter Number 

);

in my shipping calculator page :

// Calculate FedEX
    function calculate_fedex($code) {
    //print_R($this->weight);die;
       // $url = "https://gatewaybeta.fedex.com/GatewayDC";
        $url = "https://gateway.fedex.com/GatewayDC";
        $data = '<?xml version="1.0" encoding="UTF-8" ?>
<FDXRateRequest xmlns:api="http://www.fedex.com/fsmapi" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FDXRateRequest.xsd">
    <RequestHeader>
        <CustomerTransactionIdentifier>Express Rate</CustomerTransactionIdentifier>
        <AccountNumber>'.$this->fedex_account.'</AccountNumber>
        <MeterNumber>'.$this->fedex_meter.'</MeterNumber>
        <CarrierCode>'.(in_array($code,array('FEDEXGROUND','GROUNDHOMEDELIVERY')) ? 'FDXG' : 'FDXE').'</CarrierCode>
    </RequestHeader>
    <DropoffType>REGULARPICKUP</DropoffType>
    <Service>'.$code.'</Service>
    <Packaging>YOURPACKAGING</Packaging>
    <WeightUnits>LBS</WeightUnits>
    <Weight>'.number_format(($this->weight_unit != 'lb' ? convert_weight($this->weight,$this->weight_unit,'lb') : $this->weight), 1, '.', '').'</Weight>
    <OriginAddress>
        <StateOrProvinceCode>'.$this->from_state.'</StateOrProvinceCode>
        <PostalCode>'.$this->from_zip.'</PostalCode>
        <CountryCode>'.$this->from_country.'</CountryCode>
    </OriginAddress>
    <DestinationAddress>
        <StateOrProvinceCode>'.$this->to_state.'</StateOrProvinceCode>
        <PostalCode>'.$this->to_zip.'</PostalCode>
        <CountryCode>'.$this->to_country.'</CountryCode>
    </DestinationAddress>
    <Payment>
        <PayorType>SENDER</PayorType>
    </Payment>
    <PackageCount>1</PackageCount>
</FDXRateRequest>';

        // Curl
        $results = $this->curl($url,$data);

        // Debug
        if($this->debug == true) {
            print "<xmp>".$data."</xmp><br />";
            print "<xmp>".$results."</xmp><br />";
        }

        // Match Rate
        preg_match('/<NetCharge>(.*?)<\/NetCharge>/',$results,$rate);
        //print_R($rate[1]);die;
        return $rate[1];

    }

and my output is:

Rates for sending a 2 lb, 5 x 6 x 3 in package from 97210 to 55455:
Array
(
    [fedex] => Array
        (
            [PRIORITYOVERNIGHT] => 35.46
            [STANDARDOVERNIGHT] => 32.93
            [FIRSTOVERNIGHT] => 96.47
            [FEDEX2DAY] => 16.87
            [FEDEXEXPRESSSAVER] => 11.69
            [FEDEXGROUND] => 6.71
            [FEDEX1DAYFREIGHT] => 
            [FEDEX2DAYFREIGHT] => 
            [FEDEX3DAYFREIGHT] => 
            [GROUNDHOMEDELIVERY] => 11.13
            [INTERNATIONALECONOMY] => 16.87
            [INTERNATIONALFIRST] => 96.47
            [INTERNATIONALPRIORITY] => 35.46
        )

)

Can smebody give me another code of FEDEX api . Thanks in advance

  • 写回答

1条回答 默认 最新

  • dougui1977 2014-04-08 14:17
    关注

    Developer accounts and production accounts often give different results because the client's account may be getting discounts that are not available in the development environment. We had this issue a while back and the dev rates were substantially higher than production.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?