Windows mobile 下读取手机SIM卡信息
来源:互联网 发布:历史类书籍 知乎 编辑:程序博客网 时间:2024/05/01 18:50
最近在忙一个移动警务的项目,需要获取SIM卡的信息,来做身份的验证。考虑到获取:国际移动设备识别码(IMEI:International Mobile Equipment Identification Number)和国际移动用户识别码(IMSI:International Mobile Subscriber Identification Number),读取这两个号码用到TAPI的lineGetGeneralInfo()函。在新版的OpenNetCF里没有发现对这个函数的封装(也许我没找到),于是到网上找了找,找到一个以前版本OpenNetCF里的:TapiLib.dll,包含对Windows ce phone api 的封装(TAPI),综合网上的一些资料,实现代码如下:
public struct GeneralInfo
{
public string Manufacturer;
public string Model;
public string Revision;
public string SerialNumber;
public string SubscriberNumber;
}
public struct GeneralInfo
{
public string Manufacturer;
public string Model;
public string Revision;
public string SerialNumber;
public string SubscriberNumber;
}
/// <summary>
/// Tapi控制类
/// </summary>
public class ControlTapi
{
/// Tapi控制类
/// </summary>
public class ControlTapi
{
[DllImport("cellcore.dll")]
private static extern int lineGetGeneralInfo(IntPtr hLigne,byte[]lpLineGeneralInfo );
private static extern int lineGetGeneralInfo(IntPtr hLigne,byte[]lpLineGeneralInfo );
/// <summary>
/// 调用cellcore.dll获取sim卡的综合信息
/// </summary>
/// <param name="l"></param>
/// <returns></returns>
private GeneralInfo GetGeneralInfo(Line l)
{
GeneralInfo lgi = new GeneralInfo();
byte[] buffer = new byte[512];
BitConverter.GetBytes(512).CopyTo(buffer, 0);
/// 调用cellcore.dll获取sim卡的综合信息
/// </summary>
/// <param name="l"></param>
/// <returns></returns>
private GeneralInfo GetGeneralInfo(Line l)
{
GeneralInfo lgi = new GeneralInfo();
byte[] buffer = new byte[512];
BitConverter.GetBytes(512).CopyTo(buffer, 0);
if (lineGetGeneralInfo(l.hLine, buffer) != 0)
{
throw new System.ComponentModel.Win32Exception(System.Runtime.InteropServices.Marshal.GetLastWin32Error(), "TAPI Error: " + System.Runtime.InteropServices.Marshal.GetLastWin32Error().ToString("X"));
}
{
throw new System.ComponentModel.Win32Exception(System.Runtime.InteropServices.Marshal.GetLastWin32Error(), "TAPI Error: " + System.Runtime.InteropServices.Marshal.GetLastWin32Error().ToString("X"));
}
int subscsize = BitConverter.ToInt32(buffer, 44);
int subscoffset = BitConverter.ToInt32(buffer, 48);
lgi.SubscriberNumber = System.Text.Encoding.Unicode.GetString(buffer, subscoffset, subscsize).ToString();
lgi.SubscriberNumber = lgi.SubscriberNumber.Replace("/0", "");
return lgi;
int subscoffset = BitConverter.ToInt32(buffer, 48);
lgi.SubscriberNumber = System.Text.Encoding.Unicode.GetString(buffer, subscoffset, subscsize).ToString();
lgi.SubscriberNumber = lgi.SubscriberNumber.Replace("/0", "");
return lgi;
}
/// <summary>
/// 获取sim卡的IMSI
/// </summary>
/// <returns></returns>
public static string GetIMSINumber()
{
string result = "";
try
{
Tapi t = new Tapi();
t.Initialize();
Line l = t.CreateLine(0, LINEMEDIAMODE.INTERACTIVEVOICE, OpenNETCF.Tapi.LINECALLPRIVILEGE.MONITOR);
ControlTapi ctapi = new ControlTapi();
GeneralInfo gi = ctapi.GetGeneralInfo(l);
result = gi.SubscriberNumber;
l.Dispose();
t.Shutdown();
/// 获取sim卡的IMSI
/// </summary>
/// <returns></returns>
public static string GetIMSINumber()
{
string result = "";
try
{
Tapi t = new Tapi();
t.Initialize();
Line l = t.CreateLine(0, LINEMEDIAMODE.INTERACTIVEVOICE, OpenNETCF.Tapi.LINECALLPRIVILEGE.MONITOR);
ControlTapi ctapi = new ControlTapi();
GeneralInfo gi = ctapi.GetGeneralInfo(l);
result = gi.SubscriberNumber;
l.Dispose();
t.Shutdown();
}
catch// (Exception ex)
{
result = "";
}
catch// (Exception ex)
{
result = "";
}
return result;
}
/// <summary>
/// 获取IMEI的号码
/// </summary>
/// <returns></returns>
public static string GetIMEINumber()
{
string result = "";
try
{
Tapi t = new Tapi();
t.Initialize();
Line l = t.CreateLine(0, LINEMEDIAMODE.INTERACTIVEVOICE, OpenNETCF.Tapi.LINECALLPRIVILEGE.MONITOR);
ControlTapi ctapi = new ControlTapi();
GeneralInfo gi = ctapi.GetGeneralInfo(l);
result = gi.SerialNumber;
l.Dispose();
t.Shutdown();
/// 获取IMEI的号码
/// </summary>
/// <returns></returns>
public static string GetIMEINumber()
{
string result = "";
try
{
Tapi t = new Tapi();
t.Initialize();
Line l = t.CreateLine(0, LINEMEDIAMODE.INTERACTIVEVOICE, OpenNETCF.Tapi.LINECALLPRIVILEGE.MONITOR);
ControlTapi ctapi = new ControlTapi();
GeneralInfo gi = ctapi.GetGeneralInfo(l);
result = gi.SerialNumber;
l.Dispose();
t.Shutdown();
}
catch// (Exception ex)
{
result = "";
}
catch// (Exception ex)
{
result = "";
}
return result;
}
}
}
vb 的代码你可以去看看这里:http://www.peterfoot.net/RetrieveIMEIThroughTAPI.aspx
另:
1、环境:在vs2005+windows mobile 5.0 +多普达818测试通过。
2、
关于获取SIM卡的本机号码,你可以用:http://www.microsoft.com/china/msdn/archives/library/dnnetcomp/html/netcfPhoneAPI.asp,这里 提供的方法,不过这个方法需要安全认证,比较麻烦,具体认证的方式见:http://www.microsoft.com/china/MSDN/library/Mobility/pocketpc/2k3smartphonesecurity.mspx?pf=true。
3、TapiLib.dll的下载地址:http://www.cnblogs.com/Files/xjb/TapiLib.rar
4、参考资料:
http://hucgy.bokee.com/3328836.html
- Windows mobile 下读取手机SIM卡信息(ZT)
- Windows mobile 下读取手机SIM卡信息
- Windows mobile 下读取手机SIM卡信息
- Windows mobile 下读取手机SIM卡信息
- Windows mobile 下读取手机SIM卡信息
- Windows mobile 下读取手机SIM卡信息(IMEI类)
- Windows mobile 下读取手机SIM卡信息
- Windows mobile 下读取手机SIM卡信息
- Windows mobile 下读取手机SIM卡信息
- Windows mobile 下读取手机SIM卡信息
- Windows mobile 下读取手机SIM卡信息
- Windows mobile 下读取手机SIM卡信息
- Windows Mobile读取SIM卡联系人
- Windows Mobile 获取SIM卡联系人信息
- Windows mobile 从SIM卡获得手机本机号码
- Windows Mobile读取SIM卡联系人(不通过OpenNETCF)
- 手机SIM卡信息获取
- 获取手机sim卡信息
- 2007年的一天
- 接触足球
- 设计模式
- 做中国程序员人人买的起的正版UML建模工具
- how to enable debug in eclipse + weblogic
- Windows mobile 下读取手机SIM卡信息
- 第31課 このポタンを押すと,電源が入ります。
- 熊猫烧香源代码
- 程序员心情
- Crossbow病毒开放源代码计划的源程序
- a href=#与 a href=javascript:void(0) 的区别
- VSTO 安装步骤
- 打开新窗口链接的几种办法
- 穷举法运算