示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="result"></param>
        private void RequestCallback(IAsyncResult result)
        {
            Encoding            encoding = new UTF8Encoding(false); // Whenever I have UTF8 problems it's BOM's fault
            HttpListenerContext context  = null;

            try
            {
                context = HttpListener.EndGetContext(result);
                context.Response.AppendHeader("Access-Control-Allow-Origin", "*");
                context.Response.ContentEncoding = Encoding.UTF8;

                IDCardData obj         = DirectReadCard();
                string     json        = GetJsonByObject(obj);
                byte[]     outputBytes = encoding.GetBytes(json);

                context.Response.ContentType     = "application/json";
                context.Response.ContentLength64 = outputBytes.Length;
                context.Response.OutputStream.Write(outputBytes, 0, outputBytes.Length);
                //logger.WriteEntry("完成HTTP请求,已应答。");
            }
            catch (Exception ex)
            {
                byte[] outputBytes = encoding.GetBytes(ex.Message);
                context.Response.StatusCode      = 500;
                context.Response.ContentType     = "text/plain";
                context.Response.ContentLength64 = outputBytes.Length;
                context.Response.OutputStream.Write(outputBytes, 0, outputBytes.Length);

                logger.WriteEntry("读取身份证出错:" + ex.Message);
            }
            finally
            {
                if (context != null && context.Response != null)
                {
                    context.Response.Close();
                }

                HttpListener.BeginGetContext(new AsyncCallback(RequestCallback), null);
            }
        }
示例#2
0
        public void ReadIdcardInfo(object s)
        {
            #region 读取身份证信息
            IDCardData CardMsg = new IDCardData();
            int        nRet, nPort, iPhotoType;
            string     stmp;
            byte[]     cPath  = new byte[255];
            byte[]     pucIIN = new byte[4];
            byte[]     pucSN  = new byte[8];
            nPort = m_iPort;
            //if (pictureBox1.Image != null)
            //{
            //    pictureBox1.Image.Dispose();
            //    pictureBox1.Image = null;
            //}
            //Syn_SetPhotoPath(0,ref cPath[0]);	//设置照片路径	iOption 路径选项	0=C:	1=当前路径	2=指定路径
            //cPhotoPath	绝对路径,仅在iOption=2时有效
            iPhotoType = 0;
            Syn_SetPhotoType(0);        //0 = bmp ,1 = jpg , 2 = base64 , 3 = WLT ,4 = 不生成
            Syn_SetPhotoName(2);        // 生成照片文件名 0=tmp 1=姓名 2=身份证号 3=姓名_身份证号

            Syn_SetSexType(1);          // 0=卡中存储的数据	1=解释之后的数据,男、女、未知
            Syn_SetNationType(1);       // 0=卡中存储的数据	1=解释之后的数据 2=解释之后加"族"
            Syn_SetBornType(1);         // 0=YYYYMMDD,1=YYYY年MM月DD日,2=YYYY.MM.DD,3=YYYY-MM-DD,4=YYYY/MM/DD
            Syn_SetUserLifeBType(1);    // 0=YYYYMMDD,1=YYYY年MM月DD日,2=YYYY.MM.DD,3=YYYY-MM-DD,4=YYYY/MM/DD
            Syn_SetUserLifeEType(1, 1); // 0=YYYYMMDD(不转换),1=YYYY年MM月DD日,2=YYYY.MM.DD,3=YYYY-MM-DD,4=YYYY/MM/DD,
                                        // 0=长期 不转换,	1=长期转换为 有效期开始+50年

            if (Syn_OpenPort(nPort) == 0)
            {
                if (Syn_SetMaxRFByte(nPort, 80, 0) == 0)
                {
                    nRet = Syn_StartFindIDCard(nPort, ref pucIIN[0], 0);
                    nRet = Syn_SelectIDCard(nPort, ref pucSN[0], 0);
                    int i = Syn_SetPhotoType(4);//不生成图片
                    nRet = Syn_ReadMsg(nPort, 0, ref CardMsg);

                    if (nRet == 0)
                    {
                        txtIDCard.ForeColor = Color.Black;
                        txtName.ForeColor   = Color.Black;

                        SName        = CardMsg.Name.Trim();                        //完整姓名
                        txtName.Text = "*" + SName.Substring(1, SName.Length - 1); //加密后的姓名
                        SNation      = CardMsg.Nation.Trim();
                        //stmp = Convert.ToString(System.DateTime.Now) + "  性别:" + CardMsg.Sex;
                        // stmp = Convert.ToString(System.DateTime.Now) + "  民族:" + CardMsg.Nation;
                        //stmp = Convert.ToString(System.DateTime.Now) + "  出生日期:" + CardMsg.Born;
                        Address = CardMsg.Address.Trim();

                        Sidnum         = CardMsg.IDCardNo.Trim();             //完整身份证信息
                        txtIDCard.Text = replaceStr(CardMsg.IDCardNo.Trim()); //加密后的身份证信息
                        //stmp = Convert.ToString(System.DateTime.Now) + "  发证机关:" + CardMsg.GrantDept;
                        //stmp = Convert.ToString(System.DateTime.Now) + "  有效期开始:" + CardMsg.UserLifeBegin;
                        //stmp = Convert.ToString(System.DateTime.Now) + "  有效期结束:" + CardMsg.UserLifeEnd;
                        //stmp = Convert.ToString(System.DateTime.Now) + "  照片文件名:" + CardMsg.PhotoFileName;
                        //if (iPhotoType == 0 || iPhotoType == 1)
                        //{
                        //    pictureBox1.Image = Image.FromFile(CardMsg.PhotoFileName);
                        //}
                        ClearMemory();
                    }
                    else
                    {
                        stmp = Convert.ToString(System.DateTime.Now) + "  读取身份证信息错误";
                    }
                }
            }
            #endregion
        }
示例#3
0
 public static extern int Syn_ReadFPMsg(int iPortID, int iIfOpen, ref IDCardData pIDCardData, ref byte cFPhotoname);
示例#4
0
 public static extern int Syn_ReadMsg(int iPortID, int iIfOpen, ref IDCardData pIDCardData);
示例#5
0
        private bool _readData()
        {
            IDCardData CardMsg = new IDCardData();

            error = "";
            int nRet;

            byte[] pucIIN = new byte[4];
            byte[] pucSN  = new byte[8];
            //if (Syn_SetMaxRFByte(iport, 80, 0) == 0)
            //{
            nRet = Syn_StartFindIDCard(iport, ref pucIIN, 0);
            //Thread.Sleep(10);
            nRet = Syn_SelectIDCard(iport, ref pucSN, 0);
            //Thread.Sleep(10);
            nRet = Syn_ReadMsg(iport, 0, ref CardMsg);
            if (nRet == 0 || nRet == 1)
            {
                if (CardMsg.CardType.StartsWith("I"))
                {
                    carttype = "外国居留证";
                    return(true);
                }
                else
                {
                    xm      = CardMsg.Name.Trim();
                    sfz     = CardMsg.IDCardNo.Trim();
                    sex     = CardMsg.Sex.Trim();    //代码
                    mz      = CardMsg.Nation.Trim(); //代码
                    birth   = CardMsg.Born.Trim();
                    birth   = birth.Substring(0, 4) + "-" + birth.Substring(4, 2) + "-" + birth.Substring(6);
                    address = CardMsg.Address.Trim();
                    qfjg    = CardMsg.GrantDept.Trim();
                    yxqq    = CardMsg.UserLifeBegin.Trim();
                    yxqq    = yxqq.Substring(0, 4) + "-" + yxqq.Substring(4, 2) + "-" + yxqq.Substring(6);
                    yxqz    = CardMsg.UserLifeEnd.Trim();
                    if (yxqz.Length == 8)
                    {
                        yxqz = yxqz.Substring(0, 4) + "-" + yxqz.Substring(4, 2) + "-" + yxqz.Substring(6);
                    }
                    photourl = CardMsg.PhotoFileName;
                    if (CardMsg.CardType.StartsWith("J"))
                    {
                        carttype = "港澳台居民居住证";
                        txzh     = CardMsg.PassID.Trim();
                        qfcs     = CardMsg.IssuesTimes.Trim();
                    }
                    else
                    {
                        carttype = "公民身份证";
                    }
                    return(true);
                }
            }
            else
            {
                error = "读卡失败";
                return(false);
            }
            //}
            //else
            //{
            //    error = "读卡失败";
            //    return false;
            //}
        }
示例#6
0
        /// <summary>
        /// 读二代证信息含指纹
        /// </summary>
        /// <param name="photoPath"></param>
        public RegistrationByCardModel ReadCardInfoWithFingerPrint(string photoPath, out string errorMsg)
        {
            IDCardData CardMsg = new IDCardData();
            int        nRet, nPort, iPhotoType;
            string     stmp;

            errorMsg = string.Empty;
            byte[] cPath  = new byte[255];
            byte[] pucIIN = new byte[4];
            byte[] pucSN  = new byte[8];
            byte[] ucPath = new byte[256];
            nPort = m_iPort;
            RegistrationByCardModel model = new RegistrationByCardModel();

            //Syn_SetPhotoPath(0, ref cPath[0]);	//设置照片路径	iOption 路径选项	0=C:	1=当前路径	2=指定路径
            cPath = Encoding.UTF8.GetBytes(photoPath);
            Syn_SetPhotoPath(2, ref cPath[0]);
            //cPhotoPath	绝对路径,仅在iOption=2时有效
            iPhotoType = 0;
            Syn_SetPhotoType(0);        //0 = bmp ,1 = jpg , 2 = base64 , 3 = WLT ,4 = 不生成
            Syn_SetPhotoName(2);        // 生成照片文件名 0=tmp 1=姓名 2=身份证号 3=姓名_身份证号

            Syn_SetSexType(1);          // 0=卡中存储的数据	1=解释之后的数据,男、女、未知
            Syn_SetNationType(1);       // 0=卡中存储的数据	1=解释之后的数据 2=解释之后加"族"
            Syn_SetBornType(1);         // 0=YYYYMMDD,1=YYYY年MM月DD日,2=YYYY.MM.DD,3=YYYY-MM-DD,4=YYYY/MM/DD
            Syn_SetUserLifeBType(1);    // 0=YYYYMMDD,1=YYYY年MM月DD日,2=YYYY.MM.DD,3=YYYY-MM-DD,4=YYYY/MM/DD
            Syn_SetUserLifeEType(1, 1); // 0=YYYYMMDD(不转换),1=YYYY年MM月DD日,2=YYYY.MM.DD,3=YYYY-MM-DD,4=YYYY/MM/DD,
            // 0=长期 不转换,	1=长期转换为 有效期开始+50年
            if (Syn_OpenPort(nPort) == 0)
            {
                if (Syn_SetMaxRFByte(nPort, 80, 0) == 0)
                {
                    nRet = Syn_StartFindIDCard(nPort, ref pucIIN[0], 0);
                    nRet = Syn_SelectIDCard(nPort, ref pucSN[0], 0);
                    nRet = Syn_ReadFPMsg(nPort, 0, ref CardMsg, ref ucPath[0]);
                    if (nRet == 0 || nRet == 1)
                    {
                        model.StudentsName  = CardMsg.Name;
                        model.Sex           = CardMsg.Sex;
                        model.Nation        = CardMsg.Nation;
                        model.Born          = CardMsg.Born;
                        model.Address       = CardMsg.Address;
                        model.IDCardNo      = CardMsg.IDCardNo;
                        model.GrantDept     = CardMsg.GrantDept;
                        model.UserLifeBegin = CardMsg.UserLifeBegin;
                        model.UserLifeEnd   = CardMsg.UserLifeEnd;


                        ASCIIEncoding encoding = new ASCIIEncoding();
                        model.FingerPrint = encoding.GetString(ucPath, 0, 256);
                        if (iPhotoType == 0 || iPhotoType == 1)
                        {
                            model.PhotoFileName = CardMsg.PhotoFileName;
                        }
                    }
                    else
                    {
                        errorMsg = Convert.ToString(System.DateTime.Now) + "  读取身份证信息错误";
                    }
                }
            }
            else
            {
                errorMsg = Convert.ToString(System.DateTime.Now) + "  打开端口失败";
            }
            return(model);
        }
示例#7
0
        /// <summary>
        /// 读取身份证号
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public DataTable readSfzh()
        {
            DataTable dt = new DataTable();

            try
            {
                IDCardData CardMsg = new IDCardData();

                int    nRet, nPort, iPhotoType;
                string stmp;
                byte[] cPath  = new byte[255];
                byte[] pucIIN = new byte[4];
                byte[] pucSN  = new byte[8];
                nPort = m_iPort;

                string readcard = readCardTest();
                if (readcard.Length > 0)
                {
                    //stmp = Convert.ToString(System.DateTime.Now) + "  读取身份证信息错误";
                    throw new Exception(readcard);
                }

                Syn_SetPhotoPath(0, ref cPath[0]);      //设置照片路径	iOption 路径选项	0=C:	1=当前路径	2=指定路径
                //cPhotoPath	绝对路径,仅在iOption=2时有效
                iPhotoType = 0;
                Syn_SetPhotoType(0);        //0 = bmp ,1 = jpg , 2 = base64 , 3 = WLT ,4 = 不生成
                Syn_SetPhotoName(2);        // 生成照片文件名 0=tmp 1=姓名 2=身份证号 3=姓名_身份证号

                Syn_SetSexType(1);          // 0=卡中存储的数据	1=解释之后的数据,男、女、未知
                Syn_SetNationType(1);       // 0=卡中存储的数据	1=解释之后的数据 2=解释之后加"族"
                Syn_SetBornType(1);         // 0=YYYYMMDD,1=YYYY年MM月DD日,2=YYYY.MM.DD,3=YYYY-MM-DD,4=YYYY/MM/DD
                Syn_SetUserLifeBType(1);    // 0=YYYYMMDD,1=YYYY年MM月DD日,2=YYYY.MM.DD,3=YYYY-MM-DD,4=YYYY/MM/DD
                Syn_SetUserLifeEType(1, 1); // 0=YYYYMMDD(不转换),1=YYYY年MM月DD日,2=YYYY.MM.DD,3=YYYY-MM-DD,4=YYYY/MM/DD,
                // 0=长期 不转换,	1=长期转换为 有效期开始+50年
                int portResult = Syn_OpenPort(nPort);
                if (portResult == 0)
                {
                    if (Syn_SetMaxRFByte(nPort, 80, 0) == 0)
                    {
                        nRet = Syn_StartFindIDCard(nPort, ref pucIIN[0], 0);
                        nRet = Syn_SelectIDCard(nPort, ref pucSN[0], 0);
                        nRet = Syn_ReadMsg(nPort, 0, ref CardMsg);
                        if (nRet == 0)
                        {
                            //新中新
                            dt.Columns.Add("姓名");
                            dt.Columns.Add("性别");
                            dt.Columns.Add("性别编码");
                            dt.Columns.Add("民族");
                            dt.Columns.Add("出生日期");
                            dt.Columns.Add("地址");
                            dt.Columns.Add("身份证号");
                            dt.Columns.Add("发证机关");
                            dt.Columns.Add("有效期开始");
                            dt.Columns.Add("有效期结束");
                            dt.Columns.Add("照片文件名");
                            dt.Rows.Add();
                            dt.Rows[dt.Rows.Count - 1]["姓名"]    = CardMsg.Name;
                            dt.Rows[dt.Rows.Count - 1]["性别"]    = CardMsg.Sex;
                            dt.Rows[dt.Rows.Count - 1]["性别编码"]  = CardMsg.Sex.Equals("男") ? "1" : "2";
                            dt.Rows[dt.Rows.Count - 1]["民族"]    = CardMsg.Nation;
                            dt.Rows[dt.Rows.Count - 1]["出生日期"]  = CardMsg.Born;
                            dt.Rows[dt.Rows.Count - 1]["地址"]    = CardMsg.Address;
                            dt.Rows[dt.Rows.Count - 1]["身份证号"]  = CardMsg.IDCardNo;
                            dt.Rows[dt.Rows.Count - 1]["发证机关"]  = CardMsg.GrantDept;
                            dt.Rows[dt.Rows.Count - 1]["有效期开始"] = CardMsg.UserLifeBegin;
                            dt.Rows[dt.Rows.Count - 1]["有效期结束"] = CardMsg.UserLifeEnd;
                            dt.Rows[dt.Rows.Count - 1]["照片文件名"] = CardMsg.PhotoFileName;
                        }
                        else if (nRet == 1)
                        {
                            //神思
                            dt.Columns.Add("姓名");
                            dt.Columns.Add("性别");
                            dt.Columns.Add("性别编码");
                            dt.Columns.Add("民族");
                            dt.Columns.Add("出生日期");
                            dt.Columns.Add("地址");
                            dt.Columns.Add("身份证号");
                            dt.Columns.Add("发证机关");
                            dt.Columns.Add("有效期开始");
                            dt.Columns.Add("有效期结束");
                            dt.Columns.Add("照片文件名");
                            dt.Rows.Add();
                            dt.Rows[dt.Rows.Count - 1]["姓名"]    = CardMsg.Name;
                            dt.Rows[dt.Rows.Count - 1]["性别"]    = CardMsg.Sex;
                            dt.Rows[dt.Rows.Count - 1]["性别编码"]  = CardMsg.Sex.Equals("男") ? "1" : "2";
                            dt.Rows[dt.Rows.Count - 1]["民族"]    = CardMsg.Nation;
                            dt.Rows[dt.Rows.Count - 1]["出生日期"]  = CardMsg.Born;
                            dt.Rows[dt.Rows.Count - 1]["地址"]    = CardMsg.Address;
                            dt.Rows[dt.Rows.Count - 1]["身份证号"]  = CardMsg.IDCardNo;
                            dt.Rows[dt.Rows.Count - 1]["发证机关"]  = CardMsg.GrantDept;
                            dt.Rows[dt.Rows.Count - 1]["有效期开始"] = CardMsg.UserLifeBegin;
                            dt.Rows[dt.Rows.Count - 1]["有效期结束"] = CardMsg.UserLifeEnd;
                            dt.Rows[dt.Rows.Count - 1]["照片文件名"] = CardMsg.PhotoFileName;
                        }
                        else
                        {
                            stmp = Convert.ToString(System.DateTime.Now) + "  读取身份证信息错误";
                            throw new Exception(stmp);
                        }
                    }
                }
                else
                {
                    System.Threading.Thread.Sleep(1);
                    stmp = Convert.ToString(System.DateTime.Now) + "  读取故障,请重新读取!" + portResult.ToString();
                    // listBox1.Items.Add(stmp);
                    throw new Exception(stmp);
                    //return readSfzh();
                }
            }
            catch (Exception ex)
            {
                timer1.Enabled = false;
                if (this.Owner != null)
                {
                    sysCommonForm owerForm = (sysCommonForm)this.Owner;
                    owerForm.setStatus("1");
                }
                MessageBox.Show(ex.Message);
            }
            return(dt);
        }
示例#8
0
        private void readIDCard()
        {
            try
            {
                string[] files = Directory.GetFiles(BaseConfig.SavePathPhoto + "\\tmp");
                foreach (var f in files)
                {
                    try
                    {
                        File.Delete(f);
                    }
                    catch { }
                }
            }
            catch (Exception ex) { }
            IDCardData CardMsg = new IDCardData();

            string[] stmp   = new string[11];
            byte[]   pucIIN = new byte[4];
            byte[]   pucSN  = new byte[8];
            Syn_StartFindIDCard(BaseConfig.NPort, ref pucIIN[0], 0);
            Syn_SelectIDCard(BaseConfig.NPort, ref pucSN[0], 0);
            try
            {
                int ii = Syn_ReadMsg(BaseConfig.NPort, 0, ref CardMsg);
                if (ii == 0)
                {
                    Status.Text        = "读取成功";
                    Name.Text          = CardMsg.Name.Trim();
                    Sex.Text           = CardMsg.Sex;
                    Nation.Text        = CardMsg.Nation;
                    Born.Text          = CardMsg.Born;
                    Address.Text       = CardMsg.Address;
                    ID.Text            = CardMsg.IDCardNo;
                    GrantDept.Text     = CardMsg.GrantDept;
                    UserLifeBegin.Text = CardMsg.UserLifeBegin;
                    Link.Text          = "--";
                    UserLifeEnd.Text   = CardMsg.UserLifeEnd;

                    string fileName    = System.IO.Path.Combine(BaseConfig.SavePathPhoto, string.Format("{0}_{1}.bmp", CardMsg.Name.Trim(), CardMsg.IDCardNo));
                    string newFileName = string.Format("{0}_{1}_{2}.bmp", Guid.NewGuid().ToString(), CardMsg.Name.Trim(), CardMsg.IDCardNo);
                    string newPath     = System.IO.Path.Combine(BaseConfig.SavePathPhoto, "tmp", newFileName);
                    File.Copy(fileName, newPath);
                    fileNameForUpdate = newPath;
                    photo.Source      = new BitmapImage(new Uri(newPath, UriKind.Absolute));

                    if (referForCheck())
                    {
                        msgBlock.Text       = "通 过";
                        msgBlock.Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#2786E4"));
                    }
                    else
                    {
                        msgBlock.Text = "";
                        //msgBlock.Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#EA0000"));
                    }

                    if (BaseConfig.SaveNotes)
                    {
                        string       timeForName   = System.DateTime.Now.ToString("yyyy_MM_dd");
                        FileStream   file          = new FileStream(BaseConfig.SavePath + "\\" + timeForName + "记录.txt", FileMode.Append, FileAccess.Write);
                        StreamWriter stingForWrite = new StreamWriter(file);
                        stmp[0] = Convert.ToString(System.DateTime.Now);
                        stmp[1] = "  姓名:" + Name.Text;
                        stmp[2] = "  性别:" + Sex.Text;
                        stmp[3] = "  民族:" + Nation.Text;
                        stmp[4] = "  身份证号:" + ID.Text;
                        stmp[5] = "  出生日期:" + Born.Text;
                        stmp[6] = "  地址:" + Address.Text;
                        stmp[7] = "  发证机关:" + GrantDept.Text;
                        stmp[8] = "  有效期开始:" + UserLifeBegin.Text;
                        stmp[9] = "  有效期结束:" + UserLifeEnd.Text;
                        for (int i = 0; i <= 9; i++)
                        {
                            stingForWrite.WriteLine(stmp[i]);
                        }
                        stingForWrite.Close();
                        file.Close();
                    }
                }
                else
                {
                    Status.Text = "请放卡...";
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            finally
            {
                //Marshal.FreeHGlobal(msg);
                //Marshal.FreeHGlobal(img);
            }
        }
示例#9
0
        public void xzxIdCard()
        {
            byte[]                buffer      = new byte[4];
            byte[]                buffer2     = new byte[8];
            IDCardData            pIDCardData = new IDCardData();
            bool                  flag        = false;
            string                str         = "";
            int                   num         = Syn_OpenPort(this.usbPort);
            ReadIdentifyEventArgs e           = new ReadIdentifyEventArgs();

            if (num == 0)
            {
                if (num == 0)
                {
                    Syn_StartFindIDCard(this.usbPort, ref buffer[0], 0);
                    Syn_SelectIDCard(this.usbPort, ref buffer2[0], 0);
                    //Syn_SetNationType(2);
                    num = Syn_ReadMsg(this.usbPort, 0, ref pIDCardData);
                    if (num == 0)
                    {
                        DateTime time2;
                        string   str7;
                        new RecordsBaseInfoModel();
                        DateTime today  = DateTime.Today;
                        string   nation = "";
                        PadForm.idNo = pIDCardData.IDCardNo.Trim();
                        string name     = pIDCardData.Name.Trim();
                        string iDCardNo = pIDCardData.IDCardNo.Trim();
                        string sex      = pIDCardData.Sex.Trim();
                        string address  = pIDCardData.Address.Trim();

                        if ((pIDCardData.Born.Length == 8) && DateTime.TryParse(pIDCardData.Born.Substring(0, 4) + "-" + pIDCardData.Born.Substring(4, 2) + "-" + pIDCardData.Born.Substring(6, 2), out time2))
                        {
                            today = time2;
                        }

                        if (pIDCardData.Nation == "汉族")
                        {
                            str7 = "1";
                        }
                        else
                        {
                            str7   = "2";
                            nation = GetNation(pIDCardData.Nation);
                        }

                        this.StopRead();
                        e.Name       = name;
                        e.Idcard     = iDCardNo;
                        e.Addr       = address;
                        e.Birthday   = today;
                        e.Nation     = str7;
                        e.Sex        = sex;
                        e.Minority   = nation;
                        e.ReadResult = 0;
                        flag         = true;
                    }
                    else
                    {
                        flag = false;
                    }
                }
            }
            else
            {
                str = "身份证读卡器端口打开失败:";
            }
            if ((str != "") || !flag)
            {
                if (str != "")
                {
                    e.ReadResult = -1;
                    e.ErrorInfo  = str + num;
                }
            }
            else
            {
                this.StopRead();
            }
            if (base.readCardEvent == null)
            {
                throw new Exception("readCardEvent 为NULL");
            }
            base.readCardEvent(this, e);
        }
示例#10
0
        private void button3_Click(object sender, EventArgs e)
        {
            IDCardData CardMsg = new IDCardData();
            int        nRet, nPort, iPhotoType;
            string     stmp;

            byte[] cPath  = new byte[255];
            byte[] pucIIN = new byte[4];
            byte[] pucSN  = new byte[8];
            byte[] ucPath = new byte[256];
            nPort = m_iPort;
            if (pictureBox1.Image != null)
            {
                pictureBox1.Image.Dispose();
                pictureBox1.Image = null;
            }
            Syn_SetPhotoPath(0, ref cPath[0]);  //设置照片路径	iOption 路径选项	0=C:	1=当前路径	2=指定路径
            //cPhotoPath	绝对路径,仅在iOption=2时有效
            iPhotoType = 0;
            Syn_SetPhotoType(0);        //0 = bmp ,1 = jpg , 2 = base64 , 3 = WLT ,4 = 不生成
            Syn_SetPhotoName(2);        // 生成照片文件名 0=tmp 1=姓名 2=身份证号 3=姓名_身份证号

            Syn_SetSexType(1);          // 0=卡中存储的数据	1=解释之后的数据,男、女、未知
            Syn_SetNationType(1);       // 0=卡中存储的数据	1=解释之后的数据 2=解释之后加"族"
            Syn_SetBornType(1);         // 0=YYYYMMDD,1=YYYY年MM月DD日,2=YYYY.MM.DD,3=YYYY-MM-DD,4=YYYY/MM/DD
            Syn_SetUserLifeBType(1);    // 0=YYYYMMDD,1=YYYY年MM月DD日,2=YYYY.MM.DD,3=YYYY-MM-DD,4=YYYY/MM/DD
            Syn_SetUserLifeEType(1, 1); // 0=YYYYMMDD(不转换),1=YYYY年MM月DD日,2=YYYY.MM.DD,3=YYYY-MM-DD,4=YYYY/MM/DD,
            // 0=长期 不转换,	1=长期转换为 有效期开始+50年
            if (Syn_OpenPort(nPort) == 0)
            {
                if (Syn_SetMaxRFByte(nPort, 80, 0) == 0)
                {
                    nRet = Syn_StartFindIDCard(nPort, ref pucIIN[0], 0);
                    nRet = Syn_SelectIDCard(nPort, ref pucSN[0], 0);
                    nRet = Syn_ReadFPMsg(nPort, 0, ref CardMsg, ref ucPath[0]);
                    if (nRet == 0 || nRet == 1)
                    {
                        stmp = Convert.ToString(System.DateTime.Now) + "  姓名:" + CardMsg.Name;
                        listBox1.Items.Add(stmp);
                        stmp = Convert.ToString(System.DateTime.Now) + "  性别:" + CardMsg.Sex;
                        listBox1.Items.Add(stmp);
                        stmp = Convert.ToString(System.DateTime.Now) + "  民族:" + CardMsg.Nation;
                        listBox1.Items.Add(stmp);
                        stmp = Convert.ToString(System.DateTime.Now) + "  出生日期:" + CardMsg.Born;
                        listBox1.Items.Add(stmp);
                        stmp = Convert.ToString(System.DateTime.Now) + "  地址:" + CardMsg.Address;
                        listBox1.Items.Add(stmp);
                        stmp = Convert.ToString(System.DateTime.Now) + "  身份证号:" + CardMsg.IDCardNo;
                        listBox1.Items.Add(stmp);
                        stmp = Convert.ToString(System.DateTime.Now) + "  发证机关:" + CardMsg.GrantDept;
                        listBox1.Items.Add(stmp);
                        stmp = Convert.ToString(System.DateTime.Now) + "  有效期开始:" + CardMsg.UserLifeBegin;
                        listBox1.Items.Add(stmp);
                        stmp = Convert.ToString(System.DateTime.Now) + "  有效期结束:" + CardMsg.UserLifeEnd;
                        listBox1.Items.Add(stmp);
                        stmp = Convert.ToString(System.DateTime.Now) + "  照片文件名:" + CardMsg.PhotoFileName;
                        listBox1.Items.Add(stmp);
                        ASCIIEncoding encoding = new ASCIIEncoding();
                        stmp = Convert.ToString(System.DateTime.Now) + "  指纹信息文件名:" + encoding.GetString(ucPath, 0, 256);  //Convert.ToString(ucPath[0]);
                        listBox1.Items.Add(stmp);
                        if (iPhotoType == 0 || iPhotoType == 1)
                        {
                            pictureBox1.Image = Image.FromFile(CardMsg.PhotoFileName);
                        }
                    }
                    else
                    {
                        stmp = Convert.ToString(System.DateTime.Now) + "  读取身份证信息错误";
                        listBox1.Items.Add(stmp);
                    }
                }
            }
            else
            {
                stmp = Convert.ToString(System.DateTime.Now) + "  打开端口失败";
                listBox1.Items.Add(stmp);
            }
        }
示例#11
0
        public void CheckTest01()
        {
            var id = "12345";

            IDCardData.Check(id).Should().BeFalse();
        }
示例#12
0
        public override IDCardInfo readIDCard(bool get_photo, out string msg)
        {
            msg = "";
            //如果端口号为空,则以1001为默认
            if (port_number == "")
            {
                port_number = "1001";
            }
            IDCardInfo info = new IDCardInfo();

            try
            {
                var port = Syn_FindReader();
                if (port <= 0)
                {
                    msg = "无法获取有效的读卡器";
                    return(info);
                }
                if (Syn_OpenPort(port) != 0)
                {
                    msg = "打开端口失败";
                    return(info);
                }
                if (Syn_SetMaxRFByte(port, 80, 0) != 0)
                {
                    msg = "尝试连接读卡器失败";
                    return(info);
                }
                var pucIIN = new byte[4];
                if (Syn_StartFindIDCard(port, ref pucIIN[0], 0) != 0)
                {
                    msg = "查询身份证失败, 请确认身份证已放置";
                    return(info);
                }
                var pucSN = new byte[8];
                if (Syn_SelectIDCard(port, ref pucSN[0], 0) != 0)
                {
                    msg = "选择卡片失败, 请重试";
                    return(info);
                }
                var card_msg = new IDCardData();
                if (Syn_ReadMsg(port, 0, ref card_msg) != 0)
                {
                    msg = "读取卡片信息失败, 请重试";
                    return(info);
                }
                info.name           = card_msg.Name;
                info.gender         = card_msg.Sex;
                info.nation         = card_msg.Name;
                info.Birthday       = card_msg.Born;
                info.address        = card_msg.Address;
                info.id_card_number = card_msg.IDCardNo;
                info.department     = card_msg.GrantDept;
                info.StartDate      = card_msg.UserLifeBegin;
                info.EndDate        = card_msg.UserLifeEnd;
                if (get_photo)
                {
                    info.photo = ImageUtil.fromUrl(AppDomain.CurrentDomain.BaseDirectory + card_msg.PhotoFileName);
                }
            }
            catch (Exception ex) { msg = ex.Message; }
            return(info);
        }
示例#13
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private IDCardData DirectReadCard()
        {
            if (!TryOpenUSB())
            {
                if (!TryOpenSerial())
                {
                    throw new ApplicationException("连接读卡器失败");
                }
            }

            byte[]     pucIIN  = new byte[4];
            byte[]     pucSN   = new byte[8];
            IDCardData cardMsg = new IDCardData();

            int nRet = 0;

            nRet = Syn_StartFindIDCard(this.lstPort, ref pucIIN[0], 0);
            nRet = Syn_SelectIDCard(this.lstPort, ref pucSN[0], 0);

            string baseMsg = new string(' ', 256);                 //身份证基本信息返回长度为256
            string imgMsg  = new string(' ', 1024);                //身份证图片信息返回长度为1024
            IntPtr msg     = Marshal.StringToHGlobalAnsi(baseMsg); //身份证基本信息
            IntPtr img     = Marshal.StringToHGlobalAnsi(imgMsg);  //身份证图片

            try
            {
                uint mLen = 0;
                uint iLen = 0;
                nRet = Syn_ReadBaseMsg(this.lstPort, msg, ref mLen, img, ref iLen, 1);
                if (nRet == 0)
                {
                    string card  = Marshal.PtrToStringUni(msg);
                    char[] cartb = card.ToCharArray();
                    cardMsg.Name       = (new string(cartb, 0, 15)).Trim();
                    cardMsg.Sex        = new string(cartb, 15, 1);
                    cardMsg.Nation     = new string(cartb, 16, 2);
                    cardMsg.Born       = FmtDate(new string(cartb, 18, 8));
                    cardMsg.Address    = (new string(cartb, 26, 35)).Trim();
                    cardMsg.IDCardNo   = new string(cartb, 61, 18);
                    cardMsg.GrantDept  = (new string(cartb, 79, 15)).Trim();
                    cardMsg.ValidBegin = FmtDate(new string(cartb, 94, 8));
                    cardMsg.ValidEnd   = FmtDate(new string(cartb, 102, 8));
                    switch (cardMsg.Sex)
                    {
                    case "1":
                        cardMsg.SexName = "男";
                        break;

                    case "2":
                        cardMsg.SexName = "女";
                        break;
                    }
                    if (lstMZ.Contains(cardMsg.Nation))
                    {
                        cardMsg.NationName = lstMZ[cardMsg.Nation].ToString();
                    }
                    return(cardMsg);
                }
                else
                {
                    throw new ApplicationException("读取身份证信息错误");
                }
            }
            catch (Exception e2)
            {
                throw new ApplicationException(e2.Message);
            }
            finally
            {
                Syn_ClosePort(this.lstPort);
                Marshal.FreeHGlobal(msg);
                Marshal.FreeHGlobal(img);
            }
        }