ecshop手机号码归属地

接口地址: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}&nbsp;<font color="#FF0000">{$order.mobile_area}</font></td>
</tr>


你可能感兴趣的:(ecshop,手机号,归属地)