/// <summary> /// 读卡器按会员IC卡号写一张新卡 /// </summary> public static string WriteICCardID(string sNewICCard, string sRepeatCode, string storePassword, bool isBeep = true) { int icdev = 0; try { icdev = ICCardUtility.IC_InitComm(100); //初始化usb string checkStr = ""; checkStr = check(icdev, isBeep); //基本检查 if (!checkStr.Equals("ok")) { return(checkStr); } short st = 0; //校验出厂密码 //1区的出厂密码和0区出厂密码不同,0区778852013144 1区FFFFFFFFFFFF st = ICCardUtility.IC_CheckPass_4442hex(icdev, ICPass_one); if (st != 0) { st = ICCardUtility.IC_CheckPass_4442hex(icdev, storePassword); //校验本店密码 if (st != 0) { return("提示:无法通过密码校验,可能不是本店的卡。"); } } else { st = ICCardUtility.IC_ChangePass_4442hex(icdev, pwd_postion, ICPass_one, storePassword); if (st != 0) { return("提示:无法设置IC卡密码。"); } st = ICCardUtility.IC_CheckPass_4442hex(icdev, storePassword); //校验本店密码 } byte[] b1 = new byte[16]; byte[] b2 = Encoding.ASCII.GetBytes(sNewICCard); Array.Copy(b2, b1, b2.Length); b1[b2.Length] = (byte)Convert.ToInt32(sRepeatCode); st = ICCardUtility.IC_Write(icdev, ic_postion, len, b1); if (st != 0) { return("提示:无法写入IC卡号码。"); } return("Success"); } finally { //对卡下电,对于逻辑加密卡,下电后必须密码变为有效,即要写卡必须重新校验密码。 ICCardUtility.IC_Down(icdev); //关闭端口,在Windows系统中,同时只能有一个设备使用端口,所以在退出系统时,请关闭端口,以便于其它设备使用。 ICCardUtility.IC_ExitComm(icdev); } }
/// <summary> /// 每次插卡时生成新的IC卡序列号 /// </summary> public static string RefreshICCard(string sNewICCard, string sRepeatCode, string storePassword) { int icdev = 0; try { icdev = ICCardUtility.IC_InitComm(100); //初始化usb string checkStr = check(icdev); if (!checkStr.Equals("ok")) { return(checkStr); } short st = 0; st = ICCardUtility.IC_CheckPass_4442hex(icdev, ICPass); if (st != 0) { st = ICCardUtility.IC_CheckPass_4442hex(icdev, storePassword); if (st != 0) { return("无法通过密码校验,可能不是本店的卡。"); } } else { return("此卡是一张空白卡不能刷新。"); } byte[] b1 = new byte[16]; byte[] b2 = Encoding.ASCII.GetBytes(sNewICCard); Array.Copy(b2, b1, b2.Length); b1[b2.Length] = (byte)Convert.ToInt32(sRepeatCode); st = ICCardUtility.IC_Write(icdev, ic_postion, len, b1); if (st != 0) { return("无法写入IC卡号码。"); } return("Success"); } finally { //对卡下电,对于逻辑加密卡,下电后必须密码变为有效,即要写卡必须重新校验密码。 ICCardUtility.IC_Down(icdev); //关闭端口,在Windows系统中,同时只能有一个设备使用端口,所以在退出系统时,请关闭端口,以便于其它设备使用。 ICCardUtility.IC_ExitComm(icdev); } }
/// <summary> /// 删除1区数据并恢复出厂密码FFFFFFFFFFFF /// </summary> /// <param name="icdev">读卡器ID</param> /// <param name="pwd">1区密码</param> /// <returns>成功true</returns> private static bool DeleteICCaredData(int icdev, string pwd) { byte[] b = new byte[16] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; int st = ICCardUtility.IC_CheckPass_4442hex(icdev, pwd); //下载密码到读卡器 if (st == 0) { st = ICCardUtility.IC_Write(icdev, ic_postion, len, b); //清空卡号 int st1 = ICCardUtility.IC_ChangePass_4442hex(icdev, pwd_postion, pwd, ICPass_one); //恢复原出厂密码 if (st == 0 && st1 == 0) { return(true); } } return(false); }