接口地址:http://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=手机号码,返回JSON。

一、编辑/includes/lib_common.php,添加归属地查询函数
代码如下 |
复制代码 |
/**
* 获取手机号码归属地和运营商
*
* @param string $mobile 手机号码
* @return array
*/
function get_mobile_area($mobile)
{
$result = array('province'=>'', 'catName'=>''); //province-归属地 catName-运营商
$url = 'http://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=' . $mobile . '&t=' . time(); //淘宝API
$content = file_get_contents($url);
$content = iconv('GB2312', 'UTF-8', $content);
if(strlen($content) < 40)
{
return;
}
else
{
$result['province'] = substr($content, "56", "6");
$result['catName'] = substr($content, "85", "6");
}
return $result;
}
|
二、编辑/admin/order.php,添加函数调用(高亮部分)
代码如下 |
复制代码 |
/* 格式化金额 */
if ($order['order_amount'] < 0)
{
$order['money_refund'] = abs($order['order_amount']);
$order['formated_money_refund'] = price_format(abs($order['order_amount']));
}
/* 手机号码归属地 */
if (!empty($order['mobile']))
{
$result = get_mobile_area($order['mobile']);
$order['mobile_area'] = $result['province'] . $result['catName'];
}
|
三,编辑/admin/tempaltes/order_info.htm,在订单收货人信息中添加手机号码归属地
代码如下 |
复制代码 |
|
{$lang.label_tel} |
{$order.tel} |
{$lang.label_mobile} |
{$order.mobile|escape} {$order.mobile_area} |