2

我正在尝试从 UPS 获取 xml 速率肥皂馈送。

目前我收到错误“错误版本”(__Soapcall Exeption)或“0FailureHard10002XML 文档格式正确但文档无效1”(来自服务器或 php 的响应)。

我采用了开发人员工具包中提供的示例。我尝试了一切=>

  • 将肥皂版本更改为 1.2
  • 从远程 url 获取 wsdl,而不是在磁盘上
  • 我仔细检查了端点和用户 ID、访问密钥、通过、...

有没有人有一个工作脚本?,或者更好的人可以纠正我的错误:)

代码:

<?php

class UpsRate{
    private $access,$userid,$passwd,$wsdl,$operation,$endpointurl;


    public function  __construct() {
        $this->setConfig();
    }

    public function setConfig($is_test = true){
      $this->access = sfConfig::get('app_shipping_ups_access');
      $this->userid = sfConfig::get('app_shipping_ups_userid');
      $this->passwd = sfConfig::get('app_shipping_ups_password');

      $this->wsdl = sfConfig::get('sf_data_dir').'/wsdl/ups/RateWS.wsdl';
      $this->operation = "ProcessRate";

      $this->endpointurl = $is_test?'https://wwwcie.ups.com/ups.app/xml/Rate':'https://onlinetools.ups.com/ups.app/xml/Rate';
    }


  private function processRate(){
      //create soap request
      $option['RequestOption'] = 'Shop';
      $request['Request'] = $option;

      $pickuptype['Code'] = '01';
      $pickuptype['Description'] = 'Daily Pickup';
      $request['PickupType'] = $pickuptype;

      $customerclassification['Code'] = '01';
      $customerclassification['Description'] = 'Classfication';
      $request['CustomerClassification'] = $customerclassification;

      $shipper['Name'] = 'Trutec';
      $shipper['ShipperNumber'] = 'Y5562A';
      $address['AddressLine'] = array
      (
          'Ter rivierenlaan 176',
          '',
          ''
      );
      $address['City'] = 'Antwerp';
      //$address['StateProvinceCode'] = 'MD';
      $address['PostalCode'] = '2100';
      $address['CountryCode'] = 'BE';
      $shipper['Address'] = $address;
      $shipment['Shipper'] = $shipper;

      $shipto['Name'] = 'Imani Imaginarium';
      $addressTo['AddressLine'] = '21 ARGONAUT SUITE B';
      $addressTo['City'] = 'ALISO VIEJO';
      //$addressTo['StateProvinceCode'] = 'CA';
      $addressTo['PostalCode'] = '92656';
      $addressTo['CountryCode'] = 'US';
      $addressTo['ResidentialAddressIndicator'] = '';

      $shipto['Address'] = $addressTo;
      $shipment['ShipTo'] = $shipto;

      $shipfrom['Name'] = 'Trutec';
      $addressFrom['AddressLine'] = array
      (
          'Ter rivierenlaan 176',
          '',
          ''
      );
      $addressFrom['City'] = 'Deurne';
      //$addressFrom['StateProvinceCode'] = 'MD';
      $addressFrom['PostalCode'] = '2100';
      $addressFrom['CountryCode'] = 'BE';
      $shipfrom['Address'] = $addressFrom;
      $shipment['ShipFrom'] = $shipfrom;

      $service['Code'] = '03';
      $service['Description'] = 'Service Code';
      $shipment['Service'] = $service;

      $packaging1['Code'] = '02';
      $packaging1['Description'] = 'Rate';
      $package1['PackagingType'] = $packaging1;
      $dunit1['Code'] = 'IN';
      $dunit1['Description'] = 'cm';
      $dimensions1['Length'] = '5';
      $dimensions1['Width'] = '4';
      $dimensions1['Height'] = '10';
      $dimensions1['UnitOfMeasurement'] = $dunit1;
      $package1['Dimensions'] = $dimensions1;
      $punit1['Code'] = 'KG';
      $punit1['Description'] = 'KG';
      $packageweight1['Weight'] = '4';
      $packageweight1['UnitOfMeasurement'] = $punit1;
      $package1['PackageWeight'] = $packageweight1;




      $shipment['Package'] = array( $package1 );
      $shipment['ShipmentServiceOptions'] = '';
      $shipment['LargePackageIndicator'] = '';
      $request['Shipment'] = $shipment;

      return $request;
  }

  public function getRate(){

       try {
        //nitialize soap client
    $client = new SoapClient($this->wsdl , array('soap_version' => 'SOAP_1_1','trace' => 1));

    //set endpoint url
    $client->__setLocation($this->endpointurl);


        //create soap header
        $usernameToken['Username'] = $this->userid;
        $usernameToken['Password'] = $this->passwd;
        $serviceAccessLicense['AccessLicenseNumber'] = $this->access;
        $upss['UsernameToken'] = $usernameToken;
        $upss['ServiceAccessToken'] = $serviceAccessLicense;

        $header = new SoapHeader('http://www.ups.com/XMLSchema/XOLTWS/UPSS/v1.0','UPSSecurity',$upss);
        $client->__setSoapHeaders($header);


        //get response
        return $client->__soapCall($this->operation ,array($this->processRate()));
      }

      catch(Exception $ex)
      {
          echo '<pre>';
          return print_r($client->__getLastResponse());
          echo '</pre>';
      }
  }

}



?>
4

2 回答 2

0

该错误通知您的 XML 格式正确,但您包含了一个或多个不兼容的元素。你能转储发送的 XML 吗?这可能更容易确定检测到错误的位置。我不建议根据 UPS 文档中的示例来工作,它们仅用于说明目的,并且自第一次发布以来可能尚未更新。

于 2013-01-05T01:02:26.017 回答
0

我有同样的问题,并解决了这个问题:

当我拨打测试电话时,它们会起作用。我用于测试调用的端点是

https://wwwcie.ups.com/webservices/Rate

但是,当我更改为实时通话时,我会收到错误的版本错误。该端点是:

https://onlinetools.ups.com/webservices

我查看了 wsdl 文档,发现接近结尾的部分如下所示:

<wsdl:port name="RatePort" binding="tns:RateBinding">
    <!-- Production URL -->
    <!-- <soap:address location="https://onlinetools.ups.com/webservices/Rate"/> -->
    <!-- CIE (Customer Integration Environment) URL -->
    <soap:address location="https://wwwcie.ups.com/webservices/Rate"/>
</wsdl:port>

我注意到 live 版本的端点被注释掉了,所以我将部分更改如下:

<wsdl:port name="RatePort" binding="tns:RateBinding">
    <!-- Production URL -->
    <soap:address location="https://onlinetools.ups.com/webservices/Rate"/>
    <!-- CIE (Customer Integration Environment) URL -->
    <!--<soap:address location="https://wwwcie.ups.com/webservices/Rate"/>-->
</wsdl:port>

我不确定这对其他人是否有帮助,但这最终解决了我的问题。

于 2013-04-20T23:19:26.663 回答