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