JAVA express a single query interface docking interface to third-party courier birds api tutorial

Scenario:

 1, site users back orders page, when a user opens a page to call the Express interface to query the user's express orders, and displays the results on the page;

 2, fast internal search, as long as the user called me and asked their name, then search directly to the express orders of the state of the user, mainly to customer service MM use;

 3, sales system, because the parameters called directly express courier birds have been received the interface will be able to obtain, so the system can automatically every week will have single sign statistics come out, the formation of statements, while giving financial and customer service MM MM use;

 4, warehouse systems, warehouse brothers will be difficult as long as the pieces come out of the line.

 

 

 

 [Butt] using flow

1, a single number and transmits express courier companies to express coding Bird

2, express logistics birds query to track state based on a single number and courier companies

3, the bird will express logistics queries to track back to the state electricity provider platform for service providers or ISV

4, electronic business platform ISV ​​or service provider receives the data and do real-time processing or data presentation applications

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.

? < 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/11586183.html