예제 #1
0
        /// <summary>
        /// 身份证校验18位卡
        /// </summary>
        /// <param name="idcard">身份证号码</param>
        /// <returns></returns>
        private static IDCardInfo VerifyIdcard18(this string idcard)
        {
            var regionid     = Convert.ToInt32(idcard.Substring(0, 2));
            var cityid       = Convert.ToInt32(idcard.Substring(0, 6));
            var region       = table.GetRegion(regionid);
            var province     = table.GetProvince(regionid);
            var city         = table.GetCity(cityid);
            var dayofbirth   = new DateTime(int.Parse(idcard.Substring(6, 4)), int.Parse(idcard.Substring(10, 2)), int.Parse(idcard.Substring(12, 2)));
            var genderid     = int.Parse(idcard.Substring(14, 3));
            var gender       = genderid % 2 == 1 ? "男": "女";
            var code         = GetValidateCode(idcard.Substring(0, 17));
            var isVerifyPass = code == char.Parse(idcard.Substring(17, 1));

            IDCardInfo card = new IDCardInfo()
            {
                City         = city,
                Province     = province,
                Region       = region,
                DayOfBirth   = dayofbirth,
                Gender       = gender,
                IsVerifyPass = isVerifyPass
            };

            return(card);
        }
예제 #2
0
        /// <summary>
        /// 从身份证获得基本信息
        /// </summary>
        /// <param name="idInfo"></param>
        /// <returns></returns>
        public int GetContentFromIDCard(IDCardInfo idInfo)
        {
            string strTemp = "";
            //将读卡生成的本地文件读取到字符串中
            string       filename    = AvatarPath + @"\wz.txt";
            FileStream   fs          = new FileStream(filename, FileMode.Open);
            StreamReader sr          = new StreamReader(fs, System.Text.Encoding.Unicode);
            string       filecontent = sr.ReadToEnd();

            sr.Close();
            //获得姓名
            idInfo.name = filecontent.Substring(0, 15);
            //获得性别
            strTemp = filecontent.Substring(15, 1);
            if (@"1" == strTemp)
            {
                idInfo.sex = @"男";
            }
            else
            {
                idInfo.sex = @"女";
            }

            //获得民族
            strTemp = filecontent.Substring(16, 2);//nationality
            int i = Convert.ToInt32(strTemp);

            idInfo.nation = GetNation(i);

            //获得出生年月日
            strTemp       = filecontent.Substring(18, 8);//birthdate
            idInfo.birthY = strTemp.Substring(0, 4);
            idInfo.birthM = strTemp.Substring(4, 2);
            idInfo.birthD = strTemp.Substring(6, 2);

            //获得住址
            idInfo.address    = filecontent.Substring(26, 35);
            idInfo.newAddress = "";

            //获得身份证号码
            idInfo.ID = filecontent.Substring(61, 18);

            //获得签发机关
            idInfo.org = filecontent.Substring(79, 15);//org

            //获得有效期
            strTemp         = filecontent.Substring(94, 16);//period
            idInfo.vaildity = strTemp.Substring(0, 4) + @"." + strTemp.Substring(4, 2) + @"." + strTemp.Substring(6, 2) + @" - " +
                              strTemp.Substring(8, 4) + @"." + strTemp.Substring(12, 2) + @"." + strTemp.Substring(14, 2);

            //获得证件照的特征值
            GetFeatureFromIDImage(idInfo);
            idInfo.isRight = true; //这个标志用来控制是否进行人脸比对
            return(0);
        }
예제 #3
0
 /// <summary>
 /// 从证件照中提取特征值
 /// </summary>
 /// <param name="idInfo"></param>
 /// <returns></returns>
 private IntPtr GetFeatureFromIDImage(IDCardInfo idInfo)
 {
     if (idInfo != null)
     {
         Image image = idInfo.image;
         //提取证件照的特征
         IntPtr featureTemp = GetFeatureFromImage(image);
         //messageBox.AppendText("身份证特征提取成功...\n");
         idInfo.imageFeature = featureTemp;
         return(featureTemp);
     }
     else
     {
         return(IntPtr.Zero);
     }
 }
예제 #4
0
        public void AlwaysReader()
        {
            ret = 0;
            int i = 0;

            //如果身份证没有认证就会一直循环
            while ((ret = IDCardLib.Authenticate()) != 1)
            {
                i++;
                Thread.Sleep(200);
                //放卡
            }

            if (1 == ret)
            {
                //卡认证成功
                //从身份证中读出信息
                //形成文字信息文件 WZ.TXT、相片文件 XP.WLT、 ZP.BMP,如果有指纹信息形成指纹信息文件 FP.DAT
                nRet = IDCardLib.Read_Content(1);
                if (1 == nRet)
                {
                    //信息读取正确...
                    //存放相片信息
                    int           dddd    = IDCardLib.GetBmpPhotoExt();
                    int           cbPhoto = 256 * 1024;
                    StringBuilder sbPhoto = new StringBuilder(cbPhoto);
                    int           nRet1   = IDCardLib.getBMPPhotoBase64(sbPhoto, cbPhoto);
                    byte[]        byPhoto = Convert.FromBase64String(sbPhoto.ToString());
                    if (nRet1 == 1)
                    {
                        MemoryStream ms  = new MemoryStream(byPhoto);
                        Image        img = Image.FromStream(ms);
                        //赋值内存中的身份证数据
                        idInfo       = new IDCardInfo();
                        idInfo.image = img;
                        //进行身份证的信息拿到内存中来
                        GetContentFromIDCard(idInfo);
                        //IDPbox.Image = idInfo.image;
                    }
                }
                else
                {
                    IDCardLib.CloseComm();
                    Port = IDCardLib.InitCommExt();
                }
            }
        }
예제 #5
0
        /// <summary>
        /// 身份证校验15位卡
        /// </summary>
        /// <param name="idcard"></param>
        /// <returns></returns>
        private static IDCardInfo VerifyIdcard15(this string idcard)
        {
            //440304851121261
            var regionid   = Convert.ToInt32(idcard.Substring(0, 2));
            var cityid     = Convert.ToInt32(idcard.Substring(0, 6));
            var region     = table.GetRegion(regionid);
            var province   = table.GetProvince(regionid);
            var city       = table.GetCity(cityid);
            var dayofbirth = new DateTime(int.Parse("19" + idcard.Substring(6, 2)), int.Parse(idcard.Substring(8, 2)), int.Parse(idcard.Substring(10, 2)));
            var genderid   = int.Parse(idcard.Substring(12, 3));
            var gender     = genderid % 2 == 1 ? "男" : "女";

            IDCardInfo card = new IDCardInfo()
            {
                City         = city,
                Province     = province,
                Region       = region,
                DayOfBirth   = dayofbirth,
                Gender       = gender,
                IsVerifyPass = true //15位无校验码
            };

            return(card);
        }