It is suitable for docking, such as crowd, enterprise, e-commerce website, WeChat public number platform, which involves regular delivery and express delivery. Support more than 300 domestic and foreign express delivery and logistics companies' express bill number one-stop query.
instructions:
1. Kuadidi api.php doesn't need to change anything
2.example.php follow the instructions
3. If there is anything unclear, please go to the official website of express (http://www.kuaidi.com/), or call the express website for consultation
Code of kuadidi api.php
<?php /** * Created by http://www.kuaidi.com * User: Kaka * Date: 2018.9.20 * Logistics information query interface SDK * wechat:fangkangfk * Version 1.2 */ class KuaidiAPI{ private $_APPKEY = ''; private $_APIURL = "http://highapi.kuaidi.com/openapi-querycountordernumber.html?"; private $_show = 0; private $_muti = 0; private $_order = 'desc'; /** * You get the express network interface query KEY. * @param string $key */ public function KuaidiAPi($key){ $this->_APPKEY = $key; } /** * Set the data return type. 0: return json string; 1: return xml object * @param number $show */ public function setShow($show = 0){ $this->_show = $show; } /** * Set the number of returned logistics information entries, 0: return multiple lines of complete information; 1: return only one line of information * @param number $muti */ public function setMuti($muti = 0){ $this->_muti = $muti; } /** * Set the sorting of returned logistics information. desc: arrange by time from new to old; asc: arrange by time from old to new * @param string $order */ public function setOrder($order = 'desc'){ $this->_order = $order; } /** * Query logistics information, transfer in doc No, * @param Logistics No. $nu * @param Company code $com the code of the express company to be queried does not support Chinese. Please refer to the code document of the express company for details. If it is not filled in, the company will be automatically matched according to the document number by default. Note: the success rate of order matching is higher than 95%. * @throws Exception * @return array */ public function query($nu, $com=''){ if (function_exists('curl_init') == 1) { $url = $this->_APIURL; $dataArr = array( 'id' => $this->_APPKEY, 'com' => $com, 'nu' => $nu, 'show' => $this->_show, 'muti' => $this->_muti, 'order' => $this->_order ); foreach ($dataArr as $key => $value) { $url .= $key . '=' . $value . "&"; } // echo $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_TIMEOUT, 10); $kuaidresult = curl_exec($curl); curl_close($curl); if($this->_show == 0){ $result = json_decode($kuaidresult, true); }else{ $result = $kuaidresult; } return $result; }else{ throw new Exception("Please install curl plugin", 1); } } }
example.php code
<?php include 'KuaidiAPI.php'; //Change to your own KEY $key = 'c684ab43a28bc3caea53570666ce9762'; $kuaidichaxun = new KuaidiAPi($key); //Set the return format. 0: return json string; 1: return xml object //$kuaidichaxun - > setshow (1); / / optional, default to 0, return json format //Return the number of logistics information entries. 0: return multiple lines of complete information; 1: return only one line of information //$kuaidichaxun - > setmuti (1); / / optional, 0 by default //Set the sorting of returned logistics information. desc: arrange by time from new to old; asc: arrange by time from old to new //$kuaidichaxun->setOrder('asc'); //query $result = $kuaidichaxun->query('111111', 'quanfengkuaidi'); //With the company's short code query, see the document for the short code list //$result = $kuaidichaxun->query('111111', 'quanfengkuaidi'); //111111 express bill No //quanfengkuaidi express company name var_dump($result); ?>