2

UPS から xml レートのソープ フィードを取得しようとしています。

現在、「間違ったバージョン」(__Soapcall Exeption) または「0FailureHard10002The XML document is wellformed but the document is not valid1」(サーバーまたは 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 が正しくフォーマットされているが、互換性のない要素が 1 つ以上含まれていることを通知します。送信された 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>

ライブ バージョンのエンドポイントがコメント アウトされていることに気付いたので、次のようにセクションを変更しました。

<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 に答える