Home > Article > Backend Development > Various express inquiries--Api interface, express delivery--Api interface_PHP tutorial
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
<script language="javascript"> <?php$id='xxxxxxxxxxxxxxxxx'; //到http://www.ickd.cn/api/reg.html申请 $url='http://api.ickd.cn/?com=shentong&nu=588035733628&id='.$id; $data=file_get_contents($url); //echo "var data='",$data,"'"; ?> $(function(){ var dataObj=<?=$data?>; //转换为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:
<?php $id='xxxxxxxxxxxxx'; //API KEY $com='shunfeng'; //快递公司 $nu='123456'; //快递单号 $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
5630ed3a3d532a25264406317290d4a74 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 started.
'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
%>