Ejemplo n.º 1
0
 /// <summary>
 /// 用户认证(通过钱包)
 /// </summary>
 /// <param name="req"></param>
 /// <returns></returns>
 public UserAuthInfoDto UserAuthByPurse(AuthenByPurseReq req)
 {
     if (!IsCanAuth(req, out TnetNodeinfo nodeInfo, out TzcAuthLog authLog, out IdentResult identResultFront, out IdentResult identResultBack))
     {
         return(null);
     }
     if (!CopyAuthPicToReallyDir(req))
     {
         return(null);
     }
     if (!SaveAuthInfo(nodeInfo, authLog, identResultFront, identResultBack, req))
     {
         db.Rollback();
         DeleteAuthPic(new string[] { req.CardFrontPicUrl, req.CardBackPicUrl, req.HoldCardPicUrl });
         return(null);
     }
     RemoveRegInfoCache(req.Nodeid);
     return(GetUserAuthInfo(req.Nodeid));
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 获取用户认证日志
 /// </summary>
 /// <param name="req"></param>
 /// <param name="authLog"></param>
 /// <param name="identResultFront"></param>
 /// <param name="identResultBack"></param>
 private void BuildAuthLog(AuthenByPurseReq req, TzcAuthLog authLog, IdentResult identResultFront, IdentResult identResultBack)
 {
     authLog.Nodeid     = req.Nodeid;
     authLog.Createtime = DateTime.Now;
     authLog.Remarks    = "用户认证";
     authLog.Realname   = identResultFront.cards[0].name;
     try
     {
         authLog.Birthday = Convert.ToDateTime(identResultFront.cards[0].birthday);
     }
     catch (Exception err)
     {
         log.Info(identResultFront.cards[0].birthday + "转换为生日失败," + err.ToString());
     }
     authLog.Race      = identResultFront.cards[0].race;
     authLog.Sex       = identResultFront.cards[0].gender == "女" ? 2 : 1;
     authLog.Idcard    = identResultFront.cards[0].id_card_number;
     authLog.Address   = identResultFront.cards[0].address;
     authLog.IssuedBy  = identResultBack.cards[0].issued_by;
     authLog.ValidDate = identResultBack.cards[0].valid_date;
     //分解身份证身日性别
     if (authLog.Idcard.Length == 18 && !authLog.Birthday.HasValue)
     {
         //(1)前1、2位数字表示:所在省份的代码;
         //(2)第3、4位数字表示:所在城市的代码;
         //(3)第5、6位数字表示:所在区县的代码;
         //(4)第7~14位数字表示:出生年、月、日;
         //(5)第15、16位数字表示:所在地的派出所的代码;
         //(6)第17位数字表示性别:奇数表示男性,偶数表示女性;
         //(7)第18位数字是校检码:也有的说是个人信息码,用来检验身份证的正确性。校检码可以是0~9的数字,有时也用x表示(尾号是10,那么就得用X来代替)。 一般是随计算机的随机产生。
         authLog.Sex      = Convert.ToInt32(authLog.Idcard.Substring(16, 1)) % 2 == 0 ? 2 : 1;
         authLog.Birthday = new DateTime(Convert.ToInt32(authLog.Idcard.Substring(6, 4)),
                                         Convert.ToInt32(authLog.Idcard.Substring(10, 2)),
                                         Convert.ToInt32(authLog.Idcard.Substring(12, 2)));
     }
     authLog.Idcardpic1  = req.CardFrontPicUrl;
     authLog.Idcardpic2  = req.HoldCardPicUrl;
     authLog.Idcardpic3  = req.CardBackPicUrl;
     authLog.Isidentify  = 1;
     authLog.Baiduapiret = req.BaiDuRet;
     authLog.Status      = 5;        //通过实人认证,不需要再审核了
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 是否可进行注册
        /// </summary>
        /// <param name="req"></param>
        /// <param name="nodeInfo"></param>
        /// <param name="authLog"></param>
        /// <param name="identResultFront"></param>
        /// <param name="identResultBack"></param>
        /// <returns></returns>
        private bool IsCanAuth(AuthenByPurseReq req, out TnetNodeinfo nodeInfo, out TzcAuthLog authLog, out IdentResult identResultFront, out IdentResult identResultBack)
        {
            identResultFront = null;
            identResultBack  = null;
            if (!AuthBasicCheck(req.Nodeid, out TnetReginfo regInfo, out nodeInfo, out authLog))
            {
                return(false);
            }
            if (regInfo.Isconfirmed == 1 && nodeInfo != null && authLog != null && authLog.Status == 5)
            {
                Alert("已通过实人认证,不要重复认证");
                return(false);
            }
            identResultFront = GetIdentResult(req.CardFrontPicUrl);
            if (identResultFront == null)
            {
                Alert("未找到身份证正面照识别结果");
                return(false);
            }
            identResultBack = GetIdentResult(req.CardBackPicUrl);
            if (identResultBack == null)
            {
                Alert("未找到身份证反面照识别结果");
                return(false);
            }
            var cardNumber = identResultFront.cards[0].id_card_number;

            if (db.TzcAuthLogSet.Where(s => s.Nodeid != regInfo.Nodeid && s.Idcard == cardNumber).Count() > 0 ||
                db.TnetNodeinfoSet.Where(s => s.Nodeid != regInfo.Nodeid && s.Idcardno == cardNumber).Count() > 0
                )
            {
                Alert("身份证[" + identResultFront.cards[0].id_card_number + "]已存在");
                log.Info("身份证[" + identResultFront.cards[0].id_card_number + "]已存在,nodeid=" + regInfo.Nodeid);
                return(false);
            }
            return(true);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 拷贝认证照片到真实路径
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        private bool CopyAuthPicToReallyDir(AuthenByPurseReq req)
        {
            bool   copySuccess = true;
            string dateTime    = DateTime.Now.ToString("yyyyMMddhhmmss");
            string frontUrl    = authImagePath + req.Nodeid + "-" + dateTime + "-Front" + Path.GetExtension(req.CardFrontPicUrl);
            var    sourceDir   = $"/images2/tempfile/{DateTime.Now.ToString("yyyyMMdd")}/";
            var    cutPath     = "/images2";

            if (copySuccess && !Common.Facade.Helper.CopyFile(HttpContext.Current.Server.MapPath(sourceDir + Path.GetFileName(req.CardFrontPicUrl)), HttpContext.Current.Server.MapPath(frontUrl)))
            {
                copySuccess = false;
            }
            req.CardFrontPicUrl = AppConfig.ImageBaseUrl + frontUrl.Replace(cutPath, "");

            string backUrl = authImagePath + req.Nodeid + "-" + dateTime + "-Back" + Path.GetExtension(req.CardBackPicUrl);

            if (copySuccess && !Common.Facade.Helper.CopyFile(HttpContext.Current.Server.MapPath(sourceDir + Path.GetFileName(req.CardBackPicUrl)), HttpContext.Current.Server.MapPath(backUrl)))
            {
                copySuccess = false;
            }
            req.CardBackPicUrl = AppConfig.ImageBaseUrl + backUrl.Replace(cutPath, "");

            string holdUrl = authImagePath + req.Nodeid + "-" + dateTime + "-Hold" + Path.GetExtension(req.HoldCardPicUrl);

            if (copySuccess && !Common.Facade.Helper.CopyFile(HttpContext.Current.Server.MapPath(sourceDir + Path.GetFileName(req.HoldCardPicUrl)), HttpContext.Current.Server.MapPath(holdUrl)))
            {
                copySuccess = false;
            }
            req.HoldCardPicUrl = AppConfig.ImageBaseUrl + holdUrl.Replace(cutPath, "");
            if (!copySuccess)
            {
                DeleteAuthPic(new string[] { req.CardFrontPicUrl, req.CardBackPicUrl, req.HoldCardPicUrl });
                log.Error("CopyAuthPicToReallyDir", "认证失败");
                Alert("认证失败");
            }
            return(copySuccess);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 保存用户认证信息
        /// </summary>
        /// <param name="oldnodeInfo"></param>
        /// <param name="oldAuthLog"></param>
        /// <param name="identResultFront"></param>
        /// <param name="identResultBack"></param>
        /// <param name="req"></param>
        /// <returns></returns>
        private bool SaveAuthInfo(TnetNodeinfo oldnodeInfo, TzcAuthLog oldAuthLog, IdentResult identResultFront, IdentResult identResultBack, AuthenByPurseReq req)
        {
            bool isFirst = oldAuthLog == null;

            if (isFirst)
            {
                oldAuthLog = new TzcAuthLog()
                {
                    Payment = -1
                };
                oldnodeInfo = new TnetNodeinfo()
                {
                };
            }
            BuildAuthLog(req, oldAuthLog, identResultFront, identResultBack);
            BuildNodeInfo(oldnodeInfo, oldAuthLog);
            if (isFirst)
            {
                db.TzcAuthLogSet.Add(oldAuthLog);
                db.TnetNodeinfoSet.Add(oldnodeInfo);
            }
            var regInfo = db.TnetReginfoSet.FirstOrDefault(f => f.Nodeid == req.Nodeid);

            regInfo.Isconfirmed = 1;
            regInfo.Nodename    = oldAuthLog.Realname;
            regInfo.Authtime    = DateTime.Now;
            if (db.SaveChanges() < 1)
            {
                log.Error("SaveAuthInfo", "认证失败");
                Alert("认证失败");
                return(false);
            }
            return(true);
        }