0

我需要向 Estes 发送 SOAP 请求以检索报价。我在执行此操作时遇到了麻烦,因为我使用过的其他 API 要么发布 XML,要么使用 URL 字符串。这对我来说有点不同。

我相信我的问题是我无法弄清楚需要为请求发送的数组。

<?xml version="1.0" encoding="UTF-8"?>
        <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:rat="http://ws.estesexpress.com/ratequote" xmlns:rat1="http://ws.estesexpress.com/schema/2012/12/ratequote">
           <soapenv:Header>
              <rat:auth>
                 <rat:user>XXXXX</rat:user>
                 <rat:password>XXXX</rat:password>
              </rat:auth>
           </soapenv:Header>
           <soapenv:Body>
              <rat1:rateRequest>
                 <rat1:requestID>XXXXXX</rat1:requestID>
                 <rat1:account>XXXXXXX</rat1:account>
                 <rat1:originPoint>
                    <rat1:countryCode>XX</rat1:countryCode>
                    <rat1:postalCode>XXXXX</rat1:postalCode>
                    <rat1:city>XXXXXX</rat1:city>
                    <rat1:stateProvince>XX</rat1:stateProvince>
                 </rat1:originPoint>
                 <rat1:destinationPoint>
                    <rat1:countryCode>XX</rat1:countryCode>
                    <rat1:postalCode>XXXXX</rat1:postalCode>
                 </rat1:destinationPoint>
                 <rat1:payor>X</rat1:payor>
                 <rat1:terms>XX</rat1:terms>
                 <rat1:stackable>X</rat1:stackable>
                 <rat1:baseCommodities>
                    <rat1:commodity>
                       <rat1:class>X</rat1:class>
                       <rat1:weight>XXX</rat1:weight>
                    </rat1:commodity>
                 </rat1:baseCommodities>
              </rat1:rateRequest>
           </soapenv:Body>
        </soapenv:Envelope>

这是我之前使用的代码,它不起作用。

        <?php
    $client = new SoapClient("https://www.estes-express.com/rating/ratequote/services/RateQuoteService?wsdl");

    $request_object = array(
          "header"=>array(
          "auth"=>array(
                "user"=>"XXXXX",
                "password"=>"XXXXX",
                )
          ),
          "rateRequest"=>array(
                "requestID"=>"XXXXXXXXXXXXXXX",
                "account"=>"XXXXXX",
          ),
            "originPoint"=>array(
                "countryCode"=>"XX",
                "postalCode"=>"XXXXX",
                "city"=>"XXXXX",
                "stateProvince"=>"XX",
          ),
            "destinationPoint"=>array(
                "countryCode"=>"XX",
                "postalCode"=>"XXXXX",
          ),
          "payor"=> "X",
          "terms"=> "XXXX",
          "stackable"=> "X",
            "baseCommodities"=>array(
                "commodity"=>array(
                    "class"=>"XX",
                    "weight"=>"XXXX",
                )
            ),
        );

        $result = $client->rateRequest(array("request"=>$request_object));

        var_dump($result);
    ?>

这是错误

        Fatal error: Uncaught SoapFault exception: [Client] Function ("rateRequest") is not a valid method for this service in /home/content/54/11307354/html/test/new/estes.php:36 
        Stack trace: #0 /home/content/54/11307354/html/test/new/estes.php(36): SoapClient->__call('rateRequest', Array) #1 /home/content/54/11307354/html/test/new/estes.php(36): 
        SoapClient->rateRequest(Array) #2 {main} thrown in /home/content/54/11307354/html/test/new/estes.php on line 36
4

4 回答 4

1

这就是我从类数组和权重构建商品数组的方式

array:

// load the $params commodities array $comArray = array(); for ($i=0; $i<count($class_tbl); $i++) { $comArray[] = array('class'=>$class_tbl[$i], 'weight'=>$weight_tbl[$i]); }

以下代码格式化附件数组

if($inside == "Yes") {
      $accArray[$i] = "INS";   
        ++$i;
  }
    if($liftgate == "Yes") {
      $accArray[$i] = "LGATE";   
        ++$i;
  }
    if($call == "Yes") {
      $accArray[$i] = "NCM";   
        ++$i;
  }

如果交付对象不是企业(例如学校、教堂等),则 Estes 目标辅助代码也应添加到 $accArray 数组中。

于 2013-10-31T00:57:07.257 回答
1

这是传递给 Estes API 的 $params 数组

$params = array( 
    "requestID"         => "xxxxxxxx",
    "account"           => "xxxxxxxx",
    "originPoint"       => array('countryCode' => 'US', 'postalCode' => $fromzip),
    "destinationPoint"  => array('countryCode' => 'US', 'postalCode' => $shipzip),
    "payor"             => 'T',
    "terms"             => 'PPD',
    "stackable"         => 'N',
            "baseCommodities"   => array('commodity' => $comArray ),
            "accessorials"      => array('accessorialCode' => $accArray) 

如果没有附件,则需要从 $params 数组中删除该数组
);// 如果没有辅助代码,则删除辅助条目 if(sizeof($accArray) == 0){ $params = array_slice($params, 0, 8); // 删除附件条目 }

于 2013-10-31T01:09:03.713 回答
1

看看我们的肥皂电话中是否有任何帮助。我们正在做这样的肥皂电话:

// define transaction arrays
$url = "http://www.estes-express.com/rating/ratequote/services/RateQuoteService?wsdl";
$username = 'xxxxxxxx';
$password = 'xxxxxxxx';

// setting a connection timeout of five seconds
$client = new SoapClient($url, array("trace" => true,
         "exceptions" => true,
         "connection_timeout" => 5,
         "features" => SOAP_WAIT_ONE_WAY_CALLS,
         "cache_wsdl" => WSDL_CACHE_NONE));
    $old = ini_get('default_socket_timeout');
ini_set('default_socket_timeout', 5);

//Prepare SoapHeader parameters
$cred = array(
    'user'      => $username,
    'password'  => $password
);

$header = new SoapHeader('http://ws.estesexpress.com/ratequote', 'auth', $cred);
$client->__setSoapHeaders($header);

$params = array(
    "requestID"         => "xxxxxxxx",
    "account"           => "xxxxxxxx",
    "originPoint"       => array('countryCode' => 'US', 'postalCode' => $fromzip),
    "destinationPoint"  => array('countryCode' => 'US', 'postalCode' => $shipzip),
    "payor"             => 'T',
    "terms"             => 'PPD',
    "stackable"         => 'N',
            "baseCommodities"   => array('commodity' => $comArray ),
            "accessorials"      => array('accessorialCode' => $accArray)
);
    // remove accessorials entry if no accessorial codes
    if(count($accArray) == 0){
        $params = array_slice($params, 0, 8); // remove accesorials entry
    }

 // call Estes API and catch any errors
    try {
 $reply = $client->getQuote($params);
}
catch(SoapFault $e){
       // handle issues returned by the web service
       //echo "Estes soap fault<br>" . $e . "<br>";
       $edit_error_msg = "Estes quote API timed out or failed to return a quote";
         return "0.00";
}
catch(Exception $e){
       // handle PHP issues with the request
       //echo "PHP soap exception<br>" . $e . "<br>";
         $edit_error_msg = "Estes quote API timed out or failed to return a quote";
         return "0.00";
}
    unset($client);
  ini_set('default_socket_timeout', $old);

 // print_r($reply);
于 2018-06-19T17:24:56.047 回答
0

使用验证器查找 WSDL,看起来可用的两种方法是echogetQuote.

查看 WSDL 本身,您也可以看到:

<wsdl:operation name="getQuote">
    <wsdl:input name="rateRequest" message="tns:rateRequestMsg"></wsdl:input>
    <wsdl:output name="quoteInfo" message="tns:rateQuoteMsg"></wsdl:output>
    <wsdl:fault name="schemaErrorMessage" message="tns:schemaErrorMsg"></wsdl:fault>
    <wsdl:fault name="generalErrorMessage" message="tns:generalErrorMsg"></wsdl:fault>
</wsdl:operation>

尝试调用getQuote而不是rateRequest.

$result = $client->__soapCall('getQuote', array("request"=>$request_object));
于 2013-09-12T16:00:44.193 回答