1. 程式人生 > >YII中順豐快遞查詢API(無驗證碼)

YII中順豐快遞查詢API(無驗證碼)

順豐快遞查詢API(無驗證碼)


yii中:baseContoller.php


public function getSFexpressByNo($shipping_no){

$url="http://syt.sf-express.com:80/css/myquery/waybillNoMobile.action";

$params="no=".trim($shipping_no)."&local=zh_CN";//243140447489

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_USERAGENT, "S.F. Express 1.61");

curl_setopt($ch, CURLOPT_POSTFIELDS, $params);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$data = curl_exec($ch);

curl_close($ch);

$data = json_decode($data);

$info = "<div align='left' style='margin:10px;'><h3>快遞單號:".$shipping_no."</h3>";

$info .= "<p><br>";

if($data->result[0]->barList){

$barList = $data->result[0]->barList;

foreach($barList as $bar){

$info .= $bar->barScanDt." ".$bar->barScanTm." ";//時間

$info .= $bar->remark." ";//時間

$info .= $bar->zoneName."<br>";//時間

}

}

$info .= "</p></div>";

return $info;

}

//呼叫
<?php
if($shippingAddress->shipping_no){
echo $this->getSFexpressByNo($shippingAddress->shipping_no);
}else{
echo $orderShippingMethod->method_url;
}
?>