require_once('modules/FedEx/RateAvailableServicesService_v18_php/library/fedex-common.php5');
$path_to_wsdl = PATH."modules/FedEx/RateAvailableServicesService_v18_php/RateService_v18.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(
//'ParentCredential' => array(
//'Key' => $this->getProperty('key'),
//'Password' => $this->getProperty('password')
//),
'UserCredential' => array(
'Key' => $this->getProperty('key'),
'Password' => $this->getProperty('password')
)
);
$request['ClientDetail'] = array(
'AccountNumber' => $this->getProperty('shipaccount'),
'MeterNumber' => $this->getProperty('meter')
);
$request['TransactionDetail'] = array('CustomerTransactionId' => ' *** Rate Available Services Request using PHP ***');
$request['Version'] = array(
'ServiceId' => 'crs',
'Major' => '18',
'Intermediate' => '0',
'Minor' => '1'
);
$request['ReturnTransitAndCommit'] = true;
$request['RequestedShipment']['DropoffType'] = 'REGULAR_PICKUP'; // valid values REGULAR_PICKUP, REQUEST_COURIER, ...
$request['RequestedShipment']['ShipTimestamp'] = date('c');
// Service Type and Packaging Type are not passed in the request
$request['RequestedShipment']['ServiceType'] = 'INTERNATIONAL_PRIORITY'; // valid values STANDARD_OVERNIGHT, PRIORITY_OVERNIGHT, FEDEX_GROUND, ...
$request['RequestedShipment']['Shipper'] = array(
'Address'=> array('StreetLines' => array($UL->str_add1,$UL->str_add2),'City' => $UL->city_name,'StateOrProvinceCode' => $UL->state_name,'PostalCode' => $UL->zipcode,'CountryCode' => $UL->country_code));
$request['RequestedShipment']['Recipient'] = array(
'Address'=>array('StreetLines' => array($this->session->get('shipping_address1'),$this->session->get('shipping_address2')),'City' => $shipping_city,'StateOrProvinceCode' => $shipping_state,'PostalCode' => $this->session->get('shipping_postal_code'),'CountryCode' => $country_code,'Residential' => false));
$request['RequestedShipment']['ShippingChargesPayment'] = array(
'PaymentType' => 'SENDER',
'Payor' => array(
'ResponsibleParty' => array(
'AccountNumber' => $this->getProperty('billaccount'),
'Contact' => null,
'Address' => array(
'CountryCode' => COUNTRY_CODE
)
)
)
);
$request['RequestedShipment']['PackageCount'] = '1';
$request['RequestedShipment']['RequestedPackageLineItems'] = array(
'0' => array(
'SequenceNumber' => 1,
'GroupPackageCount' => 1,
'Weight' => array(
'Value' => $UL->weight//,
//'Units' => 'LB'
),
'Dimensions' => array(
'Length' => $UL->length,
'Width' => $UL->width,
'Height' => $UL->height//,
//'Units' => 'IN'
)
)
);
try {
if(setEndpoint('changeEndpoint')){
$newLocation = $client->__setLocation(setEndpoint('endpoint'));
}
$response = $client ->getRates($request);
if ($response -> HighestSeverity != 'FAILURE' && $response -> HighestSeverity != 'ERROR'){
echo 'Rates for following service type(s) were returned.'. Newline. Newline;
echo '<table border="1">';
echo '<tr><td>Service Type</td><td>Amount</td><td>Delivery Date</td>';
if(is_array($response -> RateReplyDetails)){
foreach ($response -> RateReplyDetails as $rateReply){
$this->printRateReplyDetails($rateReply);
}
}else{
$this->printRateReplyDetails($response -> RateReplyDetails);
}
echo '</table>'. Newline;
printSuccess($client, $response);
}else{
printError($client, $response);
}
writeToLog($client); // Write to log file
} catch (SoapFault $exception) {
printFault($exception, $client);
}
这是我得到的错误异常
故障
编码:SOAP-ENV:服务器 字符串:故障 请求
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://fedex.com/ws/rate/v18"><SOAP-ENV:Body><ns1:RateRequest><ns1:WebAuthenticationDetail><ns1:UserCredential><ns1:Key>AndJurrJfCvvWZWn</ns1:Key><ns1:Password>Rps8Pl4jF9zGp5wiEpDRhKiHo</ns1:Password></ns1:UserCredential></ns1:WebAuthenticationDetail><ns1:ClientDetail><ns1:AccountNumber>631140688</ns1:AccountNumber><ns1:MeterNumber>107714405</ns1:MeterNumber></ns1:ClientDetail><ns1:TransactionDetail><ns1:CustomerTransactionId> *** Rate Available Services Request using PHP ***</ns1:CustomerTransactionId></ns1:TransactionDetail><ns1:Version><ns1:ServiceId>crs</ns1:ServiceId><ns1:Major>18</ns1:Major><ns1:Intermediate>0</ns1:Intermediate><ns1:Minor>1</ns1:Minor></ns1:Version><ns1:ReturnTransitAndCommit>true</ns1:ReturnTransitAndCommit><ns1:RequestedShipment><ns1:ShipTimestamp>2016-03-30T18:35:41+05:30</ns1:ShipTimestamp><ns1:DropoffType>REGULAR_PICKUP</ns1:DropoffType><ns1:ServiceType>INTERNATIONAL_PRIORITY</ns1:ServiceType><ns1:Shipper><ns1:Address><ns1:StreetLines>SUITE 5A-1204</ns1:StreetLines><ns1:StreetLines>799 E DRAGRAM</ns1:StreetLines><ns1:City>TUCSON</ns1:City><ns1:StateOrProvinceCode>AZ</ns1:StateOrProvinceCode><ns1:PostalCode>94040</ns1:PostalCode><ns1:CountryCode>US</ns1:CountryCode></ns1:Address></ns1:Shipper><ns1:Recipient><ns1:Address><ns1:StreetLines>795 E</ns1:StreetLines><ns1:StreetLines>DRAGRAM</ns1:StreetLines><ns1:City>TUCSON</ns1:City><ns1:StateOrProvinceCode>AZ</ns1:StateOrProvinceCode><ns1:PostalCode>94040</ns1:PostalCode><ns1:CountryCode>US</ns1:CountryCode><ns1:Residential>false</ns1:Residential></ns1:Address></ns1:Recipient><ns1:ShippingChargesPayment><ns1:PaymentType>SENDER</ns1:PaymentType><ns1:Payor><ns1:ResponsibleParty><ns1:AccountNumber>631140688</ns1:AccountNumber><ns1:Address><ns1:CountryCode>KWI</ns1:CountryCode></ns1:Address></ns1:ResponsibleParty></ns1:Payor></ns1:ShippingChargesPayment><ns1:PackageCount>1</ns1:PackageCount><ns1:RequestedPackageLineItems><ns1:SequenceNumber>1</ns1:SequenceNumber>
<ns1:GroupPackageCount>1</ns1:GroupPackageCount><ns1:Weight>
<ns1:Value>20</ns1:Value></ns1:Weight><ns1:Dimensions>
<ns1:Length>8</ns1:Length><ns1:Width>10</ns1:Width>
<ns1:Height>10</ns1:Height></ns1:Dimensions></ns1:RequestedPackageLineItems>
</ns1:RequestedShipment></ns1:RateRequest></SOAP-ENV:Body>
</SOAP-ENV:Envelope>
答案 0 :(得分:0)
由于您有跟踪,您应该查看实际的请求/响应数据。当我把上面的原始POST数据(你不应该发布你的帐户/密钥信息)时,我得到了一个模式验证错误。语法看起来正确,但付款人的国家代码是KWI,但应该是美国。我建议你添加一些代码来记录请求和响应......
$soap_response_hdr = $client->__getLastResponseHeaders() ;
$soap_response = $client->__getLastResponse() ;
$soap_request_hdr = $client->__getLastRequestHeaders() ;
$soap_request = $client->__getLastRequest() ;