php api express Birds single query interface to call free docking

Bird integrated express courier single query API interface, you can dock at the same time SF Express query, in the pass, Shen Tong, tact, rhyme, BES, EMS and other domestic and 418 logistics Express interfaces inquiries. The express logistics companies, providing express a single interface to automatically identify, express courier single query interfaces and other logistics services. For business enterprise, ERP services business, this interface integrated into their own software, increasing the competitiveness of enterprises. But there is a drawback, it is necessary respectively to the major express delivery companies, namely debug interface, high maintenance cost, convenient management.

First, the interface scenario
1. After the electronic business platform for shopping, tracking purchase orders through the logistics, the logistics information call this API to get details
2. freight reconciliation process, a key to get the consignment logistics status
3. batch tracking and acquisition logistics waybill information

Docking process

Bird Express website and application interfaces KEY Certification - docking interface - Commissioning - on-line use

Second, the docking ready
1. Log fast courier birds registered account
2. Get Developer account information (ID, API Key), log in to see the courier birds background
3. Technical FBI, and complete the commissioning, logistics query api address: HTTP: //www.kdniao.com/api-track
4. integrated express logistics query interface in your software

Third, the technical docking
Express provides courier birds query interface, support 418 express logistics query, covering major domestic and international courier service enterprise single query, timely information, data integrity.

Log birds Express official website supports a variety of development languages ​​docking, including JAVA, C #, PHP and so on. Depending on your development language, select the reference code samples corresponding to the following PHP code as an example:

? < PHP
 // electricity supplier ID 
defined ( 'EBusinessID') or the DEFINE ( 'EBusinessID', '123456' );
 // electricity providers private key encryption, providing courier birds, take good care not to leak 
defined ( 'AppKey') or DEFINE ( 'the 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 ";// courier company referred to, there are official documents 
$ Number The = "12345678"; //Express orders 

// call the inquiry logistics trajectory 
// --------------------------------------- ------ 
$ logisticResult = getOrderTracesByJson ( $ KGS , $ Number );
 echo  $ logisticResult ; 

// parse data 
$ data = of json_decode ( $ logisticResult , to true ); 


IF ( $ data [ 'Success'] == to true ) { // return information about a successful 
    $ 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'] "a." ; 
    } 
} 
echo "your query is a single number:." $ Data [ 'LogisticCode']. " a 
stream information: a ." $ STR "." ;
} 

// --------------------------------------------- 
 
/ * * 
 * Json way inquiry Order logistics trajectory 
 * /
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);    
    
    //The returned information processing business ...... 
    return  $ Result ; 
} 
 
/ * * 
 * POST data submitted 
 * @param string $ url requests the Url 
 * @param Array data submitted DATAS $ 
 * @return url response returned html 
 * / 
function sendPost ( $ URL , $ DATAS ) {
     $ Temps = Array ();    
     the 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)));
}

?>

 

Guess you like

Origin www.cnblogs.com/kdn2019/p/11571970.html