/// <summary> /// 获取用户注册信息 /// </summary> /// <param name="nodeInfo"></param> /// <param name="authLog"></param> private void BuildNodeInfo(TnetNodeinfo nodeInfo, TzcAuthLog authLog) { nodeInfo.Nodeid = authLog.Nodeid; nodeInfo.Idcardno = authLog.Idcard; nodeInfo.Name = authLog.Realname; nodeInfo.Birthday = authLog.Birthday.Value; nodeInfo.Sex = authLog.Sex; if (!string.IsNullOrEmpty(authLog.Race)) { nodeInfo.Nation = authLog.Race; nodeInfo.Idcardaddr = authLog.Address; nodeInfo.Issuing = authLog.IssuedBy; string[] valid_date = authLog.ValidDate.Split('-'); if (valid_date != null && valid_date.Length == 2) { nodeInfo.Beginvalidity = Convert.ToDateTime(valid_date[0].Replace(".", "-")); if (valid_date[1].Trim() == "长期") { nodeInfo.Endvalidity = new DateTime(2099, 1, 1); } else { nodeInfo.Endvalidity = Convert.ToDateTime(valid_date[1].Replace(".", "-")); } } } }
/// <summary> /// 保存用户认真信息(PCN认证) /// </summary> /// <param name="nodeid"></param> /// <param name="pcnAuthLog"></param> /// <param name="nodeInfo"></param> /// <param name="authLog"></param> /// <param name="oppositeUrlIDCardPicFront"></param> /// <param name="oppositeUrlIDCardPicBack"></param> /// <param name="oppositUrlHoldIDCard"></param> /// <returns></returns> private bool SaveAuthInfoFromPcn(int nodeid, TzcAuthLog pcnAuthLog, TnetNodeinfo nodeInfo, TzcAuthLog authLog, string oppositeUrlIDCardPicFront, string oppositeUrlIDCardPicBack, string oppositUrlHoldIDCard) { bool isFirst = authLog == null; if (isFirst) { authLog = new TzcAuthLog(); nodeInfo = new TnetNodeinfo(); } BuildAuthLog(nodeid, pcnAuthLog, authLog, Common.Facade.Helper.DomainUrl + oppositeUrlIDCardPicFront, Common.Facade.Helper.DomainUrl + oppositeUrlIDCardPicBack, Common.Facade.Helper.DomainUrl + oppositUrlHoldIDCard); BuildNodeInfo(nodeInfo, authLog); if (isFirst) { db.TzcAuthLogSet.Add(authLog); db.TnetNodeinfoSet.Add(nodeInfo); db.TzcAuthBindpcnSet.Add(new TzcAuthBindpcn { Nodeid = authLog.Nodeid, Pcnnodeid = pcnAuthLog.Nodeid, Remarks = "" }); } var regInfo = db.TnetReginfoSet.FirstOrDefault(f => f.Nodeid == nodeid); regInfo.Isconfirmed = 1; regInfo.Nodename = authLog.Realname; regInfo.Authtime = DateTime.Now; if (!(db.SaveChanges() > 0)) { Alert("认证失败"); log.Info("认证失败:" + db.Message); return(false); } return(true); }
/// <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); }
/// <summary> /// 认证参数基础检查 /// </summary> /// <param name="nodeid"></param> /// <param name="regInfo"></param> /// <param name="nodeInfo"></param> /// <param name="authLog"></param> /// <param name="authByPcn"></param> /// <returns></returns> private bool AuthBasicCheck(int nodeid, out TnetReginfo regInfo, out TnetNodeinfo nodeInfo, out TzcAuthLog authLog, bool authByPcn = false) { regInfo = db.TnetReginfoSet.FirstOrDefault(c => c.Nodeid == nodeid); nodeInfo = db.TnetNodeinfoSet.FirstOrDefault(f => f.Nodeid == nodeid); authLog = db.TzcAuthLogSet.FirstOrDefault(f => f.Nodeid == nodeid); if (regInfo.Isconfirmed == 1 && (nodeInfo == null || authLog == null)) { Alert("数据异常,请联系管理员"); log.Info($"用户:{nodeid} 认证数据异常"); return(false); } if (regInfo.Isconfirmed == 0 && (nodeInfo != null || authLog != null)) { Alert("数据异常,请联系管理员"); log.Info($"用户:{nodeid} 认证数据异常"); return(false); } return(true); }
/// <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); }
/// <summary> /// 是否可进行注册(PCN认证) /// </summary> /// <param name="req"></param> /// <param name="pcnReginfo"></param> /// <param name="pcnAuthLog"></param> /// <param name="nodeInfo"></param> /// <param name="authLog"></param> /// <returns></returns> private bool IsCanAuthByPcn(AuthByPCNReq req, PcnAcountInfoDto pcnReginfo, TzcAuthLog pcnAuthLog, out TnetNodeinfo nodeInfo, out TzcAuthLog authLog, bool isAdmin = false) { if (isAdmin) { return(IsCanAuthByPcnAdmin(req, pcnReginfo, pcnAuthLog, out nodeInfo, out authLog)); } if (!AuthBasicCheck(req.Nodeid, out TnetReginfo regInfo, out nodeInfo, out authLog, true)) { return(false); } if (regInfo.Isconfirmed == 1 && nodeInfo != null && authLog != null && authLog.Status == 5) { Alert("已通过实人认证,不要重复认证"); return(false); } if (!CheckPcnPwd(new GetIDCardPicFromPcnReq { Client = req.Client, Nodeid = req.Nodeid, PcnLoginPwd = req.PcnLoginPwd, PcnNodecode = req.PcnNodecode, Sid = req.Sid, Sign = req.Sign, Tm = req.Tm })) { Alert("PCN登陆密码错误"); return(false); } if (db.TzcAuthBindpcnSet.Where(w => w.Pcnnodeid == pcnReginfo.NodeId || w.Nodeid == req.Nodeid).Count() > 0) { Alert("用户已通过PCN认证或此PCN账号已绑定其他用户认证"); return(false); } var otherAuthLog = db.TzcAuthLogSet.Where(w => w.Idcard == pcnAuthLog.Idcard && w.Nodeid != req.Nodeid); if (otherAuthLog.Count() > 0) { Alert("此PCN账号身份证信息已被人使用"); log.Info("PCN认证:PNCNodeid=" + pcnReginfo.NodeId + "的身份证:" + pcnAuthLog.Idcard + "存在相信认证库中"); return(false); } if (string.IsNullOrEmpty(pcnAuthLog.Idcardpic1) || string.IsNullOrEmpty(pcnAuthLog.Idcardpic2) || string.IsNullOrEmpty(pcnAuthLog.Idcardpic3)) { Alert("此PCN账号身份证图片不完整,请联系管理员"); return(false); } if (!req.PcnIDCardFrontPicUrl.Contains(pcnAuthLog.Idcardpic1)) { Alert("身份证正面照非此PCN用户"); return(false); } return(true); }
private bool IsCanAuthByPcnAdmin(AuthByPCNReq req, PcnAcountInfoDto pcnReginfo, TzcAuthLog pcnAuthLog, out TnetNodeinfo nodeInfo, out TzcAuthLog authLog) { if (!AuthBasicCheck(req.Nodeid, out TnetReginfo regInfo, out nodeInfo, out authLog, true)) { return(false); } if (regInfo.Isconfirmed == 1 && nodeInfo != null && authLog != null && authLog.Status == 5) { Alert("已通过实人认证,不要重复认证"); return(false); } if (db.TzcAuthBindpcnSet.Where(w => w.Pcnnodeid == pcnReginfo.NodeId || w.Nodeid == req.Nodeid).Count() > 0) { Alert("用户已通过PCN认证或此PCN账号已绑定其他用户认证"); return(false); } var otherAuthLog = db.TzcAuthLogSet.Where(w => w.Idcard == pcnAuthLog.Idcard && w.Nodeid != req.Nodeid); if (otherAuthLog.Count() > 0) { Alert("此PCN账号身份证信息已被人使用"); log.Info("PCN认证:PNCNodeid=" + pcnReginfo.NodeId + "的身份证:" + pcnAuthLog.Idcard + "存在相信认证库中"); return(false); } if (string.IsNullOrEmpty(pcnAuthLog.Idcardpic1) || string.IsNullOrEmpty(pcnAuthLog.Idcardpic2) || string.IsNullOrEmpty(pcnAuthLog.Idcardpic3)) { Alert("此PCN账号身份证图片不完整,请联系管理员"); return(false); } return(true); }
/// <summary> /// 实名认证 /// </summary> public bool IdCardAuth(IdAuthReq req) { req.Pic1 = "/" + req.Pic1.Replace(AppConfig.ImageBaseUrl, "").TrimStart('/'); req.Pic3 = "/" + req.Pic3.Replace(AppConfig.ImageBaseUrl, "").TrimStart('/'); var regInfo = db.TnetReginfoSet.FirstOrDefault(x => x.Nodeid == req.Nodeid); var authLog = db.TzcAuthLogSet.FirstOrDefault(x => x.Nodeid == req.Nodeid); var nodeInfo = db.TnetNodeinfoSet.FirstOrDefault(x => x.Nodeid == req.Nodeid); if (regInfo.Isconfirmed == 1 && authLog != null && nodeInfo != null && (authLog.Status == 1 || authLog.Status == 5)) { return(Fail("已通过实名认证,不要重复认证")); } IdCardService idCardService = new IdCardService(); IdentResult recResult1 = idCardService.GetRecResult(req.Pic1); if (recResult1 == null) { return(Fail("未找到身份证正面照识别结果")); } IdentResult recResult2 = idCardService.GetRecResult(req.Pic3); if (recResult2 == null) { return(Fail("未找到身份证反面照识别结果")); } var res = ValidateAuthRegInfo(req.Nodeid, recResult1, authLog);//验证信息 if (!res) { return(false); } DateTime myDate = DateTime.Now; TzcAuthLog newAuthLog = new TzcAuthLog(); if (authLog != null) { newAuthLog = authLog; myDate = authLog.Createtime; } newAuthLog.Nodeid = regInfo.Nodeid; newAuthLog.Createtime = DateTime.Now; newAuthLog.Remarks = "用户认证"; newAuthLog.Realname = req.IdCardName.IsNullOrWhiteSpace() ? recResult1.cards[0].name : req.IdCardName; try { newAuthLog.Birthday = Convert.ToDateTime(recResult1.cards[0].birthday); } catch (Exception err) { log.Info(recResult1.cards[0].birthday + "转换为生日失败," + err.ToString()); } newAuthLog.Race = recResult1.cards[0].race; newAuthLog.Sex = recResult1.cards[0].gender == "女" ? 2 : 1; newAuthLog.Idcard = req.IdCardNum.IsNullOrWhiteSpace() ? recResult1.cards[0].id_card_number : req.IdCardNum; newAuthLog.Address = recResult1.cards[0].address; newAuthLog.IssuedBy = recResult2.cards[0].issued_by; newAuthLog.ValidDate = recResult2.cards[0].valid_date; //分解身份证身日性别 if (newAuthLog.Idcard.Length == 18 && !newAuthLog.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来代替)。 一般是随计算机的随机产生。 newAuthLog.Sex = Convert.ToInt32(newAuthLog.Idcard.Substring(16, 1)) % 2 == 0 ? 2 : 1; newAuthLog.Birthday = new DateTime(Convert.ToInt32(newAuthLog.Idcard.Substring(6, 4)), Convert.ToInt32(newAuthLog.Idcard.Substring(10, 2)), Convert.ToInt32(newAuthLog.Idcard.Substring(12, 2))); } FileService fileService = new FileService(); newAuthLog.Idcardpic1 = fileService.CombinePicUrl(req.Pic1, myDate, FileActionType.身份证正面图片); newAuthLog.Idcardpic3 = fileService.CombinePicUrl(req.Pic3, myDate, FileActionType.身份证反面图片); newAuthLog.Isidentify = 1; newAuthLog.Baiduapiret = "0"; newAuthLog.Status = 0; //通过实人认证,不需要再审核了 //添加或更新认证日志 if (authLog == null) { db.TzcAuthLogSet.Add(newAuthLog); } else { db.TzcAuthLogSet.Attach(newAuthLog); db.Entry(newAuthLog).State = EntityState.Modified; } //更新tnet_nodeinfo表 bool isExistnodeInfo = nodeInfo != null; if (nodeInfo == null) { nodeInfo = new TnetNodeinfo(); } BuildNodeInfo(nodeInfo, newAuthLog); if (!isExistnodeInfo) { db.TnetNodeinfoSet.Add(nodeInfo); } else { db.TnetNodeinfoSet.Attach(nodeInfo); db.Entry(nodeInfo).State = EntityState.Modified; } if (regInfo.Isconfirmed == 0) { regInfo.Isconfirmed = 1; regInfo.Nodename = newAuthLog.Realname; regInfo.Authtime = DateTime.Now; if (db.Entry(regInfo).State == EntityState.Detached) { db.TnetReginfoSet.Attach(regInfo); db.Entry(regInfo).State = EntityState.Modified; } } int scnt = db.SaveChanges(); return(true); }