All kinds of express Query--api Interface _php Digest

Source: Internet
Author: User
Tags current time error code function definition object model ord dns names


Authorization succeeded my key

If reproduced, please indicate from this source http://blog.csdn.net/qxs965266509, must pay attention!

Love check Express API use description document API address:

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

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

Parameter descriptionFieldWhether you mustDescription COM must express company code (English), supported by courier companies see the following list Nu must express number, length must be greater than 5-bit ID
Secret must
ID that must be authorized
Authorization key, please click on the Express Query API application type optional return result types, values are HTML | JSON (default) | Text | Xmlencode Optional GBK (default) | Utf8ord optional ASC (default) |desc, returning result sort Lang optionalenBack to English results, currently only support some express (EMS, Shun Fung, DHL)Note:You must use the UTF8 encoding when using PHP's Json_decode function, and if Json_decode fails, try using UTF8 encoding. Return format format:JSON| Text | HTML | Xml
Coding:GBK| UTF8
Example: {"Status": "3", "Message": "", "Errcode": "0", "data": [{"Time": "2013-02-23 17:10", "The Context": "Liaoning Province, Dalian City, four parts of the company's collection of members Wang Guangqi's Received "},{": "2013-02-24 17:59", "context": "Liaoning Province Dalian Company has revenue"},{"Time": "2013-02-24 18:11", "context": "Liaoning Province, Dalian City, 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 telephone 15948736487 "},{" Time ":" 2013-02-26 16:47 "," 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 DescriptionFieldType Description Statusint Query result status, 0|1|2|3|4,0 indicates that the query failed, 1 normal, 2 delivery, 3 have signed, 4 return, 5 other problems errcodeint error code, 0 error, 1 number no, 2 wrong number of the verification Code, 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 messagestring error message DataArray Progress htmlstring other HTML, This field does not necessarily exist mailnostring Express number expspellnamestring Express Company English Code Exptextnamestring Express Company Chinese name Updateint last update time (Unix timestamp) Cacheint cache time , the difference between the current time and the update, in units: seconds ordstring sort, ASC | descphp Application Example

<script language= "JavaScript" > <?php$id= ' xxxxxxxxxxxxxxxxx '; To http://www.ickd.cn/api/reg.html apply $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> '; The output data of the child object variable $.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;//the 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;//the status of each piece of data html+= ' </td> '; html+= ' </tr> '; }); html+= ' </table> '; }else{//Query not to 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 = ' json ';
 $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;? >

ASP Application Example

<%
response.charset= "gb2312"
Server.ScriptTimeout = 999999999

Dim Retrieval
Dim url,nu,com
com = Request ("com") ' Company
Nu = Request ("Nu") ' Dan Hao

Dim Appkey,sendurl,responsetxt
Appkey = "Xxxxxxxxxx" replace xxxxxx with the key you requested in http://www.ickd.cn/reg.html
Sendurl = "http://api.ickd.cn/?id=" &AppKey& "&com=" &com& "&nu=" &nu& "&type=json" &ENCODE=GBK "' If you use UTF8, make sure Encode=utf8
' Response.Write Sendurl

' Send data
Responsetxt=fopen (Sendurl) '//Get the source code function

' Call Send data component
Function fopen (URL)
Dim Objxml
' Set objxml=createobject (' MSXML2. serverxmlhttp.3.0 ")" calls the XMLHTTP component, if the server does not support, please swap with one of the following two to try again
Set objxml=server.createobject ("Microsoft.XMLHTTP")
' Set objxml=server.createobject (' MSXML2. xmlhttp.4.0 ")

' Objxml.settimeouts 5000, 5000, 30000, 10000 ' resolves the timeout for DNS names, establishes the timeout for Winsock connections, the timeout for sending data, and the time-out period for receiving response. Unit milliseconds
Objxml.open "Get", Url,false ' gets API query data synchronously
Objxml.send () ' Send
If objxml.readystate<>4 Then ' state is not 4, error
Response.Write ' {status:0,errcode:100,message: ' Get data error '} '
Exit Function
End If
' ReadyState property, returns the current status of the XML file data, with the following values:
The ' 0-uninitialized:xml object was generated, but no files were loaded.
' 1-loading: Loader is in progress, but file has not started parsing.
' 2-loaded: Part of the file has been loaded and parsed, but the object model has not yet taken effect.
' 3-interactive: Only valid for partially loaded files, in which case the object model is valid but read-only.
' 4-completed: The file is fully loaded, representing the success of the load.

Fopen=objxml.responsebody
Fopen=bytestobstr (objxml.responsebody) ' returns information, with function definition encoding, if you need transcoding please select

Set objxml=nothing ' off
If err.number<>0 Then
Response.Write ' {status:0,errcode:100,message: ' Get data error '} '
Err.Clear
End If
End Function

' Page encoding Conversion
Function Bytestobstr (body)
Dim objstream
Set objstream = Server.CreateObject ("ADODB.stream") '//calling ADODB.stream component
Objstream. Type = 1
Objstream. Mode =3
Objstream. Open
Objstream. Write body
Objstream. Position = 0
Objstream. Type = 2
Objstream. Charset = "GBK" converts the original default encoding into GB2312 encoding, otherwise directly using the XMLHTTP to invoke the Web page with Chinese characters will be garbled
Bytestobstr = objstream. ReadText
Objstream. Close
Set objstream = Nothing
End Function

' Enter query results
Response.Write Responsetxt
%>

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.