《PHP應用:各種快遞查詢--Api接口》要點:
本文介紹了PHP應用:各種快遞查詢--Api接口,希望對您有用。如果有疑問,可以聯系我們。
PHP應用
授權勝利我的密鑰
PHP應用如有轉載,請標明來自此出處http://blog.csdn.net/qxs965266509,必需注意!
PHP應用愛查快遞API使用闡明文檔API地址:
PHP應用以前:http://api.ickd.cn/?com=[]&nu=[]&id=[]&type=[]&encode=[]&ord=[]&lang=[]
PHP應用目前:http://api.ickd.cn/?id=[]&secret=[]&com=[]&nu=[]&type=[]&encode=[]&ord=[]&lang=[]
PHP應用參數闡明
字段 是否必須 說明com必須快遞公司代碼(英文),所支持快遞公司見如下列表nu必須快遞單號,長度必須大于5位idPHP應用
<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>
PHP應用若服務器禁用了file_get_contents和fsockopen等函數,可使用CURL類,示例如下:
PHP應用
<?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;?>
PHP應用ASP應用示例
PHP應用<%
Response.Charset="gb2312"?
Server.ScriptTimeout = 999999999
PHP應用Dim Retrieval
Dim url,nu,com
com = Request("com")'公司
nu = Request("nu")'單號
PHP應用Dim AppKey,SendURL,ResponseTxt
AppKey = "xxxxxxxxxx" '請將XXXXXX替換成您在http://www.ickd.cn/reg.html申請到的KEY
SendURL ="http://api.ickd.cn/?id="&AppKey&"&com="&com&"&nu="&nu&"&type=json&encode=GBK"'如果使用UTF8,請確保encode=utf8
'Response.Write SendURL
PHP應用'發送數據
ResponseTxt=fopen(SendURL) '//獲取源代碼的函數
PHP應用'調用發送數據組件
Function fopen(URL)?
Dim objXML?
'Set objXML=CreateObject("MSXML2.SERVERXMLHTTP.3.0") '調用XMLHTTP組件,若服務器不支持,請換用以下兩個中的一個再試
Set objXML=Server.CreateObject("Microsoft.XMLHTTP")?
'Set objXML=Server.CreateObject("MSXML2.XMLHTTP.4.0")?
'objXML.SetTimeouts 5000, 5000, 30000, 10000' 解析DNS名字的超時時間,建立Winsock連接的超時時間,發送數據的超時時間,接收response的超時時間.單位毫秒
objXML.Open "GET",URL,False '以同步方式獲取API查詢數據
objXML.Send() '發送
If objXML.Readystate<>4 Then '狀態不為4,錯誤
Response.Write "{status:0,errCode:100,message:'獲取數據出錯'}"?
Exit Function?
End If
'Readystate屬性,傳回XML文件資料的目前狀況,返回值分別有以下:
'0-UNINITIALIZED:XML 對象被產生,但沒有任何文件被加載.
'1-LOADING:加載程序進行中,但文件尚未開始解析.
'2-LOADED:部分的文件已經加載且進行解析,但對象模型尚未生效.
'3-INTERACTIVE:僅對已加載的部分文件有效,在此情況下,對象模型是有效但只讀的.
'4-COMPLETED:文件已完全加載,代表加載成功.
fopen=objXML.ResponseBody
fopen=BytesToBstr(objXML.ResponseBody)'返回信息,同時用函數定義編碼,如果您必要轉碼請選擇?
Set objXML=Nothing'關閉?
If Err.number<>0 Then?
Response.Write "{status:0,errCode:100,message:'獲取數據出錯'}"?
Err.Clear
End If
End Function
PHP應用'頁面編碼轉換
Function BytesToBstr(body)?
Dim objstream?
Set objstream = Server.CreateObject("Adodb.Stream") '//調用adodb.stream組件
objstream.Type = 1?
objstream.Mode =3?
objstream.Open?
objstream.Write body?
objstream.Position = 0?
objstream.Type = 2?
objstream.Charset = "GBK" '轉換本來默認的編碼轉換成GB2312編碼,否則直接用XMLHTTP調用有中文字符的網頁得到的將是亂碼?
BytesToBstr = objstream.ReadText?
objstream.Close?
Set objstream = Nothing?
End Function
PHP應用'輸入查詢成果
Response.Write ResponseTxt
%>
維易PHP培訓學院每天發布《PHP應用:各種快遞查詢--Api接口》等實戰技能,PHP、MYSQL、LINUX、APP、JS,CSS全面培養人才。
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/6841.html