php - FEDEX 网络服务 wsdl 文件

标签 php web-services api wsdl fedex

有人要求我使用 PHP 将网站与 FedEx 集成。我不知道从哪里开始。我已经注册了一个测试帐户,并且下载了唯一的示例代码。这引用了一个 .wsdl 文件,但示例代码实际上并不包含该文件。我无法在文档中的任何位置找到此文件的位置。谁能帮忙?如果我能在本周的某个时候连接到 API,我会很高兴。

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

require_once('../library/fedex-common.php5');


//The WSDL is not included with the sample code.
//Please include and reference in $path_to_wsdl variable.
$path_to_wsdl = "../wsdl/LocatorService_v2.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' => '*** Locator Request v2 using PHP ***');
$request['Version'] = array('ServiceId' => 'dloc', 'Major' => '2', 'Intermediate' => '0', 'Minor' => '0');

$bNearToPhoneNumber = false;
if ($bNearToPhoneNumber)
{
    $request['NearToPhoneNumber'] = getProperty('phonenumber'); // Replace 'XXX' with phone number
}
else
{
    $request['NearToAddress'] = getProperty('locatoraddress');
}

$request['DropoffServicesDesired'] = array('Express' => 1, // Location desired services
                                                                    'FedExStaffed' => 1,
                                                                    'FedExSelfService' => 1,
                                                                    'FedExAuthorizedShippingCenter' => 1,
                                                                    'HoldAtLocation' => 1);

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

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

    if ($response -> HighestSeverity != 'FAILURE' && $response -> HighestSeverity != 'ERROR')
    {
        echo 'Dropoff Locations<br>';
        echo '<table border="1"><tr><td>Streetline</td><td>City</td><td>State</td><td>Postal Code</td><td>Distance</td></tr>';
        foreach ($response -> DropoffLocations as $location)
        {
            if(is_array($response -> DropoffLocations))
            {              
                echo '<tr>';
                echo '<td>'.$location -> BusinessAddress -> StreetLines. '</td>';
                echo '<td>'.$location -> BusinessAddress -> City. '</td>';
                echo '<td>'.$location -> BusinessAddress -> StateOrProvinceCode. '</td>';
                echo '<td>'.$location -> BusinessAddress -> PostalCode. '</td>';
                echo '<td>('.$location -> Distance -> Value . ' ';
                echo $location -> Distance -> Units . ')'. '</td>';
                echo '</tr>';
            }
            else
            {
                //echo $location . Newline;
            }
        }
        echo '</table>';
        printSuccess($client, $response);
    }
    else
    {
        printError($client, $response);
    } 

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

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

?>

最佳答案

这可能是您的 wsdl:https://github.com/timborden/fedex/blob/master/wsdl/LocatorService_v2.wsdl

但是您应该在 Fedex 文档上有一个更官方的下载链接。

顺便说一句,代码示例不是很好,ini_set("soap.wsdl_cache_enabled", "0");应该删除(性能问题)但至少有一个 PHP 客户端(fedex-common)!

关于php - FEDEX 网络服务 wsdl 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8744829/

相关文章:

php/mysql 数组删除字段

php - 创建可单元测试的 API 客户端

web-services - Web 服务和企业消息系统有什么区别?

Facebook FQL 在查询某些 URL 时返回 "An unknown error occurred"

javascript - 如何通过表单提交传递下拉列表的值?

php - PHP中如何调用存储过程

java - Web 服务请求在 android 浏览器和代码中不起作用;但它在电脑浏览器中工作

javascript - 在 JavaScript 中发布解析 JSON 字符串

android - 如果我使用他们的 API,我如何反射(reflect)某些外部来源(例如 : Facebook, LinkedIn 等)的用户数据的变化?

xml - Reddit 搜索 api - 通过 subreddit 搜索