聚合国内IT技术精华文章,分享IT技术精华,帮助IT从业人士成长

国际移动用户识别码:IMSI

2014-08-08 22:05 浏览: 3382246 次 我要评论(0 条) 字号:

国际移动用户识别码,即IMSI(International Mobile Subscriber Identity),它是在公众陆地移动电话网(PLMN)中用于唯一识别移动用户的一个号码。在GSM网络,这个号码通常被存放在SIM卡中。

IMSI共有15位,其结构如下:

MCC+MNC+MSIN  (MNC+MSIN=NMSI)

  • MCC:Mobile Country Code,移动国家码,MCC的资源由国际电联(ITU)统一分配和管理,唯一识别移动用户所属的国家,共3位,中国为460;
  • MNC:Mobile Network Code,移动网络码,共2位,中国移动TD系统使用00,中国联通GSM系统使用01,中国移动GSM系统使用02,中国电信CDMA系统使用03,一个典型的IMSI号码为460030912121001;
  • MSIN:Mobile Subscriber Identification Number ,移动客户识别号,唯一识别码共有10位。

以下为国内MCC+MNC的相关数据:

imsi

Android获取IMSI的方案:

public class SimUtil {

         /**

          * 中国移动

          */

         public static final int SIM_TYPE_CHINA_MOBILE = 1;

         /**

          * 中国联通

          */

         public static final int SIM_TYPE_CHINA_UNICOM = 2;

         /**

          * 中国电信

          */

         public static final int SIM_TYPE_CHINA_TELECOM = 3;


         /** SIM卡是中国移动 */

         public static boolean isChinaMobile() {

                   String imsi = getSimOperator();

                   if (imsi == null) return false;

                   return imsi.startsWith("46000") || imsi.startsWith("46002") || imsi.startsWith("46007");

         }

         /** SIM卡是中国联通 */

         public static boolean isChinaUnicom() {

                   String imsi = getSimOperator();

                   if (imsi == null) return false;

                   return imsi.startsWith("46001");

         } 

         /** SIM卡是中国电信 */

         public static boolean isChinaTelecom() {

                   String imsi = getSimOperator();

                   if (imsi == null) return false;

                   return imsi.startsWith("46003");

         }

         private static String getSimOperator() {

                   TelephonyManager tm = (TelephonyManager)BoyaaApp.getApplication().getSystemService(Context.TELEPHONY_SERVICE);

                   return tm.getSubscriberId();

         }     

         /** 获取手机电话号码 */

         public static String getPhoneNumbers() {

                   TelephonyManager tm = (TelephonyManager)BoyaaApp.getApplication().getSystemService(Context.TELEPHONY_SERVICE);

                   return tm.getLine1Number();

         }      

         //sim卡是否可读

         public static boolean isCanUseSim() {

             try {

                 TelephonyManager mgr = (TelephonyManager) BoyaaApp.getApplication().getSystemService(Context.TELEPHONY_SERVICE);

                 return TelephonyManager.SIM_STATE_READY == mgr

                         .getSimState();

             } catch (Exception e) {

                 e.printStackTrace();

             }

             return false;

         }

}

IOS获取IMSI方案:(会存在审核不通过的风险,7.0以后貌似无法获取,未测试)

使用coreTelephony.framework获取imsi

#define PRIVATE_PATH  "/System/Library/PrivateFrameworks/CoreTelephony.framework/CoreTelephony"

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
#if !TARGET_IPHONE_SIMULATOR
    void *kit = dlopen(PRIVATE_PATH,RTLD_LAZY);    
    NSString *imsi = nil;
    int (*CTSIMSupportCopyMobileSubscriberIdentity)() = dlsym(kit, "CTSIMSupportCopyMobileSubscriberIdentity");
    imsi = (NSString*)CTSIMSupportCopyMobileSubscriberIdentity(nil);
    dlclose(kit);    

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"IMSI" 
                                                    message:imsi 
                                                   delegate:self 
                                          cancelButtonTitle:@"OK" 
                                          otherButtonTitles:nil];
    [alert show];
    [alert release];
#endif
}

参考资料:



网友评论已有0条评论, 我也要评论

发表评论

*

* (保密)

Ctrl+Enter 快捷回复