1。获取functions
try { $client = new SoapClient("http://www.fangbei.org/services/inquiryTracingAndOpcCode?wsdl"); print_r($client->__getFunctions()); print_r($client->__getTypes()); } catch (SOAPFault $e) { print $e;}
返回
Array( [0] => getTracingAndOpcCodeResponse getTracingAndOpcCode(getTracingAndOpcCode $parameters))Array( [0] => struct tracingAndOpcCodeResult { string opcCode; string tracingNo; } [1] => struct getTracingAndOpcCode { string logisticCode; } [2] => struct getTracingAndOpcCodeResponse { tracingAndOpcCodeResult return; })
2. 调用接口
$logisticCode = "3696116566481503";try { $client = new SoapClient('http://www.fangbei.org/services/inquiryTracingAndOpcCode?wsdl'); $param = array("logisticCode"=>$logisticCode); $result = $client->getTracingAndOpcCode($param); var_dump($result); if (isset($result->return->opcCode) || !empty($result->return->opcCode)){ $opcCode = $result->return->opcCode; $tracingNo = $result->return->tracingNo; var_dump($opcCode); var_dump($tracingNo); } $new_logisticCode = str_pad($logisticCode, 50, "0", STR_PAD_RIGHT); $new_opcCode = str_pad($opcCode, 20, "0", STR_PAD_RIGHT); $new_tracingNo = str_pad($tracingNo, 15, "0", STR_PAD_RIGHT); $data = array( "trackno" => $tracingNo, "opccode" => $opcCode, "logisticscode" => $logisticCode, "secret" => md5($new_tracingNo.$new_opcCode.$new_logisticCode), ); $url = "http://wechat.fangbei.org/WeChat/WeChartInterface.ashx"; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($curl); curl_close($curl); var_dump($output); $response = simplexml_load_string($output, 'SimpleXMLElement', LIBXML_NOCDATA); var_dump($response); var_dump($response->Response); } catch (SOAPFault $e) { print_r('Exception:'.$e);}