联邦快递服务出错 api
Getting error in fedex rate services api
我在响应费率服务时遇到错误 api,但没有得到我所缺少的。
这是我的代码
$path_to_wsdl = Folder::realpath(dirname(__FILE__) . '/wsdl/RateService_v18.wsdl');
ini_set("soap.wsdl_cache_enabled", "0");
$client = new SoapClient($path_to_wsdl, array('trace' => 1, 'stream_context' => stream_context_create(array('ssl' => array('verify_peer' => false, 'verify_peer_name' => false)))));
$request['WebAuthenticationDetail'] = array(
'UserCredential' => array(
'Key' => 'fedex key',
'Password' => 'fedex password'
)
);
$request['ClientDetail'] = array(
'AccountNumber' => 'fedex account number',
'MeterNumber' => 'fedex meter no.'
);
$request['TransactionDetail'] = array(
'CustomerTransactionId' => ' *** Rate Request v18 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');
$request['RequestedShipment']['ServiceType'] = 'PRIORITY_OVERNIGHT'; // 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']['Shipper'] = array('Address' => array(
'StreetLines' => array('10 Fed Ex Pkwy'), // Origin details
'City' => 'Memphis',
'StateOrProvinceCode' => 'TN',
'PostalCode' => '38115',
'CountryCode' => 'US'));
$request['RequestedShipment']['Recipient'] = array(
'Address' => array(
'StreetLines' => array('13450 Farmcrest Ct'), // Destination details
'City' => 'Herndon',
'StateOrProvinceCode' => 'VA',
'PostalCode' => '20171',
'CountryCode' => 'US'
)
);
$request['RequestedShipment']['ShippingChargesPayment'] = array(
'PaymentType' => 'SENDER',
'Payor' => array(
'AccountNumber' => 'fedex acc no.',
'CountryCode' => 'US'
)
);
$request['RequestedShipment']['RateRequestTypes'] = 'ACCOUNT';
$request['RequestedShipment']['RateRequestTypes'] = 'LIST';
$request['RequestedShipment']['PackageCount'] = '2';
$request['RequestedShipment']['PackageDetail'] = 'INDIVIDUAL_PACKAGES'; // Or PACKAGE_SUMMARY
$request['RequestedShipment']['RequestedPackageLineItems'] = array(
'0' => array(
'Weight' => array(
'Value' => 2.0,
'Units' => 'LB'
),
'Dimensions' => array(
'Length' => 10,
'Width' => 10,
'Height' => 3,
'Units' => 'IN'
)
),
'1' => array(
'Weight' => array(
'Value' => 5.0,
'Units' => 'LB'
),
'Dimensions' => array(
'Length' => 20,
'Width' => 20,
'Height' => 10,
'Units' => 'IN'
)
)
);
try {
return $client->getRates($request);
} catch (SoapFault $exception) {
return $exception;
}
这是我得到的错误异常
[faultstring] => Fault
[faultcode] => SOAP-ENV:Server
[detail] => stdClass Object
(
[cause] => UnrecoverableClientError
[code] => SchemaError
[desc] => validation failure for RateRequest Error:cvc-enumeration-valid: Value '1' is not facet-valid with respect to enumeration
)
我坚持使用这条特定的线 - "validation failure for RateRequest Error:cvc-enumeration-valid: Value '1' is not facet-valid with respect to enumeration"。
终于有了答案
替换 RateService_v18.wsdl 文件中下面给出的行
<xs:element name="Minor" type="xs:int" fixed="1" minOccurs="1">
和
<xs:element name="Minor" type="xs:int" minOccurs="1">
并将 Parameter Minor 发送为 0,如下所示
$request['Version'] = array(
'ServiceId' => 'crs',
'Major' => '18',
'Intermediate' => '0',
'Minor' => '0'
);
我在响应费率服务时遇到错误 api,但没有得到我所缺少的。
这是我的代码
$path_to_wsdl = Folder::realpath(dirname(__FILE__) . '/wsdl/RateService_v18.wsdl');
ini_set("soap.wsdl_cache_enabled", "0");
$client = new SoapClient($path_to_wsdl, array('trace' => 1, 'stream_context' => stream_context_create(array('ssl' => array('verify_peer' => false, 'verify_peer_name' => false)))));
$request['WebAuthenticationDetail'] = array(
'UserCredential' => array(
'Key' => 'fedex key',
'Password' => 'fedex password'
)
);
$request['ClientDetail'] = array(
'AccountNumber' => 'fedex account number',
'MeterNumber' => 'fedex meter no.'
);
$request['TransactionDetail'] = array(
'CustomerTransactionId' => ' *** Rate Request v18 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');
$request['RequestedShipment']['ServiceType'] = 'PRIORITY_OVERNIGHT'; // 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']['Shipper'] = array('Address' => array(
'StreetLines' => array('10 Fed Ex Pkwy'), // Origin details
'City' => 'Memphis',
'StateOrProvinceCode' => 'TN',
'PostalCode' => '38115',
'CountryCode' => 'US'));
$request['RequestedShipment']['Recipient'] = array(
'Address' => array(
'StreetLines' => array('13450 Farmcrest Ct'), // Destination details
'City' => 'Herndon',
'StateOrProvinceCode' => 'VA',
'PostalCode' => '20171',
'CountryCode' => 'US'
)
);
$request['RequestedShipment']['ShippingChargesPayment'] = array(
'PaymentType' => 'SENDER',
'Payor' => array(
'AccountNumber' => 'fedex acc no.',
'CountryCode' => 'US'
)
);
$request['RequestedShipment']['RateRequestTypes'] = 'ACCOUNT';
$request['RequestedShipment']['RateRequestTypes'] = 'LIST';
$request['RequestedShipment']['PackageCount'] = '2';
$request['RequestedShipment']['PackageDetail'] = 'INDIVIDUAL_PACKAGES'; // Or PACKAGE_SUMMARY
$request['RequestedShipment']['RequestedPackageLineItems'] = array(
'0' => array(
'Weight' => array(
'Value' => 2.0,
'Units' => 'LB'
),
'Dimensions' => array(
'Length' => 10,
'Width' => 10,
'Height' => 3,
'Units' => 'IN'
)
),
'1' => array(
'Weight' => array(
'Value' => 5.0,
'Units' => 'LB'
),
'Dimensions' => array(
'Length' => 20,
'Width' => 20,
'Height' => 10,
'Units' => 'IN'
)
)
);
try {
return $client->getRates($request);
} catch (SoapFault $exception) {
return $exception;
}
这是我得到的错误异常
[faultstring] => Fault
[faultcode] => SOAP-ENV:Server
[detail] => stdClass Object
(
[cause] => UnrecoverableClientError
[code] => SchemaError
[desc] => validation failure for RateRequest Error:cvc-enumeration-valid: Value '1' is not facet-valid with respect to enumeration
)
我坚持使用这条特定的线 - "validation failure for RateRequest Error:cvc-enumeration-valid: Value '1' is not facet-valid with respect to enumeration"。
终于有了答案
替换 RateService_v18.wsdl 文件中下面给出的行
<xs:element name="Minor" type="xs:int" fixed="1" minOccurs="1">
和
<xs:element name="Minor" type="xs:int" minOccurs="1">
并将 Parameter Minor 发送为 0,如下所示
$request['Version'] = array(
'ServiceId' => 'crs',
'Major' => '18',
'Intermediate' => '0',
'Minor' => '0'
);