windows mobile 6.0 C# 如何获得 SIM卡 ICCID ?

love_study 2009-07-21 06:07:05
最近 项目 中要用到获得用户手机SIM卡原始ID(ICCID),就是 SIM卡 后面的 20位数字,请问大家 这个信息怎么获取?
最好是C# 代码,请大家帮我解决,谢谢!
...全文
404 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
lixangers 2011-09-05
  • 打赏
  • 举报
回复
源码分享:
我们的项目就是这样用的,绝对可用!要分哦!
#region---获取Sim卡IMSI---
//定义常量
const int EF_ICCID = 0x2FE2;//ICCID号码在Sim卡的存储地址
const int SIM_RECORDTYPE_TRANSPARENT = 0x00000001; //只获取单个记录

//读取SIM卡 IMSI 模块
[DllImport("cellcore.dll")]// 初始化Sim卡列表,并返回一个可以操作的句柄lphSim
private static extern IntPtr SimInitialize(IntPtr dwFlags, IntPtr lpfnCallBack, IntPtr dwParam, out IntPtr lphSim);

[DllImport("cellcore.dll")]// 关闭Sim卡列表
private static extern IntPtr SimDeinitialize(IntPtr hSim);

[DllImport("cellcore.dll")]// 读取指定的记录
private static extern IntPtr SimReadRecord(IntPtr hSim, IntPtr dwAddress, IntPtr dwRecordType, IntPtr dwIndex, byte[] lpData, IntPtr dwBufferSize, ref IntPtr lpdwBytesRead);


[DllImport("cellcore.dll")]// 获取Sim卡指定记录的信息(数据结构)
private static extern IntPtr SimGetRecordInfo(IntPtr hSim, IntPtr dwAddress, ref SimRecord lpSimRecordInfo);

[StructLayout(LayoutKind.Sequential)]//Sim 卡记录的数据结构
public struct SimRecord
{
public IntPtr cbSize;
public IntPtr dwParams;
public IntPtr dwRecordType;
public IntPtr dwItemCount;
public IntPtr dwSize;
}

public static string GetSimIMSI()
{
//获取Sim卡的ICCID
IntPtr res, hSim;
//初始化Sim卡列表
res = SimInitialize(IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, out hSim);
if (res != IntPtr.Zero)
return "-1"; //Can not Initialize Sim.

SimRecord rec = new SimRecord();
rec.cbSize = (IntPtr)Marshal.SizeOf(rec);
res = SimGetRecordInfo(hSim, (IntPtr)EF_ICCID, ref rec);//获取ICCID的数据结构信息
if (res != IntPtr.Zero)
return "-2"; //Could not read the ICCID information from the SIM..

byte[] bData = new byte[(int)rec.dwSize + 1];//这里多加了一个字节来扩充一下缓冲区
IntPtr dwBytesRead = IntPtr.Zero;
res = SimReadRecord(hSim, (IntPtr)EF_ICCID, rec.dwRecordType, IntPtr.Zero, bData, (IntPtr)bData.Length, ref dwBytesRead);
if (res != IntPtr.Zero)
return "-3"; //Could not read the ICCID from the SIM.
SimDeinitialize(hSim);

string str = byteToString(bData);

return str;
}

public static string byteToString(byte[] b)
{
StringBuilder sb = new StringBuilder();
int n = b.Length;
for (int i = 0; i < n; i++)
{
sb.Append(StrReverse(b[i].ToString("x").PadLeft(2, '0')));
}
return sb.ToString().Substring(0, 20);
}


public static string StrReverse(string str) //高低位转换
{
StringBuilder sb = new StringBuilder();
sb.Append(str[1]);
sb.Append(str[0]);
return sb.ToString();
}
#endregion
poling_ai 2011-09-04
  • 打赏
  • 举报
回复
MS提供了一套API(SIM管理器)用于管理电话、手机卡,你可以使用C#平台调用试试,
swanmsg 2011-09-04
  • 打赏
  • 举报
回复
谁有代码,共享一下。
seifu 2011-09-04
  • 打赏
  • 举报
回复
也来学习,用力帮顶.
sxz2008 2011-01-20
  • 打赏
  • 举报
回复
我估计很快也要做那块了。
yangquanqu 2011-01-18
  • 打赏
  • 举报
回复
用r3读卡器插进电脑即可显示Sim的iccid数字。
infsafe 2009-07-23
  • 打赏
  • 举报
回复
帮顶.
love_study 2009-07-23
  • 打赏
  • 举报
回复
为什么获取不到呢?
love_study 2009-07-22
  • 打赏
  • 举报
回复
怎么没有人回答啊
wade_li 2009-07-22
  • 打赏
  • 举报
回复
应该是获取不到吧!

7,660

社区成员

发帖
与我相关
我的任务
社区描述
Windows Phone是微软发布的一款手机操作系统,它将微软旗下的Xbox LIVE游戏、Zune音乐与独特的视频体验整合至手机中。
社区管理员
  • Windows客户端开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧