通過本接口可以查詢圓通快遞、申通快遞、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;
echo $logistics_info;
echo "<br><br><a href='$logistics_url' target='_self'>點我點我</a>";
//exit;
}