/** 本环境使用php+smarty,结合两种快递api调取快递数据 * 说明,先快递鸟调取数据,失败后再调取快递网的数据
* 快递鸟 http://www.kdniao.com 快递网 http://www.kuaidi.com/ * ----前台调用代码---- <{if $de.is_virtual neq 1 && $de.logistics_name}> <dl class="dl clearfix"> <dt>物流信息</dt> <dd>物流名称:<{$de.logistics_name}></dd> <{if $de.invoice_no}> <dd>物流单号:<{$de.invoice_no}></dd> <{/if}> </dl> <{if $de.logistics_name&&$de.invoice_no&&$logistics_config.logistics_connect==1}> <dl><script src="<{$config.weburl}>/api/***.php?com=<{$de.logistics_name}>&nu=<{$de.invoice_no}>"></script></dl> <{/if}> <{/if}> */
1 <?php 2 include_once("../includes/global.php"); 3 @include_once("../config/logistics_config.php"); 4 $api_id = $logistics_config[\'logistic_app_id\'] ? $logistics_config[\'logistic_app_id\'] : ""; 5 $api_sceret = $logistics_config[\'logistic_api_sceret\'] ? $logistics_config[\'logistic_api_sceret\'] : ""; 6 define("API_Id", $api_id); 7 define("API_Sceret", $api_sceret); //快递网只需这个 api_id不起作用 8 9 //llog(\'\',true); 10 //llog(\'key\'.API_Sceret); 11 12 if ($_GET["com"] && $_GET["nu"]) { 13 //查询表中支持的快递公司 14 $sql = "select * from " . FASTMAIL . " where company=\'" . $_GET["com"] . "\'"; 15 $db->query($sql); 16 //llog(\'查询表中支持的快递公司:\'.$sql); 17 if ($db->num_rows()) { 18 $fast_mail = $db->fetchRow(); 19 $com = $fast_mail["pinyin"]; //快递公司代号 20 $nu = $_GET["nu"]; //快递单号 21 $order = \'\'; //订单号(可不填) 22 $sql2 = "select * from `fast_mail_record` where `number`=\'{$nu}\'"; 23 $db->query($sql2); 24 $info = $db->fetchRow(); //缓存记录 25 //llog(\'--------查询缓存数据:-------\'); 26 //llog($info); 27 $time = date(\'Y-m-d H:i:s\', time()); 28 //无缓存或缓存超过1小时直接获取 29 if (!$info || (time() - strtotime($info[\'uptime\'])) > 3600) { 30 //llog(\'+++快递鸟调取++\'); 31 $birds = getOrderTracesByJson($order, $com, $nu); 32 //llog($birds); 33 if ($birds[\'Success\'] && count($birds[\'Traces\']) > 0) { //快递鸟调取 34 $tables = joinHtml($birds[\'Traces\']); 35 //缓存数据 36 if ($info[\'id\']) 37 $sql = "update `fast_mail_record` set `record`=\'{$tables}\',`uptime`=\'{$time}\' where id=\'{$info[\'id\']}\'"; 38 else 39 $sql = "insert into `fast_mail_record` (`code`,`number`,`record`) VALUE (\'{$birdsCode[$com]}\',\'{$nu}\',\'{$tables}\')"; 40 $db->query($sql); 41 //llog(\'+++快递鸟调取成功缓存数据:\'.$sql); 42 echo "document.write(\'" . $tables . "\');"; 43 } else { //快递鸟调取失败,再调取快递网 44 //快递鸟公司代码->快递网代码 45 $birdsCode = array(\'AAE\' => \'aae\', \'YTO\' => \'yuantong\', \'QFKD\' => \'quanfengkuaidi\', \'DBL\' => \'debangwuliu\', \'ZYWL\' => \'zhongyouwuliu\', \'STO\' => \'shentong\', \'SF\' => \'shunfeng\', \'HHTT\' => \'tiantian\', \'ZJS\' => \'zhaijisong\', \'Aramex\' => \'aramex\', \'AXD\' => \'anxinda\', \'ZTO\' => \'zhongtong\', \'YD\' => \'yunda\'); 46 $res = kuaidi($birdsCode[$com], $nu); 47 //llog(\'---快递网调取---\'); 48 //llog($res); 49 if ($res[\'success\'] && count($res[\'data\']) > 0) { 50 $tables = joinHtml($res[\'data\']); 51 //缓存数据 52 if ($info[\'id\']) 53 $sql = "update `fast_mail_record` set `record`=\'{$tables}\',`uptime`=\'{$time}\' where id=\'{$info[\'id\']}\'"; 54 else 55 $sql = "insert into `fast_mail_record` (`code`,`number`,`record`) VALUE (\'{$birdsCode[$com]}\',\'{$nu}\',\'{$tables}\')"; 56 $db->query($sql); 57 //llog(\'---快递网调取成功缓存数据++\'.$sql); 58 echo "document.write(\'" . $tables . "\');"; 59 } elseif (isset($res[\'Reason\']) && strlen($res[\'Reason\']) > 0 || isset($res[\'reason\']) && strlen($res[\'reason\']) > 0) { 60 //llog(\'---调取失败返回数据--\'); 61 echo "document.write(\'<p style=\\'color:#ff6933;font-size:14px;font-weight:bold;\\'>" . $birds[\'Reason\'] . "!</p><p style=\\'color:red;font-size:14px;font-weight:bold;\\'>" . $res[\'reason\'] . "!</p>\');"; 62 } elseif (isset($info[\'record\']) && strlen($info[\'record\']) > 0) { 63 //llog(\'---还是用老数据--\'); 64 echo "document.write(\'" . $info[\'record\'] . "\');"; 65 } else { 66 //llog(\'---无数据可用--\'); 67 echo "document.write(\'暂时没有物流信息!\');"; 68 } 69 } 70 } else { 71 //llog(\'---直接调用缓存返回数据--\'); 72 //调取缓存 73 echo "document.write(\'" . $info[\'record\'] . "\');"; 74 } 75 } else { 76 //llog(\'表中不支持的快递公司--\'); 77 echo "document.write(\'暂时没有物流信息!\');"; 78 } 79 } 80 81 82 /**快递鸟 查询订单第一方案 83 * @param string $OrderCode 订单编号(可空) 84 * @param $ShipperCode 快递公司编码 85 * @param $LogisticCode 物流单号 86 * @return url响应返回的html Json方式 87 */ 88 function getOrderTracesByJson($OrderCode = \'\', $ShipperCode, $LogisticCode) 89 { 90 $requestData = "{\'OrderCode\':\'" . $OrderCode . "\',\'ShipperCode\':\'" . $ShipperCode . "\',\'LogisticCode\':\'" . $LogisticCode . "\'}"; 91 $url = \'http://api.kdniao.cc/Ebusiness/EbusinessOrderHandle.aspx\'; 92 $datas = array( 93 \'EBusinessID\' => API_Id, // 用户ID 94 \'RequestType\' => \'1002\', 95 \'RequestData\' => urlencode($requestData), 96 \'DataType\' => \'2\', 97 ); 98 $datas[\'DataSign\'] = encrypt($requestData, API_Sceret); 99 $result = sendPost($url, $datas); 100 //根据公司业务处理返回的信息......json格式 101 return json_decode($result, true); 102 } 103 104 105 /** 快递鸟 106 * post提交数据 107 * @param string $url 请求Url 108 * @param array $datas 提交的数据 109 * @return url响应返回的html 110 */ 111 function sendPost($url, $datas) 112 { 113 $temps = array(); 114 foreach ($datas as $key => $value) { 115 $temps[] = sprintf(\'%s=%s\', $key, $value); 116 } 117 $post_data = implode(\'&\', $temps); 118 $url_info = parse_url($url); 119 120 if ($url_info[\'port\'] == \'\') { 121 $url_info[\'port\'] = 80; 122 } 123 // echo $url_info[\'port\']; 124 $httpheader = "POST " . $url_info[\'path\'] . " HTTP/1.0\r\n"; 125 $httpheader .= "Host:" . $url_info[\'host\'] . "\r\n"; 126 $httpheader .= "Content-Type:application/x-www-form-urlencoded\r\n"; 127 $httpheader .= "Content-Length:" . strlen($post_data) . "\r\n"; 128 $httpheader .= "Connection:close\r\n\r\n"; 129 $httpheader .= $post_data; 130 $fd = fsockopen($url_info[\'host\'], $url_info[\'port\']); 131 fwrite($fd, $httpheader); 132 $gets = ""; 133 $headerFlag = true; 134 while (!feof($fd)) { 135 if (($header = @fgets($fd)) && ($header == "\r\n" || $header == "\n")) { 136 break; 137 } 138 } 139 while (!feof($fd)) { 140 $gets .= fread($fd, 128); 141 } 142 fclose($fd); 143 144 return $gets; 145 } 146 147 /**快递鸟 148 * 电商Sign签名生成 149 * @param data 内容 150 * @param appkey Appkey 151 * @return DataSign签名 152 */ 153 function encrypt($data, $appkey) 154 { 155 return urlencode(base64_encode(md5($data . $appkey))); 156 } 157 158 159 /**--------------------------------快递网 查询第二方案---------------------------------------------------- 160 * @param $com 公司代号 161 * @param $nu 快递单号 162 * @param int $id 缓存表id 163 * @return string 164 */ 165 function kuaidi($com, $nu) 166 { 167 $AppKey = \'e456181bcd8234562928a92b0786acf1\'; //申请的key 169 $url = \'http://api.kuaidi.com/openapi.html?id=\' . $AppKey . \'&com=\' . $com . \'&nu=\' . $nu . \'&show=0&muti=0&order=asc\'; 170 //优先使用curl模式发送数据 171 if (function_exists(\'curl_init\') == 1) { 172 $curl = curl_init(); 173 curl_setopt($curl, CURLOPT_URL, $url); 174 curl_setopt($curl, CURLOPT_HEADER, 0); 175 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 176 curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER[\'HTTP_USER_AGENT\']); 177 curl_setopt($curl, CURLOPT_TIMEOUT, 5); 178 $res = curl_exec($curl); 179 curl_close($curl); 180 } 181 $res = json_decode($res, true); 182 return $res; 183 // return "document.write(\'" . $htmls ."\');"; 184 } 185 186 //拼装html 187 function joinHtml($res) 188 { 189 $tables = \'<table width="520px" border="0" cellspacing="0" cellpadding="0" id="showtablecontext" style="border-collapse:collapse;border-spacing:0;"><tbody><tr><td width="163" style="background:#39b54a;border:1px solid #39b54a;color:#FFFFFF;font-size:14px;font-weight:bold;height:28px;line-height:28px;padding:3px 5px;">时间</td><td width="354" style="background:#39b54a;border:1px solid #39b54a;color:#FFFFFF;font-size:14px;font-weight:bold;height:28px;line-height:28px;padding:3px 5px;">地点和跟踪进度</td></tr>\'; 190 foreach ($res as $vo) { 191 $time = $vo[\'AcceptTime\'] ? $vo[\'AcceptTime\'] : $vo[\'time\']; 192 $context = $vo[\'AcceptStation\'] ? $vo[\'AcceptStation\'] : $vo[\'context\']; 193 $tables .= \'<tr><td width="163" style="border:1px solid #DDDDDD;font-size:12px;line-height:22px;padding:3px 5px;">\' . $time . \'</td><td width="354" style="border:1px solid #DDDDDD;font-size:12px;line-height:22px;padding:3px 5px;text-align: left;">\' . $context . \'</td></tr>\'; 194 } 195 $tables .= \'</tbody></table>\'; 196 return $tables; 197 } 198 199 function llog($msg, $f = false, $path = "/logs/temp") 200 { 201 define("APP_ROOT_DIRECTORY", dirname(dirname(__FILE__)));//获取项目根目录绝对路径 202 $file = APP_ROOT_DIRECTORY . $path . ".log"; 203 if ($f) 204 file_put_contents($file, \'\'); 205 error_log("[" . date("Y-m-d H:i:s") . "] " . print_r($msg, true) . "\n\r", 3, $file); 206 } 207 208 ?>
前面使用了快递鸟调取数据,失败后再调取快递网的数据
==================================新版本加入了app端的支持
1 //调试样例 http://www.abc.app/api/logistic.php?com=申通快递&nu=3315555780084&type=json 2 //代码开始 3 include_once("../includes/global.php"); 4 @include_once("../config/logistics_config.php"); 5 //管理后台--设置--物流查询平台 设置下列参数 6 $api_id = $logistics_config[\'logistic_app_id\'] ? $logistics_config[\'logistic_app_id\'] : ""; 7 $api_sceret = $logistics_config[\'logistic_api_sceret\'] ? $logistics_config[\'logistic_api_sceret\'] : ""; 8 define("API_Id", $api_id); 9 define("API_Sceret", $api_sceret); 10 $type=$_GET["type"]; //type=json app访问 11 if (!$type){ 12 $type="html"; 13 } 14 //快递网测试 15 if ($_GET["com"] && $_GET["nu"]) { 16 //查询表中支持的快递公司 17 $sql = "select * from " . FASTMAIL . " where company=\'" . $_GET["com"] . "\'"; 18 $db->query($sql); 19 //fb(\'查询表中支持的快递公司:\'.$sql); 20 if ($db->num_rows()) { 21 $fast_mail = $db->fetchRow(); 22 $com = $fast_mail["pinyin"]; //快递鸟对应物流公司代码 23 $com2 = $fast_mail["pinyin2"]; //快递网对应物流公司代码 24 $nu = $_GET["nu"]; //快递单号 25 $order = \'\'; //订单号(可不填) 26 $sql2 = "select * from `mallbuilder_fast_mail_record` where `number`=\'{$nu}\' and `code`=\'{$com}\'"; 27 $db->query($sql2); 28 $info = $db->fetchRow(); //缓存记录 29 //fb(\'--------查询缓存数据:-------\'); 30 //fb($info); 31 $time = date(\'Y-m-d H:i:s\', time()); 32 //无缓存或缓存超过1小时直接获取 33 if (!$info || (time() - strtotime($info[\'uptime\'])) > 3600) { 34 //fb(\'+++快递鸟调取++\'); 35 $birds = getOrderTracesByJson($order, $com, $nu); 36 //fb($birds); 37 if ($birds[\'Success\'] && count($birds[\'Traces\']) > 0) { //快递鸟调取 38 $tables = array(); 39 foreach($birds[\'Traces\'] as $k => $vo){ 40 $tables[$k][\'time\'] = $vo[\'AcceptTime\']; 41 $tables[$k][\'context\'] = $vo[\'AcceptStation\']; 42 } 43 //fb($tables,\'字段转换\'); 44 $tables = json_encode_ex($tables); 45 $record =addslashes($tables); //插入数据 \n 报错 46 //fb($tables,\'json中文显示\'); 47 //缓存数据 48 if ($info[\'id\']) 49 $sql = "update `mallbuilder_fast_mail_record` set `code`=\'{$com}\',`record`=\'{$record}\',`uptime`=\'{$time}\' where id=\'{$info[\'id\']}\'"; 50 else 51 $sql = "insert into `mallbuilder_fast_mail_record` (`code`,`number`,`record`) VALUE (\'{$com}\',\'{$nu}\',\'{$record}\')"; 52 $db->query($sql); 53 //fb(\'+++快递鸟调取成功-开始缓存数据:\'.$sql); 54 lookorder($tables); 55 } else { 56 //fb(\'---快递鸟调取失败,再调取快递网---\'); 57 $res = kuaidi($com2, $nu); 58 //fb($res); 59 if ($res[\'success\'] && count($res[\'data\']) > 0) { 60 $tables =json_encode_ex($res[\'data\']); 61 $record =addslashes($tables); 62 //fb($tables,\'json转换中文显示\'); 63 //缓存数据 64 if ($info[\'id\']) 65 $sql = "update `mallbuilder_fast_mail_record` set `code`=\'{$com}\', `record`=\'{$record}\',`uptime`=\'{$time}\' where id=\'{$info[\'id\']}\'"; 66 else 67 $sql = "insert into `mallbuilder_fast_mail_record` (`code`,`number`,`record`) VALUE (\'{$com}\',\'{$nu}\',\'{$record}\')"; 68 $db->query($sql); 69 //fb(\'---快递网调取成功--缓存数据++\'.$sql); 70 lookorder($tables); 71 /* } elseif (isset($res[\'Reason\']) && strlen($res[\'Reason\']) > 0 || isset($res[\'reason\']) && strlen($res[\'reason\']) > 0) { 72 lookorder(\'\',1);*/ 73 } elseif (isset($info[\'record\']) && strlen($info[\'record\']) > 0) { 74 //fb(\'---调取失败原因---启用老数据--\'); 75 //fb($birds[\'Reason\'].\' | \'.$res[\'reason\']); 76 //fb($info[\'record\']); 77 78 lookorder($info[\'record\']); 79 } else { 80 //fb(\'---无数据可用--\'); 81 lookorder(\'\',1); 82 } 83 } 84 } else { 85 //fb(\'---直接调用缓存返回数据--\'); 86 // echo "document.write(\'" . $info[\'record\'] . "\');"; 87 lookorder($info[\'record\']); 88 } 89 } else { 90 //fb(\'表中不支持的快递公司--\'); 91 lookorder(\'\',1); 92 } 93 } 94 /**输出信息 95 * @param string $con 快递信息(json) 96 * @param int $style 1为未查到数据 97 */ 98 function lookorder($con=\'\',$style=0) 99 { 100 global $type; 101 //fb($type,\'type\'); 102 if ($type == "json") { 103 if($style){ 104 $con = array(\'errCode\'=>403,\'message\'=>\'没有查到相关信息。单号暂未收录或已过期!\',\'data\'=>\'\'); 105 $con = json_encode($con); 106 echo $con; 107 }else{ 108 $data =json_decode($con); 109 $con = array(\'errCode\'=>0,\'message\'=>\'\',\'data\'=>$data); 110 $con =json_encode($con); 111 echo $con; 112 } 113 //fb($con,\'app输出\'); 114 }else{ 115 if($style) 116 echo "document.write(\'<p style=\\'color:red;font-size:14px;font-weight:bold;\\'>没有查到相关信息。单号暂未收录或已过期!</p>\')"; 117 else{ 118 $con = joinHtml($con); 119 echo "document.write(\'" . $con . "\');"; 120 } 121 //fb($con,\'html输出\'); 122 } 123 exit; 124 } 125 126 /**快递鸟 查询订单物流轨迹 127 * @param string $OrderCode 订单编号(可空) 128 * @param $ShipperCode 快递公司编码 129 * @param $LogisticCode 物流单号 130 * @return url响应返回的html Json方式 131 */ 132 function getOrderTracesByJson($OrderCode = \'\', $ShipperCode, $LogisticCode) 133 { 134 $requestData = "{\'OrderCode\':\'" . $OrderCode . "\',\'ShipperCode\':\'" . $ShipperCode . "\',\'LogisticCode\':\'" . $LogisticCode . "\'}"; 135 $url = \'http://api.kdniao.cc/Ebusiness/EbusinessOrderHandle.aspx\'; 136 $datas = array( 137 \'EBusinessID\' => API_Id, // 用户ID 138 \'RequestType\' => \'1002\', 139 \'RequestData\' => urlencode($requestData), 140 \'DataType\' => \'2\', 141 ); 142 $datas[\'DataSign\'] = encrypt($requestData, API_Sceret); 143 $result = sendPost($url, $datas); 144 //根据公司业务处理返回的信息......json格式 145 return json_decode($result, true); 146 } 147 148 149 /** 150 * post提交数据 151 * @param string $url 请求Url 152 * @param array $datas 提交的数据 153 * @return url响应返回的html 154 */ 155 function sendPost($url, $datas) 156 { 157 $temps = array(); 158 foreach ($datas as $key => $value) { 159 $temps[] = sprintf(\'%s=%s\', $key, $value); 160 } 161 $post_data = implode(\'&\', $temps); 162 $url_info = parse_url($url); 163 164 if ($url_info[\'port\'] == \'\') { 165 $url_info[\'port\'] = 80; 166 } 167 // echo $url_info[\'port\']; 168 $httpheader = "POST " . $url_info[\'path\'] . " HTTP/1.0\r\n"; 169 $httpheader .= "Host:" . $url_info[\'host\'] . "\r\n"; 170 $httpheader .= "Content-Type:application/x-www-form-urlencoded\r\n"; 171 $httpheader .= "Content-Length:" . strlen($post_data) . "\r\n"; 172 $httpheader .= "Connection:close\r\n\r\n"; 173 $httpheader .= $post_data; 174 $fd = fsockopen($url_info[\'host\'], $url_info[\'port\']); 175 fwrite($fd, $httpheader); 176 $gets = ""; 177 $headerFlag = true; 178 while (!feof($fd)) { 179 if (($header = @fgets($fd)) && ($header == "\r\n" || $header == "\n")) { 180 break; 181 } 182 } 183 while (!feof($fd)) { 184 $gets .= fread($fd, 128); 185 } 186 fclose($fd); 187 188 return $gets; 189 } 190 191 /** 192 * 电商Sign签名生成 193 * @param data 内容 194 * @param appkey Appkey 195 * @return DataSign签名 196 */ 197 function encrypt($data, $appkey) 198 { 199 return urlencode(base64_encode(md5($data . $appkey))); 200 } 201 202 203 /**快递网 查询第二方案 204 * @param $com 公司代号 205 * @param $nu 快递单号 206 * @param int $id 缓存表id 207 * @return string 208 */ 209 function kuaidi($com, $nu) 210 { 211 $AppKey = \'11222333444555\'; 212 // $AppKey= API_Sceret?API_Sceret:\'1234567898765\'; 213 $url = \'http://api.kuaidi.com/openapi.html?id=\' . $AppKey . \'&com=\' . $com . \'&nu=\' . $nu . \'&show=0&muti=0&order=asc\'; 214 //优先使用curl模式发送数据 215 if (function_exists(\'curl_init\') == 1) { 216 $curl = curl_init(); 217 curl_setopt($curl, CURLOPT_URL, $url); 218 curl_setopt($curl, CURLOPT_HEADER, 0); 219 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 220 curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER[\'HTTP_USER_AGENT\']); 221 curl_setopt($curl, CURLOPT_TIMEOUT, 5); 222 $res = curl_exec($curl); 223 curl_close($curl); 224 } 225 $res = json_decode($res, true); 226 return $res; 227 // return "document.write(\'" . $htmls ."\');"; 228 } 229 230 //拼装html 231 function joinHtml($res) 232 { 233 //fb($res,\'拼装html\'); 234 $res = str_replace(\'\r\',\'<br/> \',$res); //把换行符替换成html格式 235 $res = json_decode($res,true); 236 $tables = \'<table width="520px" border="0" cellspacing="0" cellpadding="0" id="showtablecontext" style="border-collapse:collapse;border-spacing:0;"><tbody><tr><td width="163" style="background:#39b54a;border:1px solid #39b54a;color:#FFFFFF;font-size:14px;font-weight:bold;height:28px;line-height:28px;padding:3px 5px;">时间</td><td width="354" style="background:#39b54a;border:1px solid #39b54a;color:#FFFFFF;font-size:14px;font-weight:bold;height:28px;line-height:28px;padding:3px 5px;">地点和跟踪进度</td></tr>\'; 237 foreach ($res as $vo) { 238 $time = $vo[\'time\'] ? $vo[\'time\'] : $vo[\'AcceptTime\'] ; 239 $context = $vo[\'context\'] ? $vo[\'context\'] : $vo[\'AcceptStation\']; 240 $tables .= \'<tr><td width="163" style="border:1px solid #DDDDDD;font-size:12px;line-height:22px;padding:3px 5px;">\' . $time . \'</td><td width="354" style="border:1px solid #DDDDDD;font-size:12px;line-height:22px;padding:3px 5px;text-align: left;">\' . $context . \'</td></tr>\'; 241 } 242 $tables .= \'</tbody></table>\'; 243 return $tables; 244 }
下面是快递100和爱查快递api接口示例
1 /** 快递100 https://www.kuaidi100.com/openapi/api_post.shtml 2 * @param $com 快递公司代码,不支持中文 3 * @param $nu 快递单号,请勿带特殊符号,不支持中文(大小写不敏感) 4 * @param $show 返回类型:如果不填,默认返回json字符串 5 0:返回json字符串, 6 1:返回xml对象, 7 2:返回html对象, 8 3:返回text文本。 9 * @return string 10 */
11 function php100($com,$nu){ 12 $AppKey= API_Sceret?API_Sceret:\'a704e4fb5fcc8124\';//请将XXXXXX替换成您在http://kuaidi100.com/app/reg.html申请到的KEY 13 $url =\'http://api.kuaidi100.com/api?id=\'.$AppKey.\'&com=\'.$com.\'&nu=\'.$nu.\'&show=2&muti=1&order=asc\'; 14 //请勿删除变量$powered 的信息,否则本站将不再为你提供快递接口服务。 15 $powered = \'查询数据由:<a href=\"http://kuaidi100.com\" target=\"_blank\">KuaiDi100.Com (快递100)</a> 网站提供 \'; 16 //优先使用curl模式发送数据 17 if (function_exists(\'curl_init\') == 1){ 18 $curl = curl_init(); 19 curl_setopt ($curl, CURLOPT_URL, $url); 20 curl_setopt ($curl, CURLOPT_HEADER,0); 21 curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1); 22 curl_setopt ($curl, CURLOPT_USERAGENT,$_SERVER[\'HTTP_USER_AGENT\']); 23 curl_setopt ($curl, CURLOPT_TIMEOUT,5); 24 $con = curl_exec($curl); 25 curl_close ($curl); 26 } 27 28 return \'document.write("\' . $con .\'<br/>\' . $powered.\'");\'; 29 } 30 32 33
爱查快递 http://api.ickd.cn/?id=[]&secret=[]&com=[]&nu=[]&type=[]&encode=[]&ord=[]&lang=[] /*com 必须 快递公司代码(英文),所支持快递公司见如下列表 nu 必须 快递单号,长度必须大于5位 id 必须 授权KEY,申请请点击快递查询API申请方式 在新版中ID为一个纯数字型,此时必须添加参数secret(secret为一个小写的字符串) secret 必选(新增) 该参数为新增加,老用户可以使用申请时填写的邮箱和接收到的KEY值登录http://api.ickd.cn/users/查看对应secret值 type 可选 返回结果类型,值分别为 html | json(默认) | text | xml encode 可选 gbk(默认)| utf8 ord 可选 asc(默认)|desc,返回结果排序 lang 可选 en返回英文结果,目前仅支持部分快递(EMS、顺丰、DHL)*/
1 function lookorder($com,$nu,$type) 2 { 3 $api_id = API_Id; 4 $api_sceret = API_Sceret; 5 $url2 = "http://api.ickd.cn/?com=" . $com . "&nu=" . trim($nu) . "&id=" . $api_id . "&type=" . $type . "&secret=" . $api_sceret . "&encode=utf8"; 6 $con = file_get_contents($url2); 7 if ($type == "json") { 8 return $con; 9 } else { 10 return "document.write(\'" . $con . "\');"; 11 } 12 }