php快递单号查询接口使用示例
发布:smiling 来源: PHP粉丝网 添加日期:2020-12-07 17:40:15 浏览: 评论:0
这篇文章主要介绍了php快递单号查询接口使用示例,需要的朋友可以参考下
通过本接口可以查询圆通快递、申通快递、ems快递、韵达快递等快递单号查询信息,无需其他额外开发,非常方便
首先到www.aikuaidi.cn上注册个账号,使用key,代码如下:
- <?php
- /**
- * 查询物流信息
- */
- define('IN_ECS', true);
- require(dirname(__FILE__) . '/includes/init.php');
- if ($id = intval($_REQUEST['id'])) {
- $sql_select = 'SELECT consignee,mobile,tel,tracking_sn,shipping_code,shipping_name FROM '.
- $GLOBALS['ecs']->table('order_info')." WHERE order_id=$id";
- $order_info = $GLOBALS['db']->getRow($sql_select);
- // 快递公司code映射
- $shipping_code = array (
- 'ems' => 'ems',
- 'ems2' => 'ems',
- 'sto_express' => 'zjs',
- 'sto_nopay' => 'zjs',
- 'zto' => 'zhongtong',
- 'sto' => 'shentong',
- 'yto' => 'yuantong',
- 'sf' => 'shunfeng',
- 'emssn' => 'ems',
- 'sf2' => 'shunfeng',
- 'yunda' => 'yunda',
- );
- $logistics_code = $shipping_code[$order_info['shipping_code']] ? $shipping_code[$order_info['shipping_code']] : $order_info['shipping_code'];
- $aikuaidi_key = 'xxxxxxx';
- $logistics_url = "http://www.aikuaidi.cn/rest/?key=$aikuaidi_key&order={$order_info['tracking_sn']}&id=$logistics_code&ord=asc&show=html";
- $logistics_info = file_get_contents($logistics_url);
- //var_dump($logistics_info);
- //$logistics_info = iconv('gb2312', 'UTF-8', $logistics_info);
- echo <<<EOF
- <span>收货人:<strong>{$order_info['consignee']}</strong></span>
- <span>联系电话:<strong>{$order_info['mobile']} // {$order_info['tel']}</strong></span>
- <span>配送:<strong>{$order_info['shipping_name']}</strong></span>
- <span>运单号:<strong>{$order_info['tracking_sn']}</strong></span><br><br>
- EOF; //phpfensi.com
- echo $logistics_info;
- echo "<br><br><a href='$logistics_url' target='_self'>点我点我</a>";
- //exit;
- }
Tags: php快递单号查询
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)