自定义 Kuaidi100.Com 快递查询函数
1、应用场景
(1)电商网站用户打开“我的订单”时调用此API显示结果
(2)物流系统对帐前调用此API查一次所有运单的签收状态
2、请求地址
http://api.kuaidi100.com/api?id=[]&com=[]&nu=[]&valicode=[]&show=[0|1|2|3]&muti=[0|1]&order=[desc|asc]
3.参考文档 http://www.kuaidi100.com/openapi/api_post.shtml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
function getOrderExpress($no, $com){ $com = strtolower($com); $cont = getKD100ExprInfo($com, $no, '0', $useApi = false); $res = json_decode($cont); if ($res->status == '200' || $res->status == '1') { if (!empty($res->data)) { foreach ($res->data as $k => $v) { $expressArr[] = array('time' => $v->time, 'context' => $v->context); } } }else{ $expressArr[] = array(); } return $expressArr; }
function getKD100ExprInfo($cmpcode, $exprno, $show = 0, $useApi = false) { $AppKey = '*****'; $url = ($useApi) ? 'http://api.kuaidi100.com/api?id='.$AppKey.'&com='.$cmpcode.'&nu='.$exprno .'&show=0&muti=1&order=asc' : "http://www.kuaidi100.com/query?type=$cmpcode&postid=$exprno"; $cont = CurlOpen($url); if (!$useApi) { $res = json_decode($cont, true); $res['data'] = array_reverse($res['data']); $cont = json_encode($res); } return $cont; } function CurlOpen($url){ $curl = curl_init(); curl_setopt ($curl, CURLOPT_URL, $url); curl_setopt ($curl, CURLOPT_HEADER,0); curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($curl, CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']); curl_setopt ($curl, CURLOPT_TIMEOUT,5); $get_content = curl_exec($curl); curl_close ($curl); return $get_content; } header('content-type:text/html;charset=utf-8'); $res = getOrderExpress('3100380429014 ', 'YUNDA'); var_dump($res);
|