手机+ip查询归属地

本文介绍如何利用PHP结合第三方API或数据库,实现对手机号码和IP地址的归属地查询,涵盖国内外地理位置定位及运营商信息获取。
摘要由CSDN通过智能技术生成

根据手机或者ip获取归属地-第三方接口

<?php

/**
 * 归属地工具
 * Class BelongingToLocal
 */
class BelongingToLocal
{
   
    protected $cityArr = ["北京", "上海", "天津", "重庆"];

    protected $cityStr = "北京,上海,天津,重庆,河北,山西,河南,辽宁,吉林,黑龙江,内蒙古,江苏,山东,安徽,浙江,福建,湖北,湖南,广东,广西,江西,四川,海南,贵州,云南,西藏,陕西,甘肃,青海,宁夏,新疆,港澳台";

    /**
     * 通过手机号获取归属
     * @param string $tel
     * @return array
     */
    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);
    }

    /**
     * 通过ip获取归属
     * @param string $ip
     * @return array
     */
    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);
    }

    /**
     * 360
     * @param $ip
     * @return array
     */
    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详细地址:&nbsp; <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
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值