接口地址: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,在订单收货人信息中添加手机号码归属地
<tr>
<td><div align="right"><strong>{$lang.label_tel}</strong></div></td>
<td>{$order.tel}</td>
<td><div align="right"><strong>{$lang.label_mobile}</strong></div></td>
<td>{$order.mobile|escape} <font color="#FF0000">{$order.mobile_area}</font></td>
</tr>
本文介绍了一种通过淘宝API查询手机号码归属地及运营商的方法。具体实现包括在PHP项目中添加函数来获取手机号码信息,并在订单详情页面展示手机号码的归属地。


1786

被折叠的 条评论
为什么被折叠?



