1、利用开源项目libphonenumber的资源:https://github.com/googlei18n/libphonenumber

在项目中maven配置如下:都用最新的包

    <dependency>
   <groupId>com.googlecode.libphonenumber</groupId>
   <artifactId>geocoder</artifactId>
   <version>2.15</version>
        </dependency>
        
        <dependency>
   <groupId>com.googlecode.libphonenumber</groupId>
   <artifactId>libphonenumber</artifactId>
   <version>6.3</version>
        </dependency>
        
        <dependency>
   <groupId>com.googlecode.libphonenumber</groupId>
   <artifactId>prefixmapper</artifactId>
   <version>2.15</version>
       </dependency>
       <dependency>
   <groupId>com.googlecode.libphonenumber</groupId>
   <artifactId>carrier</artifactId>
   <version>1.5</version>
       </dependency>

2、项目代码:关键代码

        private PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
        PhoneNumberOfflineGeocoder phoneNumberOfflineGeocoder = PhoneNumberOfflineGeocoder.getInstance();

        String language ="CN";
        PhoneNumber referencePhonenumber = null;

       String phoneNum = "1872209XXXX";
        
        try {
            referencePhonenumber = phoneUtil.parse(phoneNum, language);
          
        } catch (NumberParseException e) {
            e.printStackTrace();
        }
        //手机号码归属城市 referenceRegion 
        String referenceRegion = phoneNumberOfflineGeocoder.getDescriptionForNumber(referencePhonenumber,Locale.CHINA);

 

备注:摘抄自:http://blog.csdn.net/wangjianzhongshixiao/article/details/42441055

posted on 2017-12-07 17:48  公子扶胸  阅读(2168)  评论(0编辑  收藏  举报