Home  >  Article  >  Backend Development  >  Various express inquiries--Api interface_php digest

Various express inquiries--Api interface_php digest

WBOY
WBOYOriginal
2016-05-16 19:53:491501browse


Authorization successful my key

If you reprint, please indicate the source http://blog.csdn.net/qxs965266509, please pay attention!

Aicha Express API instruction document API address:

Previously: 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 Is it necessary Note that com must have a courier company code (English). The supported courier companies are listed below. nu must have a courier order number, and the length must be greater than 5 digits id
secret must
ID that must be authorized
Authorize KEY, to apply please click Express Query API application method type optional return result type, the values ​​are html | json (default) | text | xmlencode optional gbk (default) | utf8ord optional asc (default) | desc, return results Sorting lang is optionalenReturn English results, currently only supports some express delivery (EMS, SF Express, DHL)Note:When using PHP’s json_decode function, UTF8 encoding must be used. If json_decode appears Failure, please try using UTF8 encoding. Return format: json | text | html | xml
Encoding: GBK| UTF8
Example: {"status":"3","message":"","errCode":"0","data":[{"time":"2013-02-23 17:10","context" :"The recipient Wang Guang of the Fourth Department Company in Zhongshan District, Dalian City, Liaoning Province has received the receipt"},{"time":"2013-02-24 17:59","context":"The company in Dalian City, Liaoning Province has received the receipt "},{"time":"2013-02-24 18:11","context":"The Fourth Department Company of Zhongshan District, Dalian City, Liaoning Province has received the receipt"},{"time":"2013-02-26 07 ; ":"Customer colleagues send and receive family members and have signed for delivery person Zhang Jinda"}],"html":"","mailNo":"7151900624","expTextName":"YTO Express","expSpellName":"yuantong"," update":"1362656241","cache":"186488","ord":"ASC"}Field description Field type Description statusint query result status, 0|1|2|3|4, 0 means query failed, 1 normal, 2 dispatching, 3 signed for, 4 returned, 5 other problems errCodeint error code, 0 no error, 1 order number not Exists, 2 verification code error, 3 link query server failure, 4 internal program error, 5 program execution error, 6 express delivery number format error, 7 express company error, 10 unknown error messagestring error message dataarray progress htmlstring other HTML, this field is not There must be mailNostring courier number expSpellNamestring courier company English code expTextNamestring courier company Chinese name updateint last update time (unix timestamp) cacheint cache time, the difference between the current time and update, the unit is: seconds ordstring sorting, ASC | DESCphp application Example
<script language="javascript"> <&#63;php$id='xxxxxxxxxxxxxxxxx';
//到<a href="http://www.ickd.cn/api/reg.html">http://www.ickd.cn/api/reg.html</a>申请
$url='http://api.ickd.cn/&#63;com=shentong&nu=588035733628&id='.$id; $data=file_get_contents($url); 
//echo "var data='",$data,"'"; &#63;> $(function(){
 var dataObj=<&#63;=$data&#63;>;
//转换为json对象 var html='<tr>'; html+='<th>物流状态:</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+='时间'; 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+='地点和跟踪进度'; html+='</td>'; html+='</tr>'; //输出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;// 每条数据的时间  html+='</td>';  html+='<td width="354" style="border:1px solid #dddddd;font-size: 12px;line-height:22px;padding:3px 5px;">';  html+=item.context;// 每条数据的状态  html+='</td>';  html+='</tr>'; }); html+='</table>'; }else{
//查询不到 
html+='<span style="color:#f00">Sorry! '+dataObj.message+'</span>'; }
 html+='</td></tr>'; $("#shipping_detail").append(html);});</script>

If the server has disabled functions such as file_get_contents and fsockopen, you can use the CURL class. The example is as follows:

<&#63;php $id='xxxxxxxxxxxxx';
//API KEY $com='shunfeng';
//快递公司 $nu='123456';
//快递单号 $type='json';
 $encode='utf8'; 
$gateway=sprintf('http://api.ickd.cn/&#63;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;&#63;>

ASP application example

6d17b4a52b39e6ad4e2ecd645079f34d4 Then 'The status is not 4, error
Response.Write "{status:0,errCode:100,message:'Error getting data'}"
Exit Function
End If
'Readystate attribute returns the current status of the XML file data. The return values ​​are as follows:
'0-UNINITIALIZED: XML object was generated, but no file was loaded.
'1-LOADING: Loading is in progress, but file parsing has not yet begun.
'2-LOADED: Some files have been loaded and parsed, but the object model has not yet taken effect.
'3-INTERACTIVE: Only valid for loaded partial files, in which case the object model is valid but read-only.
'4-COMPLETED: The file has been completely loaded, indicating that the loading is successful.

fopen=objXML.ResponseBody
fopen=BytesToBstr(objXML.ResponseBody)' returns information and uses function definition encoding. If you need to transcode, please select

Set objXML=Nothing'Close
If Err.numbera8093152e673feb7aba1828c435320940 Then
Response.Write "{status:0,errCode:100,message:'Error getting data'}"
Err.Clear
End If
End Function

'Page encoding conversion
Function BytesToBstr(body)
Dim objstream
Set objstream = Server.CreateObject("Adodb.Stream") '//Call adodb.stream component
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = "GBK" 'Convert the original default encoding to GB2312 encoding, otherwise directly using XMLHTTP to call a webpage with Chinese characters will result in garbled codes
BytesToBstr = objstream.ReadText
objstream.Close
Set objstream = Nothing
End Function

'Enter query results
Response.Write ResponseTxt
%>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn