快遞鳥物流接口-快遞API接口查詢(php對接)

這篇文章主要介紹了關於快遞鳥查詢Api接口使用(PHP版),有着一定的參考價值,現在分享給大家,有需要的朋友可以參考一下
項目開發中,有些需求難免會用到關於快遞的一些Api接口;本篇主要介紹的是快遞的查詢Api及與其他各家的不同之處;
常用的提供快遞Api接口的有:
快遞鳥
快遞100
等等
固然,對於你小小的需求的話,快遞100可滿足你的需求;但是,當萬一某天請求次數太多,你的查詢服務就得停止,影響你的產品體驗;所以,推薦你直接使用快遞鳥,一步到位。

官方網址: http://www.kdniao.com/reg

即時查詢api: http://www.kdniao.com/api-track

需要登錄 ,申請一下 用戶ID 和 API key

可實現需求
App中直接集成實現快遞物流信息查詢Api接口
在微信公衆號中,根據用戶輸入的訂單號,我們的後臺識別訂單號並根據快遞鳥查詢快遞Api接口,實現自動查詢的功能
等等
快遞查詢Api接口
接口文檔及各開發語言Demo
查詢Api接口定義
系統級輸入參數
快遞鳥物流接口-快遞API接口查詢(php對接)
快遞鳥物流接口-快遞API接口查詢(php對接)
請求JSON參數

{

    "OrderCode" : "",

    "ShipperCode" : "SF",

    "LogisticCode" : "118650888018"}

響應JSON參數

{

    "EBusinessID" : "1109259",

    "OrderCode" : "",

    "ShipperCode" : "SF",

    "LogisticCode" : "118461988807",

    "Success" : true,

    "State" : 3,

    "Reason" : null,

    "traces" : [{

            "AcceptTime" : "2014/06/25 08:05:37",

            "AcceptStation" : "正在派件..(派件人:鄧裕富,電話:18718866310)[深圳 市]",

            "Remark" : null

        }, {

            "AcceptTime" : "2014/06/25 04:01:28",

            "AcceptStation" : "快件在 深圳集散中心 ,準備送往下一站 深圳 [深圳市]",

            "Remark" : null

        }, {

            "AcceptTime" : "2014/06/25 01:41:06",

            "AcceptStation" : "快件在 深圳集散中心 [深圳市]",

            "Remark" : null

        }, {

            "AcceptTime" : "2014/06/24 20:18:58",

            "AcceptStation" : "已收件[深圳市]",

            "Remark" : null

        }, {

            "AcceptTime" : "2014/06/24 20:55:28",

            "AcceptStation" : "快件在 深圳 ,準備送往下一站 深圳集散中心 [深圳市]",

            "Remark" : null

        }, {

            "AcceptTime" : "2014/06/25 10:23:03",

            "AcceptStation" : "派件已簽收[深圳市]",

            "Remark" : null

        }, {

            "AcceptTime" : "2014/06/25 10:23:03",

            "AcceptStation" : "簽收人是:已簽收[深圳市]",

            "Remark" : null

        }

    ]}

以PHP開發語言爲例,進行展開

<?php

//電商ID

defined('EBusinessID') or define('EBusinessID', '請到快遞鳥官網申請http://kdniao.com/reg');

//電商加密私鑰,快遞鳥提供,注意保管,不要泄漏

defined('AppKey') or define('AppKey', '請到快遞鳥官網申請http://kdniao.com/reg');

//請求url

defined('ReqURL') or define('ReqURL', 'http://api.kdniao.cc/Ebusiness/EbusinessOrderHandle.aspx');

//調用查詢物流軌跡

//---------------------------------------------

$logisticResult=getOrderTracesByJson();

echo logisticResult;

//---------------------------------------------

/**

 * Json方式 查詢訂單物流軌跡

 */

function getOrderTracesByJson(){    $requestData= "{'OrderCode':'','ShipperCode':'YTO','LogisticCode':'12345678'}";     $datas = array(

        'EBusinessID' => EBusinessID,

        'RequestType' => '1002',

        'RequestData' => urlencode($requestData) ,

        'DataType' => '2',

    );

    $datas['DataSign'] = encrypt($requestData, AppKey); $result=sendPost(ReqURL, $datas);           //根據公司業務處理返回的信息......       return $result;

}

/**

 *  post提交數據 

 * @param  string $url 請求Url

 * @param  array $datas 提交的數據 

 * @return url響應返回的html

 */

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;

}

/**

 * 電商Sign簽名生成

 * @param data 內容   

 * @param appkey Appkey

 * @return DataSign簽名

 */

function encrypt($data, $appkey) {

    return urlencode(base64_encode(md5($data.$appkey)));

}

?>

如你的產品需對接或集成快遞接口,快遞鳥是不錯的選擇;會給您提供專業的技術支持人員;查詢次數不限,有免費版和付費版可以多種套餐供選擇。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章