Windows Phone 7 SIM卡資訊獲取
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");
}
}
相關文章
- iOS獲取SIM卡資訊iOS
- 獲取 Windows Phone 的 User-Agent 字串Windows字串
- Windows mobile 下讀取手機SIM卡資訊Windows
- android 從SIM卡獲取聯絡人資訊Android
- Windows Phone 7 墓碑機制Windows
- Windows Phone 7程式設計Windows程式設計
- HTML Agility Pack for Windows Phone 7 (WP7)HTMLWindows
- Windows Phone 7解析圖片格式Windows
- vmi:獲取 windows 系統硬體資訊Windows
- 一起學Windows Phone7開發(十四.一 Phone Task)Windows
- Windows Phone 7 開發 31 日談——第21日:Silverlight Toolkit for Windows PhoneWindows
- Windows Phone 7 點陣圖程式設計Windows程式設計
- Windows系統安全獲取重要資訊的方法(一)Windows
- Windows Phone7開發系列視訊地址Windows
- Windows Phone7 實現檔案上傳Windows
- spring boot學習(7)— 配置資訊的獲取方式Spring Boot
- Windows Phone FAQWindows
- Windows Phone 7 開發 31 日談——第7日:啟動器Windows
- Windows Phone 7監測網路環境變化Windows
- 探索Windows Phone 7的單元測試(翻譯)Windows
- 與Windows Phone 7 相關的一些概念Windows
- 資料繫結(一)——《Windows Phone 7程式設計》Windows程式設計
- 資料繫結(二)——《Windows Phone 7程式設計》Windows程式設計
- 簡單XNA_Windows Phone 7 3D動畫Windows3D動畫
- mac獲取cpu資訊Mac
- 獲取資訊版本1
- Windows phone 應用開發[2]-資料快取Windows快取
- 《Windows Phone 7入門經典之使用Silverlight和XNA開發Windows Phone應用》書評Windows
- SAI:51%受訪者表示會考慮Windows Phone 7AIWindows
- Windows Phone 7 TextBox全選擴充套件行為Windows套件
- Windows Phone 體驗Windows
- C# url資訊獲取C#
- 常用OS獲取資訊命令
- GetDiskSerial DLL獲取硬碟資訊硬碟
- 使用XNA為Windows phone 7開發簡單拼圖遊戲Windows遊戲
- Windows Phone 7中帶題頭的TextBox和PasswordBoxWindows
- ·Windows Phone 7首款機型8月25日開賣Windows
- Windows Phone 7 開發 31 日談——第25日:外部APIWindowsAPI