编程语言
首页 > 编程语言> > java 手机号本地验证归属地

java 手机号本地验证归属地

作者:互联网

1. http://repo1.maven.org/maven2/com/googlecode/libphonenumber/

下载依赖包:carrier-1.9.jar  geocoder-2.32.jar  libphonenumber-7.2.2.jar  prefixmapper-2.32.jar

/**查询手机归属地*/
    public static boolean checkPhone(String tel, String _city) {
        PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
        PhoneNumberOfflineGeocoder phoneNumberOfflineGeocoder = PhoneNumberOfflineGeocoder.getInstance();
        String language ="CN";
        Phonenumber.PhoneNumber referencePhonenumber = null;
        try {
            referencePhonenumber = phoneUtil.parse(tel, language);
        } catch (NumberParseException e) {
            e.printStackTrace();
        }
//手机号码归属城市 city
        String city= phoneNumberOfflineGeocoder.getDescriptionForNumber(referencePhonenumber,Locale.CHINA);
        return city.equals(_city);
    }

 

标签:city,java,手机号,referencePhonenumber,归属,jar,tel,String
来源: https://www.cnblogs.com/wowanyasuo/p/10722502.html