Bird express a single number identifying logistics track information query interface Api (PHP version)

This article describes the logistics track information about the bird express a single number to identify the query interface Api, has a certain reference value, now for everyone to share, there is a need of a friend for reference

background:

Project development, some demand will inevitably use some Api interfaces on the courier; This part describes the query Api Express and other various differences;

Commonly used to provide express Api interfaces: Express birds, rookie, express delivery companies, etc.

As we have used some api interface, you will find that you are applying for an account number or key calls a day Api interfaces are restricted, some 2000 times / day, some 5000 times / second; the only thing you feel trouble that requires the user to add the chain, while the user is not required to add birds express the chain. For users without portal, it is nothing more than a very demanding; and, the excess fee to use.

Express birds, Api interface is a request does not limit the number of yo and permanently free

Of course, you little demand for it, some interfaces can meet your needs; however, in case one day when the request too many times, you have to stop inquiry service, affect your product experience; therefore, it is recommended that you directly the use of courier birds, in one step.

Scenarios

 

 

Demand can be achieved

  1. App directly implement integrated express logistics information inquiry Api Interface

  2. In the micro-channel public number, a number based on the order entered by the user, the background of our order number and the identification of birds in accordance with the express courier Api query interface, automatic query function

  3. and many more

Key applications

Docking preparation
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

According to your information, in order to be filled out completely, click to submit an application.

After a successful login, you can see the key ID and other information, these information requests can query other interfaces Api

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.

Login courier birds 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/11585864.html