/// <summary> /// 读取16进制的卡号(含动态码的卡号) /// 参数:isBeep 是否需要蜂鸣, /// isCreate是入库或入会类型的操作,此类操作空白卡需要返回卡号 /// 校验逻辑:1检查设备 2.检查密码 3.检查是不是空白卡 /// 返回包含动态码的完整卡号,开新卡的业务只返回卡号 /// </summary> public static bool ReadICCard(string storePassword, out string icCardId, out string repeatCode, out string errMsg, bool isBeep = true, bool isCreate = false) { string checkStr = ""; icCardId = string.Empty; repeatCode = string.Empty; errMsg = string.Empty; int icdev = 0; try { icdev = ICCardUtility.IC_InitComm(100); //初始化usb checkStr = check(icdev, isBeep); //基本检查 if (!checkStr.Equals("ok")) { errMsg = checkStr; return(false); } short st = 0; //开新卡 if (isCreate) { st = ICCardUtility.IC_CheckPass_4442hex(icdev, storePassword, secnr_index); if (st == 0) { errMsg = "提示:此卡正在使用。"; return(false); } st = ICCardUtility.IC_CheckPass_4442hex(icdev, ICPass, secnr_index_ic); if (st != 0) { errMsg = "提示:无法读取IC卡信息。"; return(false); } StringBuilder data = new StringBuilder(); st = ICCardUtility.IC_Read_hex(icdev, 1, len - 1, data); //新卡块4无卡号,改为读块1的原始卡号 if (st == 0) { errMsg = data.ToString().Substring(0, len - 1); return(true); } } else { st = ICCardUtility.IC_CheckPass_4442hex(icdev, ICPass_one, secnr_index); if (st == 0) { errMsg = "提示:此卡是一张空白卡,不需要处理。"; return(false); } st = ICCardUtility.IC_CheckPass_4442hex(icdev, storePassword, secnr_index); if (st != 0) { errMsg = "提示:无法通过密码校验,可能不是本店的卡。"; return(false); } byte[] data = new byte[len]; st = ICCardUtility.IC_Read(icdev, ic_postion, len, data); if (st == 0) { byte[] b1 = new byte[len - 1]; Array.Copy(data, b1, b1.Length); byte b2 = data[len - 1]; string s = Encoding.ASCII.GetString(b1) + b2.ToString("X2"); repeatCode = Convert.ToInt32(s.Substring(8), 16).ToString(); string sICCardID = s.Substring(0, 8).Replace("\0", ""); icCardId = s; return(true); } } errMsg = "提示:无法读取IC卡信息。"; return(false); } finally { ICCardUtility.IC_Down(icdev); ICCardUtility.IC_ExitComm(icdev); } }
/// <summary> /// 仅仅读取卡号(不校验)参数扇区号0-15,块号0-63 /// </summary> public static string GetCardID(int index, int postion, string storePassword, bool isBeep = false) { string sICCardID = ""; string checkStr = ""; int icdev = 1; try { icdev = ICCardUtility.IC_InitComm(100); //初始化usb checkStr = check(icdev, isBeep); //基本检查 if (!checkStr.Equals("ok")) { return(checkStr); } short st = 0; if (index == 0) { st = ICCardUtility.IC_CheckPass_4442hex(icdev, ICPass, index); if (st != 0) { st = ICCardUtility.IC_CheckPass_4442hex(icdev, ICPass_one, index); if (st != 0) { return("提示:无法读取IC卡信息。"); } } StringBuilder data = new StringBuilder(); st = ICCardUtility.IC_Read_hex(icdev, postion, 8, data); //新卡块4无卡号,改为读块1的原始卡号 if (st == 0) { return(data.ToString().Substring(0, 8)); } return("提示:无法读取IC卡信息。"); } else { st = ICCardUtility.IC_CheckPass_4442hex(icdev, storePassword, index); if (st != 0) { st = ICCardUtility.IC_CheckPass_4442hex(icdev, ICPass_one, index); if (st != 0) { return("提示:无法读取IC卡信息。"); } } byte[] data = new byte[8]; st = ICCardUtility.IC_Read(icdev, postion, 8, data); if (st == 0) { sICCardID = Encoding.ASCII.GetString(data).Replace("\0", "0"); return(sICCardID); } return("提示:无法读取IC卡信息。"); } } finally { ICCardUtility.IC_Down(icdev); ICCardUtility.IC_ExitComm(icdev); } }