Express Logistics Information Query Interface API application Example c#/php

Source: Internet
Author: User
Tags current time json openid ord

With express HTMLAPI interface to inquire about the courier logistics Information


1. API Request Address

Http://www.kuaidi100.com/applyurl?key=[]&com=[]&nu=[]

(with the parameters, please remove the brackets first)


2, incoming parameter description


Parameters

is required

Description

Key

Is

100 of the authorized key, if there are 100 key to express, you can directly use existing, if not yet applied, please click the Express query API to apply.

Com

Is

Express Company code see the following table

Nu

Is

Express number

3, supported Companies

HTMLAPI Support Express 100 all supported companies, the following list only the most common several express

Category

Express Company Code

Company name

E

   
 

EMS

EMS

 

Emsguoji

EMS International

S

   
 

Shentong

td>

Extend

 

Shunfeng

Shun Feng

Y

   
 

youzhengguonei

China Post domestic parcel/registered letter/Domestic Small bundle

 

Youzhengguoji

p> China Post International Parcel/registered letter/Foreign small Package large package


4, return the result description:

After submitting the request, the Express 100 will return you a URL address that can see the result, such as: http://www.kuaidi100.com/kuaidiresult?id=23, you directly access or invoke the URL with an IFRAME page (call method see Chapter fourth below), You can see the result. Effect:



Special Reminders:

Because EMS, Shun Fung and Shentong occasionally unstable, unstable will first show the verification code (as shown below), so do not directly to this page to parse into the form of JSON, otherwise it will be wrong! The following figure:

5, the overall use of the process

The first step, the background to create a link, call: http://www.kuaidi100.com/applyurl?key=[]&com=[]&nu=[], after the call system will return a URL address, such as: http:// Www.kuaidi100.com/kuaidiresult?id=23.

Step two: Add an IFRAME tag to the page where the results are to be displayed, and pass the result URL address to the SRC value of the IFRAME label to see the results (if you want to implement the system automatically pass the result URL into the IFRAME label SRC, refer to chapter fifth below), IFRAME Code Demonstration:

<iframe name= "kuaidi100" src= "Results URL address" width= "" height= "" 380 "marginwidth=" 0 "marginheight=" 0 "hspace=" 0 "vspace= "0" frameborder= "0" scrolling= "no" ></iframe>

If you want to implement the system to automatically pass the result URL into the iframe label of SRC, refer to the following


6, C # demonstration

First add an IFRAME, take the data, fill it

 <iframe class= "Address_b order_zhui"  height= "260px"  width= "100%"  id= "Kdframe" ></IFRAME> 
$.get ("get.aspx",  { wid: wid, openid: openid, rid: rid },                       function  (data)  {             
           $ ("#bhao"). Hide ();                          if  (data != null)  {                        
     $ ("#bhao"). Show ();                   
          //$ ("#retData"). HTML (data);                       
      $ ("#kdFrame"). attr ("src",  data);                          }                      }               );




Background:

With Htmlapi

WebClient client = new WebClient ();
String url = string. Format ("Http://www.kuaidi100.com/applyurl?key={0}&com={1}&nu={2}", Apikey, Typecom, nu);
Log. Info ("url:" + URL);
byte[] Pagedata = client. Downloaddata (URL);
String pagehtml = Encoding.ASCII.GetString (pagedata);
Log. Info ("Return URL:" + pagehtml);
Response.Write (pagehtml);



Love-Check Express API use description document

API address:

Before: http://api.ickd.cn/?com=[] &nu=[]&id=[]&type=[]&encode=[]&ord=[]&lang=[]

currently:http://api.ickd.cn/?id=[]& Secret=[]&com=[]&nu=[]&type=[]&encode=[]&ord=[]&lang=[]

parameter Description

Field      must      description
com      must      Express Company Code (English), Support Courier companies see the following list
Nu      must      Express number, length must be greater than 5 bits
ID
Secret      must
Must      Authorized ID
Authorization key, please click the Express Query API application Method
Type      Optional      Return the result type, the value is HTML | JSON (default) | Text | XML
encode      Optional    &NBSP;GBK (default) | UTF8
Ord      optional      ASC (default) |desc, returning results sort
Lang      optional     en return English results, currently only support some express (EMS, Shun Fung, DHL)

Note: You must use the UTF8 encoding for PHP's Json_decode function, and if a json_decode failure occurs, try using UTF8 encoding.


return format


Format: JSON | Text | HTML | Xml
Code: gbk| UTF8
Example:
{"Status": "3", "Message": "", "Errcode": "0", "data": [{"Time": "2013-02-23 17:10", "The Context": "Dalian City, Liaoning Province, four parts of the company's Inbox Wang Guangqi's received"} , {"Time": "2013-02-24 17:59", "The Context": "Liaoning Province Dalian company has income"},{"Time": "2013-02-24 18:11", "" "" ":" The region of Dalian City, Liaoning Province, four of the company has received "},{" Time ":" "2013-02-26 07:33", "The Context": "Changchun City, Jilin Province, the company's Zhang Jinda sent to send a member of the sending part of the phone 15948736487"},{"Time": "2013-02-26 16:47", "the context": "Customer colleagues to send and receive the family has signed to send a member Zhang Jinda"}], "HTML": "", "Mailno": "7151900624", "Exptextname": "Yuantong Express", "Expspellname": "Yuantong", "Update": "1362656241", "Cache": "186488", "Ord": "ASC"}


Field description

Field type description
status int query result status, 0|1|2|3|4,0 that query failed, 1 normal, 2 delivery, 3 have signed, 4 return, 5 other problems
Errcode int error code, 0 no error, 1 number does not exist, 2 authentication code error, 3 link query server failed, 4 program internal error, 5 program execution error, 6 Express number format error, 7 Express Company error, 10 unknown error
Message string error messages
Data array Progress
HTML string Other HTML, this field does not necessarily exist
Mailno String Express number
Expspellname String Express Company English code
Exptextname String Express Company Chinese name
update int last update time (Unix timestamp)
cache int caching time, the difference between the current time and the update, in seconds
Ord string sort, ASC | DESC


PHP Application Example

<script language= "JavaScript" >  <?php      $id = ' xxxxxxxxxxxxxxxxx ';//to HTTP ://www.ickd.cn/api/reg.html application      $url = ' http://api.ickd.cn/?com=shentong&nu= 588035733628&id= '. $id;         $data =file_get_contents ($url);         //echo  "Var data= '", $data, "'";   ?>         $ (function () {      var dataobj=<?= $data?
>;//convert to JSON object        var html= ' <tr> ';
        html+= ' <th> logistics status:</th> ';         html+= ' <td> ';                 if (dataobj.status>0) {                               html+= ' <table width= "520px"   cellspacing= "0"  cellpadding= "0"  border= "0"  style= "border-collapse: collapse;  border-spacing: 0pt; " > ';            html+= ' <tr> ';                                html+= ' <td width= ' 163 " style=" background-color:# e6f9fa;border:1px solid  #75c2ef; font-size:14px;font-weight:bold;height:20px;text-indent:15px; " > ';                               html+= ' time ';                                html+= ' </td> ';                                html+= ' <td width= ' 354 " style=" Background-color: #e6f9fa; border:1px solid # 75c2ef;font-size:14px;font-weight:bold;height:20px;text-indent:15px; " > ';                               html+= ' location and tracking progress ';                                html+= ' </td> ';                                html+= ' </tr> ';                                //variable for output data                                 $.each (Dataobj.data,function (Idx,item) {                                            html+= ' <tr> ';                                             html+= ' <td width= ' 163 " style=" border:1px solid  #dddddd; Font-size: 12px;line-height:22px;padding:3px 5px; " > ';                                            html+=item.time;//  time of each piece of data                                             html+= ' </td > ';                                            html+= ' <td width= ' 354 " style=" border:1px solid # dddddd;font-size: 12px;line-height:22px;padding:3px 5px; " > ';                                             html+=item.context;//  status of each piece of data                                            html+= ' </td> ';                                             html+= ' </tr> ';                              &nbsp});                                html+= ' </table> ';                 }else{        //Query not                               html+= ' <span style= "color: #f00" >sorry!   ' +dataobj.message+ ' </span> ';                 }                html+= ' </td></tr> ';              
      $ ("#shipping_detail"). Append (HTML);
}); </script>


If the server disables functions such as file_get_contents and Fsockopen, you can use the Curl class, as shown in the following example:

<?php
$id = ' xxxxxxxxxxxxx ';//api KEY
$com = ' Shunfeng ';//Express Company
$nu = ' 123456 ';//Express number
$type = ' J    Son ';
$encode = ' UTF8 ';
$gateway =sprintf (' http://api.ickd.cn/?id=%s&com=%s&nu=%s&encode=%s&type=%s ', $id, $com, $nu, $  Encode, $type);
$ch =curl_init ($gateway);
curl_setopt ($ch, curlopt_returntransfer,true);
curl_setopt ($ch, curlopt_header,false);
$resp =curl_exec ($ch);
$errmsg =curl_error ($ch);
if ($errmsg) {
exit ($errmsg);
}
Curl_close ($ch);
echo $resp;
? >


Currently supported list of express companies


Express Company Code
EMS Express EMS
Shentong Express Shentong
Yuantong Express Yuantong
Zhong Tong Express Zhongtong
Huitong Express Huitong
Daily Express Tiantian
Yun da Express Yunda
Shun Fung Express Shunfeng
Home Urgent Delivery Zhaijisong
CCEs Express CCEs
China Post flat Mail pingyou
The Morning Star Xingchen
Fast Express sure
Quick Express Kuaijie
China Railway Express Zhongtie
AAE Express AAE
Chit-Courier Anjie
Andrew Xinda Express Anxinda
US Express Chengguang
Daejeon Logistics Datian
Darbond Logistics Debang
DHL Express DHL
Dpex Express Dpex
D-Speed Express DSU
FedEx International FedEx
FedEx Domestic FEDEXCN
The original aviation Logistics Feihang
Funda Express Fengda
Fei Kang da Express fkd
Fast Tatsu Express Fkdex
Tiandi Huayu Logistics Huayu
Jia Ji Express Jiaji
Jia Yi Logistics Jiayi
Canada Express Jiayunmei
Jin Yue Express Jinyue
Union Hao Tong Logistics | Express Lianhaotong
US Express Longbang
Air Courier Minhang
Hong Kong can reach the Nengda
OCS Express OCS
All Morning Express Quanchen
Full Peak Express Quanfeng
All Nippon Express Quanritong
Full One Express Quanyi
such as the Wind Tatsu Express Rufeng
Shengfeng Logistics Shengfeng
Shenghui Logistics Shenghui
TNT Express TNT
UPS UPS
Million Home logistics Wanjia
New State Logistics Xinbang
Xin Fei Hong Express xinfeihong
Xinfeng Express Xinfeng
Asian Wind Express Yafeng
A Bang Express Yibang
Excellent Speed Express Yousu
Far into the logistics Yuancheng
Nenjide Cheng Yuanzhi
The more abundant express Yuefeng
Express China Express Yuntong
Source Wei Feng Ywfex
China Postal Logistics Zhongyou


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.