我一直在网上搜索并阅读FedEx网络服务开发者指南,看看是否有可能使用他们的API提交几个邮政编码并返回Ground套餐的估计运输时间。类似于FedEx"获取费率&过境时间"页面呢。有人做过这样的事吗?
答案 0 :(得分:0)
为了做到这一点,您需要使用FedEx"验证可用性和承诺服务"。以下是其使用PDF的链接:https://www.fedex.com/templates/components/apps/wpor/secure/downloads/pdf/201607/FedEx_WebServices_ValidationAvailabilityAndCommitmentServices_WSDLGuide_v2016.pdf
我一直在努力,并且已经整理了一段快速而肮脏的PHP代码。
<?php
// This is the local path to the FedEx Validation Availability and Commitment Service WSDL
$_wsdlPath = '/xxxxxx/xxxxx/xxxxx/ValidationAvailabilityAndCommitmentService_v6.wsdl';
$ship_from_zip = 10001;
$ship_to_zip = 90210;
// Create the SOAP client
try {
$client = new SoapClient($_wsdlPath, array('trace' => 1));
}
catch(SoapFault $soapFault) {
print($soapFault);
return;
}
// Create our request that we will send to FedEx
$transit_time_request = createTransitTimeRequest($ship_from_zip, $ship_to_zip);
// Send our request to FedEx
$transit_time_response = callTransitTimeRequest($client, $transit_time_request);
print_r($transit_time_response);
function callTransitTimeRequest($client, $transit_time_request) {
try {
// Call FedEx's serviceAvailability operation
$response = $client->serviceAvailability($transit_time_request);
return $response;
}
catch(SoapFault $soapFault) {
print($soapFault);
return null;
}
}
function createTransitTimeRequest($ship_from_zip, $ship_to_zip) {
$_meterNumber = 'xxxxxx'; // Your accounts ClientDetail MeterNumber
$_accountNumber = 'xxxxx'; // You accounts ClientDetail AccountNumber
$_password = 'xxxxxx'; // Your accounts UserCredential Password
$_key = 'xxxxx'; // Your accounts UserCredential Key
$_majorVersion = X; // The WSDL version
$request['WebAuthenticationDetail'] = array();
$request['WebAuthenticationDetail']['UserCredential'] = array();
$request['WebAuthenticationDetail']['UserCredential']['Key'] = $_key;
$request['WebAuthenticationDetail']['UserCredential']['Password'] = $_password;
$request['ClientDetail'] = array();
$request['ClientDetail']['AccountNumber'] = $_accountNumber;
$request['ClientDetail']['MeterNumber'] = $_meterNumber;
$request['TransactionDetail'] = array();
$request['TransactionDetail']['CustomerTransactionId'] = 'ServiceAvailabilityRequest';
$request['Version'] = array();
$request['Version']['ServiceId'] = 'vacs';
$request['Version']['Major'] = $_majorVersion;
$request['Version']['Intermediate'] = '0';
$request['Version']['Minor'] = '0';
$request['Origin'] = array();
$request['Origin']['PostalCode'] = $ship_from_zip;
$request['Origin']['CountryCode'] = 'US';
$request['Destination'] = array();
$request['Destination']['PostalCode'] = $ship_to_zip;
$request['Destination']['CountryCode'] = 'US';
$request['ShipDate'] = date("Y-m-d");
$request['CarrierCode'] = "FDXG"; // FDXG = Ground, FDXE = Express
return $request;
}
?>
此外,这是上述代码返回的内容以及您可以期待的内容:
stdClass Object
(
[HighestSeverity] => NOTE
[Notifications] => stdClass Object
(
[Severity] => NOTE
[Source] => vacs
[Code] => 2002
[Message] => Your Packaging was assumed.
[LocalizedMessage] => Your Packaging was assumed.
)
[TransactionDetail] => stdClass Object
(
[CustomerTransactionId] => ServiceAvailabilityRequest
)
[Version] => stdClass Object
(
[ServiceId] => vacs
[Major] => 6
[Intermediate] => 0
[Minor] => 0
)
[Options] => Array
(
[0] => stdClass Object
(
[Service] => FEDEX_GROUND
[TransitTime] => FOUR_DAYS
)
[1] => stdClass Object
(
[Service] => GROUND_HOME_DELIVERY
[TransitTime] => FOUR_DAYS
)
)
)