我们正在尝试对联合包裹服务(UPS)的“Quantum”界面进行测试,以获取订单状态信息。我们使跟踪编号API正常运行,但QVEvents API遇到了麻烦。
UPS“出站订阅帐户”已设置,激活并链接到我的帐号。在“用户设置”屏幕中,已选中“用户访问Quantum View数据” View 。顺便说一句,我已经使Tracking API使用类似的代码,因此认为我可以排除用户名或密码问题。这两个API在操作上有什么不同? (例如:SSL要求,HTTP header 设置?)
这是用于我的跟踪API的代码(“Tack by Waybill”):
<?php
// UPS Tracker API - track specfic Waybill
// DEV server
$access = '99999999399999999';
$userid = '9999999';
$passwd = '999999999999';
$endpointUrl = 'https://www.ups.com/ups.app/xml/Track';
$outFileName = './XOLTResult.xml';
// Note: you need at least a UPS DEV account to test this
$data ="<?xml version=\"1.0\"?><AccessRequest xml:lang='en-US'>
<AccessLicenseNumber>$access</AccessLicenseNumber>
<UserId>$userid</UserId>
<Password>$passwd</Password>
</AccessRequest>
<?xml version=\"1.0\"?>
<TrackRequest>
<Request>
<TransactionReference>
<CustomerContext>
<InternalKey>hello</InternalKey>
</CustomerContext>
<XpciVersion>1.0</XpciVersion>
</TransactionReference>
<RequestAction>Track</RequestAction>
</Request>
<TrackingNumber>9999999999999999</TrackingNumber>
</TrackRequest>";
$ch = curl_init("https://www.ups.com/ups.app/xml/Track");
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_TIMEOUT, 60);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
$result=curl_exec ($ch);
$data = strstr($result, '<?');
$xml=simplexml_load_string($data);
echo "<pre>";
print_r($xml);
这是提供错误消息的Quantum API代码...
<?php
// UPS Quantum API ("Show list of recent tracking information")
// DEV server
$access = '99999999399999999';
$userid = '9999999';
$passwd = '999999999999';
$endpointUrl = 'https://wwwcie.ups.com/ups.app/xml/QVEvents'; // URL for testing Quantum
$outFileName = './XOLTResult.xml';
try
{
$data ="<?xml version=\"1.0\"?>
<AccessRequest xml:lang=\"en-US\">
<AccessLicenseNumber>$access</AccessLicenseNumber>
<UserId>$userid</UserId>
<Password>$passwd</Password>
</AccessRequest>
<?xml version=\"1.0\"?>
<QuantumViewRequest xml:lang=\"en-US\">
<Request>
<TransactionReference>
<CustomerContext>Test XML</CustomerContext>
<XpciVersion>1.0007</XpciVersion>
</TransactionReference>
<RequestAction>QVEvents</RequestAction>
<IntegrationIndicator></IntegrationIndicator>
</Request>
</QuantumViewRequest>";
$postData = array
(
'content' => $data
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_URL,$endpointUrl);
curl_setopt($ch, CURLOPT_VERBOSE, 1 );
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // disable SSL verification if not installed
//curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSLVERSION, 3); // use Secure Socket v3 SSL3
curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, 'SSLv3');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$postData);
if( ! $result = curl_exec($ch))
{
trigger_error(curl_error($ch));
}
echo $result;
$data = strstr($result, '<?');
$xml=simplexml_load_string($data);
echo "<pre>";
print_r($xml);
}
catch(Exception $ex)
{
echo ($ex . "!");
}
curl_close($ch);
这实际上是发送给UPS的XML ...
[请注意,双重xml header 正是他们所要求的,并且可以在所有其他API中使用,所以请不要怪我]
<?xml version="1.0"?>
<AccessRequest xml:lang="en-US">
<AccessLicenseNumber>999</AccessLicenseNumber>
<UserId>999</UserId>
<Password>999</Password>
</AccessRequest>
<?xml version="1.0"?>
<QuantumViewRequest xml:lang="en-US">
<Request>
<TransactionReference>
<CustomerContext>Test XML</CustomerContext>
<XpciVersion>1.0007</XpciVersion>
</TransactionReference>
<RequestAction>QVEvents</RequestAction>
<IntegrationIndicator></IntegrationIndicator>
</Request>
</QuantumViewRequest>
错误消息如下所示:
HTTP/1.1 100 Continue
HTTP/1.1 200 OK
Date: Fri, 25 Jul 2014 22:50:57 GMT
Server: Apache
X-Frame-Options: SAMEORIGIN
Pragma: no-cache
Transfer-Encoding: chunked
Content-Type: application/xml
<QuantumViewResponse><Response><TransactionReference><XpciVersion>1.0</XpciVersion>
</TransactionReference><ResponseStatusCode>0</ResponseStatusCode>
<ResponseStatusDescription>Failure</ResponseStatusDescription><Error>
<ErrorSeverity>Hard</ErrorSeverity><ErrorCode>10001</ErrorCode>
<ErrorDescription>The XML document is not well formed</ErrorDescription></Error>
</Response></QuantumViewResponse><pre>
在不使用UPS SCA_SDO库的情况下,因为它不会安装在我的PC上。也许我应该再看一遍,但是我的程序员向我保证,这不是必需的,并且与这个问题无关。双层XML看起来很可疑,但是手册说这是UPS想要的方式。我猜UPS根据请求运行预处理器。
最佳答案
根据2014年7月的Quantum View Developers Guide,未使用IntegrationIndicator
。
从Request
节点中删除它,它应该可以按预期运行:
<Request>
<TransactionReference>
<CustomerContext>Test XML</CustomerContext>
<XpciVersion>1.0007</XpciVersion>
</TransactionReference>
<RequestAction>QVEvents</RequestAction>
</Request>