试图测试UPS"Quantum"接口 - XML文档格式不正确

Mus*_*rge 5 php xml web-services ups

我们正在尝试测试联合包裹服务(UPS)"量子"接口测试获取订单状态信息.我们得到了跟踪号API,但是遇到了QVEvents问题.

UPS"出站订阅帐户"已设置,有效并链接到我的帐号.用户访问在"用户设置"屏幕中选中"昆腾视图数据"视图.我很幸运地得到了跟踪API使用类似的代码,所以认为我可以排除用户名或密码问题.这两个API有什么不同的操作吗?(例如:SSL要求,HTTP标头设置?)

以下是跟踪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);
Run Code Online (Sandbox Code Playgroud)

这是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);        
Run Code Online (Sandbox Code Playgroud)

这是实际发送给UPS的XML ... [注意双xml标头是他们要求的,它适用于所有其他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>
Run Code Online (Sandbox Code Playgroud)

错误消息如下所示:

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>
Run Code Online (Sandbox Code Playgroud)

我没有使用UPS SCA_SDO库,因为它不会安装在我的电脑上.也许我应该再看一遍,但我的程序员向我保证这不是必要的,与此问题无关.双重堆叠的XML看起来很可疑,但手动说这是UPS想要的方式.我想UPS会根据请求运行预处理器.

Abe*_*Abe 0

IntegrationIndicator 已被弃用。也不要将数据作为数组传递。