Beispiel #1
0
        /// <summary>
        /// 初始化0区,参数:0区新卡号和原密码
        /// </summary>
        public static string WriteICCard(string card, string pwd)
        {
            int icdev = 0;

            try
            {
                icdev = ICAccess.IC_InitComm(100); //初始化usb

                string checkStr = check(icdev);
                if (!checkStr.Equals("ok"))
                {
                    return(checkStr);
                }
                int st = ICAccess.IC_CheckPass_4442hex(icdev, pwd, 0);     //下载密码到读卡器
                if (st == 0)
                {
                    st = ICAccess.IC_Write_hex(icdev, 1, len, card);            //写卡号
                    int st1 = ICAccess.IC_ChangePass(icdev, 3, 0, pwd, ICPass); //写密码
                    if (st == 0 && st1 == 0)
                    {
                        return("Success");
                    }
                }
                return("操作失败");
            }
            finally
            {
                //对卡下电,对于逻辑加密卡,下电后必须密码变为有效,即要写卡必须重新校验密码。
                ICAccess.IC_Down(icdev);
                //关闭端口,在Windows系统中,同时只能有一个设备使用端口,所以在退出系统时,请关闭端口,以便于其它设备使用。
                ICAccess.IC_ExitComm(icdev);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 读卡器蜂鸣
        /// </summary>
        public static void Beep(int time)
        {
            int icdev = 0;

            icdev = ICAccess.IC_InitComm(100);      //初始化usb
            ICAccess.IC_DevBeep(icdev, (uint)time); //等待10毫秒
            ICAccess.IC_ExitComm(icdev);
        }
Beispiel #3
0
        /// <summary>
        /// 读卡器按会员IC卡号写一张新卡
        /// </summary>
        public static string WriteICCardID(string sNewICCard, string sRepeatCode, bool isBeep = true)
        {
            int icdev = 0;

            try
            {
                icdev = ICAccess.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 = ICAccess.IC_CheckPass_4442hex(icdev, ICPass_one);
                if (st != 0)
                {
                    st = ICAccess.IC_CheckPass_4442hex(icdev, CommonValue.ICStorePassword); //校验本店密码
                    if (st != 0)
                    {
                        return("提示:无法通过密码校验,可能不是本店的卡。");
                    }
                }
                else
                {
                    st = ICAccess.IC_ChangePass_4442hex(icdev, pwd_postion, ICPass_one, CommonValue.ICStorePassword);
                    if (st != 0)
                    {
                        return("提示:无法设置IC卡密码。");
                    }
                    st = ICAccess.IC_CheckPass_4442hex(icdev, CommonValue.ICStorePassword); //校验本店密码
                }
                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            = ICAccess.IC_Write(icdev, ic_postion, len, b1);
                if (st != 0)
                {
                    return("提示:无法写入IC卡号码。");
                }
                return("Success");
            }
            finally
            {
                //对卡下电,对于逻辑加密卡,下电后必须密码变为有效,即要写卡必须重新校验密码。
                ICAccess.IC_Down(icdev);
                //关闭端口,在Windows系统中,同时只能有一个设备使用端口,所以在退出系统时,请关闭端口,以便于其它设备使用。
                ICAccess.IC_ExitComm(icdev);
            }
        }
Beispiel #4
0
        /// <summary>
        /// 每次插卡时生成新的IC卡序列号
        /// </summary>
        public static string RefreshICCard(string sNewICCard, string sRepeatCode)
        {
            int icdev = 0;

            try
            {
                icdev = ICAccess.IC_InitComm(100); //初始化usb

                string checkStr = check(icdev);
                if (!checkStr.Equals("ok"))
                {
                    return(checkStr);
                }

                short st = 0;

                st = ICAccess.IC_CheckPass_4442hex(icdev, ICPass);
                if (st != 0)
                {
                    st = ICAccess.IC_CheckPass_4442hex(icdev, CommonValue.ICStorePassword);
                    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            = ICAccess.IC_Write(icdev, ic_postion, len, b1);
                if (st != 0)
                {
                    return("无法写入IC卡号码。");
                }
                return("Success");
            }
            finally
            {
                //对卡下电,对于逻辑加密卡,下电后必须密码变为有效,即要写卡必须重新校验密码。
                ICAccess.IC_Down(icdev);
                //关闭端口,在Windows系统中,同时只能有一个设备使用端口,所以在退出系统时,请关闭端口,以便于其它设备使用。
                ICAccess.IC_ExitComm(icdev);
            }
        }
Beispiel #5
0
        public static string GetUid()
        {
            int icdev = 0;

            icdev = ICAccess.IC_InitComm(100);
            string checkStr = check(icdev, false);

            if (!checkStr.Equals("ok"))
            {
                return(checkStr);
            }
            //获得IC卡UID
            ulong uid = 0;
            int   st  = dc_anticoll(icdev, ref uid);

            ICAccess.IC_ExitComm(icdev);
            return(uid.ToString());
        }
Beispiel #6
0
        /// <summary>
        /// 读卡器回收卡
        /// </summary>
        public static string RecoveryICCard()
        {
            int icdev = 0;

            try
            {
                icdev = ICAccess.IC_InitComm(100); //初始化usb

                string checkStr = check(icdev);
                if (!checkStr.Equals("ok"))
                {
                    return(checkStr);
                }

                if (DeleteICCaredData(icdev, ICPass_one))
                {
                    return("Success");
                }
                if (DeleteICCaredData(icdev, CommonValue.ICStorePassword))
                {
                    return("Success");
                }
                if (DeleteICCaredData(icdev, ICPass))
                {
                    return("Success");
                }
                return("此卡不是新卡也不是本店的卡,无法通过密码校验");
                //short st = 0;
                //st = ICAccess.IC_CheckPass_4442hex(icdev, ICPass_one);
                //if (st != 0)
                //{
                //    st = ICAccess.IC_CheckPass_4442hex(icdev, ICStorePassword);
                //    if (st != 0)
                //    {
                //        return "无法通过密码校验,可能不是本店的卡。";
                //    }
                //}
                //else
                //{
                //    return "此卡是一张空白卡,不需要处理。";
                //}
                //byte[] b = new byte[16] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
                //st = ICAccess.IC_Write(icdev, ic_postion, len, b);  //清空卡号
                //if (st != 0)
                //{
                //    return "无法写入IC卡号码。";
                //}
                //st = ICAccess.IC_ChangePass_4442hex(icdev, pwd_postion,ICStorePassword, ICPass_one); //恢复原出厂密码
                //if (st != 0)
                //{
                //    return "无法设置IC卡密码。";
                //}
                //return "Success";
            }
            finally
            {
                //对卡下电,对于逻辑加密卡,下电后必须密码变为有效,即要写卡必须重新校验密码。
                ICAccess.IC_Down(icdev);
                //关闭端口,在Windows系统中,同时只能有一个设备使用端口,所以在退出系统时,请关闭端口,以便于其它设备使用。
                ICAccess.IC_ExitComm(icdev);
            }
        }
Beispiel #7
0
        /// <summary>
        /// 判断读卡器中插入的是一张空卡
        /// </summary>
        public static bool CheckNullCard()
        {
            int icdev = 0;

            try
            {
                icdev = ICAccess.IC_InitComm(100); //初始化usb

                if (icdev <= 0)
                {
                    return(false);
                }

                int    iReadDev = -1;
                byte[] sdata    = new byte[9];

                iReadDev = ICAccess.IC_ReadVer(icdev, sdata);
                if (iReadDev < 0)
                {
                    return(false);
                }

                short st = 0;
                st = ICAccess.IC_InitType(icdev, 16);
                if (st < 0)
                {
                    return(false);
                }

                st = ICAccess.IC_DevBeep(icdev, 10);//等待10毫秒
                st = ICAccess.IC_Status(icdev);
                if (st == 1)
                {
                    return(false);
                }
                if (st != 0)
                {
                    return(false);
                }

                st = ICAccess.IC_CheckPass_4442hex(icdev, ICPass);
                if (st != 0)
                {
                    st = ICAccess.IC_CheckPass_4442hex(icdev, CommonValue.ICStorePassword);
                    if (st != 0)
                    {
                        return(false);
                    }
                }
                else
                {
                    return(true);
                }
                return(false);
            }
            finally
            {
                //对卡下电,对于逻辑加密卡,下电后必须密码变为有效,即要写卡必须重新校验密码。
                ICAccess.IC_Down(icdev);
                //关闭端口,在Windows系统中,同时只能有一个设备使用端口,所以在退出系统时,请关闭端口,以便于其它设备使用。
                ICAccess.IC_ExitComm(icdev);
            }
        }
Beispiel #8
0
        /// <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);
            }
        }
Beispiel #9
0
        /// <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);
            }
        }