連接愛查快遞接口的方法
一、首先去愛查快遞http://www.ickd.cn/api/reg.html申請KEY,很快的,幾分鐘就申請下來了。比快遞100好多了,服務也好多了。
二、創建表單,提交數據,發送地址為:$url ='http://api.ickd.cn/?com='.$typeCom.'&nu='.$typeNu.'&id='.$key.'&type=html&encode=utf8';
只要把表達那的值帶進去就行了,就可以提交了。
實現代碼為:
example.html
[html]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>快遞單號獲取接口API - Example</title>
<script language="javascript" src="jquery-1.4.4.min.js"></script>
<script language="javascript">
$(document).ready(function(){
$("#btnSnap").click(function(){
$("#shipping_detail").html("<img src='load.gif' />");
var expressid = $("#expressid").val();
var expressno = $("#expressno").val();
//$.get("api/kuaidi.php",{expressid:expressid,expressno:expressno},function(data){
$.ajax({
async: false,
type : "get",
//contentType : "application/json;charset=ut",
dataType : "html",
url : "get.php",
data : "expressid=" +expressid + "&expressno=" + expressno,
success : function(msg) {// msg為返回的數據,在這裡做數據綁定 $("#shipping_detail").html(msg); }
});
});
});
</script>
<script type="text/javascript">
$(document).ready(function(){
$("tr:even").css("background-color","#EAF2D3");
});
</script>
<style>
#retForm{width:640px;line-height:22px;padding-bottom:10px;border-bottom:1px dotted #ccc;}
#retData{
background:#efefef;
padding:10px;
line-height:18px;
width: 96%;
border: 0;
}
.txtPartner{width:960px;margin:20px 10px;padding:10px 0 0 0;border-top:1px solid #dfdfdf;}
.txtPartner h1{font-size:14px;color:#FF5632;}
.txtPartner a{float:left;margin:0 10px 10px 0;}
.logo {
font-size: 18px;
font-weight: bold;
text-align: center;
padding: 10px;
font-family: "微軟雅黑";
}
.txtURL {
font-size: 12px;
padding: 10px;
}
</style>
<style>
.ickd_return{
font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
width:100%;
border-collapse:collapse;
}
th,td {
font-size:1em;
border:1px solid #98bf21;
padding:3px 7px 2px 7px;
text-align:center;}
th{
text-align:center;
font-size:1.1em;
padding-top:5px;
padding-bottom:4px;
background-color:#A7C942;
color:#ffffff;}
tr.td{
color:#000000;
background-color:#EAF2D3;
}
</style>
<style>
#retForm{width:640px;line-height:22px;padding-bottom:10px;border-bottom:1px dotted #ccc;}
#retData{
background:#efefef;
padding:10px;
line-height:18px;
width: 96%;
border: 0;
}
.txtPartner{width:960px;margin:20px 10px;padding:10px 0 0 0;border-top:1px solid #dfdfdf;}
.txtPartner h1{font-size:14px;color:#FF5632;}
.txtPartner a{float:left;margin:0 10px 10px 0;}
.logo {
font-size: 18px;
font-weight: bold;
text-align: center;
padding: 10px;
font-family: "微軟雅黑";
}
.txtURL {
font-size: 12px;
padding: 10px;
}
</style>
</head>
<body>
<div class="result">
</div>
<!-- <form action="kuaidi.php" method="get"> -->
<div class="seatchForm">
<div class="txtURL">
<p>快遞公司:
<input name="expressid" type="text" id="expressid" />
快遞單號:<input name="expressno" type="text" id="expressno"/>
</p>
<p>說明:查詢時需要發送兩個參數:公司名(拼音或英文);快遞單號</p>
</div>
<div class="txtButton"><input type="submit" value="查詢" id="btnSnap" class="btnSnap"/></div>
</div>
<div class="txtAboutSnap">
<p>獲取范例:</p>
<div id="shipping_detail"></div>
<img src="load.gif" />
</div>
</div>
</body>
</html>
get.php
[php]
<?php
header('Content-type:text/html;charset=utf-8');
//echo '*****';
$typeCom = $_GET["expressid"];//快遞公司 www.2cto.com
$typeNu = $_GET["expressno"]; //快遞單號
$key='**********';//到<a href="http://www.ickd.cn/api/reg.html">http://www.ickd.cn/api/reg.html</a>申請
$url ='http://api.ickd.cn/?com='.$typeCom.'&nu='.$typeNu.'&id='.$key.'&type=html&encode=utf8';
//echo $url;
$data = file_get_contents($url);
echo $data;
?>
作者:hljflp