Windows Phone 7 SIM卡信息获取

简介: public class SIM { #region 平台调用 [DllImport("cellcore.
    public class SIM
    {
        #region 平台调用
        [DllImport("cellcore.dll")]
        public extern static int SimInitialize(int dwFlags, IntPtr lpfnCallback, int dwParam, ref IntPtr lphSim);

        [DllImport("cellcore.dll")]

        public extern static int SimDeinitialize(IntPtr hSim);

        [DllImport("cellcore.dll")]
        public extern static int SimReadRecord(IntPtr hSim, int dwAddress, int dwRecordType, int dwIndex, byte[] lpData, int dwBufferSize, ref int dwSize);

        int EF_ICCID = 0x2fe2;
        int SIM_RECORDTYPE_TRANSPARENT = 1;
        #endregion



        //返回Sim卡背面的20位ICCID 
        public string SimSerialNumber()
        {
            IntPtr hSim = default(IntPtr);
            byte[] iccid = new byte[10];
            int dwsize = 0;
            SimInitialize(0, IntPtr.Zero, 0, ref hSim);
            SimReadRecord(hSim, EF_ICCID, SIM_RECORDTYPE_TRANSPARENT, 0, iccid, iccid.Length, ref dwsize);//在这里获取了SIM卡ID
            SimDeinitialize(hSim);
            return FormatAsSimString(iccid);
        }

        /// <summary>
        /// 对SIM卡ID进行格式化
        /// </summary>
        /// <param name="iccid">byte格式的ID</param>
        /// <returns>字符串格式</returns>
        private static string FormatAsSimString(byte[] iccid)
        {
            string rawString = GetRawIccIDString(iccid);
            return String.Format("{0} {1} {2} {3}", rawString.Substring(0, 6), rawString.Substring(6, 5), rawString.Substring(11, 4), rawString.Substring(15, 4));
        }

        /// <summary>
        /// 格式转换函数
        /// </summary>
        /// <param name="iccid"></param>
        /// <returns></returns>
        private static string GetRawIccIDString(byte[] iccid)
        {
            System.Text.StringBuilder builder = new System.Text.StringBuilder();
            int i = 0;
            while (i < iccid.Length)
            {
                byte b = iccid;
                builder.Append(ConvertInt4PairToString(b));
                Math.Max(System.Threading.Interlocked.Increment(ref i), i - 1);
            }
            return builder.ToString();
        }

        private static string ConvertInt4PairToString(byte byteValue)
        {
            return ((byte)(byteValue << 4) | (byteValue >> 4)).ToString("x2");
        }
    }


相关文章
|
Java 应用服务中间件 开发工具
[App Service for Windows]通过 KUDU 查看 Tomcat 配置信息
[App Service for Windows]通过 KUDU 查看 Tomcat 配置信息
137 2
|
Java Windows
【Azure Developer】Windows中通过pslist命令查看到Java进程和线程信息,但为什么和代码中打印出来的进程号不一致呢?
【Azure Developer】Windows中通过pslist命令查看到Java进程和线程信息,但为什么和代码中打印出来的进程号不一致呢?
175 1
|
消息中间件 Java Kafka
【Azure 事件中心】在Windows系统中使用 kafka-consumer-groups.bat 查看Event Hub中kafka的consumer groups信息
【Azure 事件中心】在Windows系统中使用 kafka-consumer-groups.bat 查看Event Hub中kafka的consumer groups信息
115 0
|
JavaScript Windows
NodeJs——如何获取Windows电脑指定应用进程信息
NodeJs——如何获取Windows电脑指定应用进程信息
261 0
|
存储 Linux 网络安全
都2023年了还不了解?使用FileZilla搭建信息文件服务器(Windows7)
都2023年了还不了解?使用FileZilla搭建信息文件服务器(Windows7)
1186 0
|
Docker Windows 容器
Windows Docker Desktop 无法启动 自动退出报错信息为:Docker Desktop -Unexpected WsL error An unexpected error was e
Windows Docker Desktop 无法启动 自动退出报错信息为:Docker Desktop -Unexpected WsL error An unexpected error was e
947 0
|
应用服务中间件 nginx Windows
windows中查看本机ip,网关信息,端口号
windows中查看本机ip,网关信息,端口号
890 0
|
Web App开发 XML 网络协议
|
Windows
WINDOWS调用出错后,得到信息字串
WINDOWS调用出错后,得到信息字串
75 0
|
开发框架 Prometheus 监控
Windows监控:基于Prometheus+Grafana监控CPU、内存、磁盘、网络、GPU信息
Windows监控:基于Prometheus+Grafana监控CPU、内存、磁盘、网络、GPU信息
Windows监控:基于Prometheus+Grafana监控CPU、内存、磁盘、网络、GPU信息

热门文章

最新文章