根据手机或者ip获取归属地-第三方接口
<?php
class BelongingToLocal
{
protected $cityArr = ["北京", "上海", "天津", "重庆"];
protected $cityStr = "北京,上海,天津,重庆,河北,山西,河南,辽宁,吉林,黑龙江,内蒙古,江苏,山东,安徽,浙江,福建,湖北,湖南,广东,广西,江西,四川,海南,贵州,云南,西藏,陕西,甘肃,青海,宁夏,新疆,港澳台";
public function useTel($tel = '')
{
list($area, $city) = $this->tel_360($tel);
if ($area == '' || $city == '') list($area, $city) = $this->tel_K780($tel);
if ($area == '' || $city == '') list($area, $city) = $this->tel_51240($tel);
if ($area == '' || $city == '') list($area, $city) = $this->tel_sg($tel);
return $this->format($area, $city);
}
public function useIp($ip = '')
{
list($area, $city) = $this->ip_360($ip);
if ($area == '' || $city == '') list($area, $city) = $this->ip_bd($ip);
if ($area == '' || $city == '') list($area, $city) = $this->ip_ip($ip);
return $this->format($area, $city);
}
protected function ip_360($ip)
{
$this->header = [];
$result = $this->request("http://www.ip360.cn/", "ip={
$ip}&action=2");
$area = $city = $result_str = '';
$location = $this->getSubstr($result, 'IP详细地址: <font color=#cc3300>', '</font>');
$arrConf = explode(",", $this->cityStr);
$isHas = false;
foreach ($arrConf as $value) {
if ($isHas) break;
$area = $value;
if ($value != '' && strpos(mb_substr($location, 0, 6), $value) !== false) $isHas = true;
if (!empty($c = $this->getSubstr($location, $value . '自治区', '市'))) $city = $c;
if (!empty($c = $this->getSubstr($location, $value . '省', '市'))) $city = $c;
if (!empty($c = $this->getSubstr($location, $value . '市', '市'))) $city = $c