需要帮助将SOAP请求发送到Estes

时间:2013-09-12 14:51:25

标签: php xml soap

我需要向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 个答案:

答案 0 :(得分:1)

这就是我如何从类数组中构建商品数组&amp;重量

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数组中,如果交付给非企业(例如学校,教堂等)

答案 1 :(得分: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); //删除accesorials条目         }

答案 2 :(得分: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);

答案 3 :(得分:0)

Looking up the WSDL with a validator看起来可用的两种方法是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));