Background:
Share an article about synchronizing the logistics track to the local server in the e-commerce system. The current scheme uses the express bird integration api as the data source interface, which is free of charge, but the function provided is very powerful, with a special after-sales maintenance team. demo can be called in multiple languages
The realization idea is roughly divided into three steps:
Step 1: submit subscription information to express bird interface
Step 2: after receiving the request, the express bird will track the callback address and push the express information to the callback interface
Step 3: after receiving the data pushed by Post, the callback interface performs logical processing
Note: it is recommended to deploy an API project separately for the address of the callback, not under the main program, or require signature verification for the callback when submitting the subscription.
1, Docking process
Express bird website applies for interface KEY and certifies - docking interface - Debugging - online use
2, Docking preparation 1 Log in to express bird to sign up for express account 2. Obtain the developer account information (ID, API key), Log in to express bird background to view 3. Carry out technical joint debugging and complete debugging, and query api address of logistics track: http://www.kdniao.com/api-trackĀ 4. Integrate express logistics query interface in your software
3, The technology connects with the Express query interface provided by express bird, supports 418 express logistics queries, covering the single number queries of domestic and foreign mainstream express service enterprises, with timely information and complete data.
Log in to express bird official website to support multiple development language docking, including JAVA, C, PHP, etc. According to your development language, choose to refer to the corresponding code examples. Take PHP code as an example:
Attached below is the detailed code: (php)
<?php //Electricity supplier ID defined('EBusinessID') or define('EBusinessID', '123456'); //E-commerce encrypts the private key, which is provided by express bird. Take care not to disclose defined('AppKey') or define('AppKey', '1234567890'); //Request url: test address //defined('ReqURL') or define('ReqURL', 'http://sandboxapi.kdniao.cc:8080/kdniaosandbox/gateway/exterfaceInvoke.json'); //Request url: official address defined('ReqURL') or define('ReqURL', 'http://api.kdniao.cc/Ebusiness/EbusinessOrderHandle.aspx'); $kgs = "JD";//Express company abbreviation, official document $number = "12345678";//Courier number //Call to query logistics track //--------------------------------------------- $logisticResult=getOrderTracesByJson($kgs,$number); echo $logisticResult; //Analytical data $data = json_decode($logisticResult,true); if($data['Success'] == true){//Information returned successfully $str = ""; if(isset($data['Traces']) && !empty($data['Traces'])){ for($i=0;$i<count($data['Traces']);$i++){ $str .= "Time:".$data['Traces'][$i]['AcceptTime']."<br/>Address:".$data['Traces'][$i]['AcceptStation']."<br/>"; } } echo "The number you inquired is:".$data['LogisticCode']."<br/> //Logistics information: < br / > ". $str."; } //--------------------------------------------- /** * Json Query order logistics track by */ function getOrderTracesByJson($kgs,$number){ $requestData= "{'OrderCode':'','ShipperCode':'$kgs','LogisticCode':'$number'}"; $datas = array( 'EBusinessID' => EBusinessID, 'RequestType' => '1002', 'RequestData' => urlencode($requestData) , 'DataType' => '2', ); $datas['DataSign'] = encrypt($requestData, AppKey); $result=sendPost(ReqURL, $datas); //Information returned according to the company's business processing return $result; } /** * post Submit data * @param string $url Request Url * @param array $datas Submitted data * @return url html returned in response */ function sendPost($url, $datas) { $temps = array(); foreach ($datas as $key => $value) { $temps[] = sprintf('%s=%s', $key, $value); } $post_data = implode('&', $temps); $url_info = parse_url($url); if(empty($url_info['port'])) { $url_info['port']=80; } $httpheader = "POST " . $url_info['path'] . " HTTP/1.0\r\n"; $httpheader.= "Host:" . $url_info['host'] . "\r\n"; $httpheader.= "Content-Type:application/x-www-form-urlencoded\r\n"; $httpheader.= "Content-Length:" . strlen($post_data) . "\r\n"; $httpheader.= "Connection:close\r\n\r\n"; $httpheader.= $post_data; $fd = fsockopen($url_info['host'], $url_info['port']); fwrite($fd, $httpheader); $gets = ""; $headerFlag = true; while (!feof($fd)) { if (($header = @fgets($fd)) && ($header == "\r\n" || $header == "\n")) { break; } } while (!feof($fd)) { $gets.= fread($fd, 128); } fclose($fd); return $gets; } /** * E-commerce Sign generation * @param data content * @param appkey Appkey * @return DataSign autograph */ function encrypt($data, $appkey) { return urlencode(base64_encode(md5($data.$appkey))); } ?>