连接爱查快递接口的方法
一、首先去爱查快递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
<!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"www.it165.net, 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
<?phpheader('Content-type:text/html;charset=utf-8'); //echo '*****'; $typeCom = $_GET["expressid"];//快递公司 $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; ?>
郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。
新闻热点
疑难解答