According to the mobile phone number of the location, operators we refer to Google's Libphonenumber package, Libphonenumber is used to parse, format, store and verify the phone number of Java, C + + or JavaScript class library.
Dependent jar Packs: Com.googlecode.libphonenumber (Libphonenumber, Geocoder, Prefixmapper, Carrier)
Jar Package Download Address: Http://mvnrepository.com/search?q=libphonenumber (we can also use MAVEN configuration)
Package com.yuanzubao.common.util;
Import Java.util.Locale;
Import Com.google.i18n.phonenumbers.PhoneNumberToCarrierMapper;
Import Com.google.i18n.phonenumbers.PhoneNumberUtil;
Import Com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
Import Com.google.i18n.phonenumbers.geocoding.PhoneNumberOfflineGeocoder; /** * Cell Phone number attribution query * Dependent JAR package: Com.googlecode.libphonenumber (Libphonenumber, Geocoder, Prefixmapper, Carrier) * Developer: WANGQL * Development time Rooms: 2015-11-24 * */public class Phoneutil {private static phonenumberutil Phonenumberutil = Phonenumberutil.getinstan
CE ();
private static Phonenumbertocarriermapper Carriermapper = Phonenumbertocarriermapper.getinstance ();
private static Phonenumberofflinegeocoder Geocoder = Phonenumberofflinegeocoder.getinstance (); /** * According to the country code and cell phone number to determine whether the cell phone number is valid * @param phonenumber * @param countrycode * @return * * Public STA Tic Boolean Checkphonenumber (String PhoneNumber, string countrycode) {int ccode = Integer.valueof (CountryCode);
Long phone = long.valueof (PhoneNumber);
PhoneNumber pn = new PhoneNumber ();
Pn.setcountrycode (Ccode);
Pn.setnationalnumber (phone);
return Phonenumberutil.isvalidnumber (PN); /** * According to the country code and cell phone number to determine the mobile phone operator * @param phonenumber * @param * * * @return * * * * * * * * publi
C Static String Getcarrier (String PhoneNumber, string countrycode) {int ccode = integer.valueof (CountryCode);
Long phone = long.valueof (PhoneNumber);
PhoneNumber pn = new PhoneNumber ();
Pn.setcountrycode (Ccode);
Pn.setnationalnumber (phone);
Return result only in English, turn into Chinese String carrieren = carriermapper.getnamefornumber (pn, Locale.english);
String Carrierzh = "";
Carrierzh + = Geocoder.getdescriptionfornumber (pn, Locale.chinese);
Switch (carrieren) {case "Carrierzh": + + = "mobile";
Break
Case "Unicom":Carrierzh = "Unicom";
Break
Case "Telecom": Carrierzh + + "telecom";
Break
Default:break;
return Carrierzh;
/** * * @Description: According to the country code and mobile phone number of the home * @date 2015-7-13 11:33:18 * @param @param phonenumber * @param @param countrycode * @param @return parameter * @throws/public static string Getgeo (String p
Honenumber, String countrycode) {int ccode = integer.valueof (CountryCode);
Long phone = long.valueof (PhoneNumber);
PhoneNumber pn = new PhoneNumber ();
Pn.setcountrycode (Ccode);
Pn.setnationalnumber (phone);
Return Geocoder.getdescriptionfornumber (PN, Locale.chinese); }
}
Note: CountryCode is the country code, the mainland number is 86