예제 #1
0
        private bool BuildTnetDriverLicLog(TnetDriveLicLog oldTnetDriveLicLog, DriverResult driResult, AuthDriverLicenseReq req)
        {
            string host = HttpContext.Current.Request.Url.Host;

            host = "http://images2." + host.Substring(host.IndexOf('.') + 1);
            oldTnetDriveLicLog.Name            = driResult.姓名.words;
            oldTnetDriveLicLog.Addr            = driResult.住址.words;
            oldTnetDriveLicLog.Birthday        = driResult.出生日期 == null ? "" : driResult.出生日期.words;
            oldTnetDriveLicLog.Cardimg         = req.FrontImgUrl.Replace("/images2", host);
            oldTnetDriveLicLog.CardimgAppendix = req.AppendixImgUrl.Replace("/images2", host);
            oldTnetDriveLicLog.Cardno          = driResult.证号 == null ? "" : driResult.证号.words;
            oldTnetDriveLicLog.Country         = driResult.国籍 == null ? "" : driResult.国籍.words;
            oldTnetDriveLicLog.Enddate         = driResult.至 == null ? "" : driResult.至.words;
            oldTnetDriveLicLog.VehicleType     = driResult.准驾车型 == null ? "" : driResult.准驾车型.words;
            oldTnetDriveLicLog.ValidPeriod     = driResult.效期限 == null ? "" : driResult.效期限.words;
            oldTnetDriveLicLog.Sex             = driResult.性别 == null ? "" : driResult.性别.words;
            oldTnetDriveLicLog.Nodeid          = req.Nodeid;
            oldTnetDriveLicLog.Firtdate        = driResult.初次领证日期 == null ? "" : driResult.初次领证日期.words;
            oldTnetDriveLicLog.Remarks         = "";
            oldTnetDriveLicLog.Status          = 1;
            oldTnetDriveLicLog.Fileno          = req.FileNo;
            return(true);
        }
예제 #2
0
        /// <summary>
        /// 驾驶证绑定
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public DriverLicenseDto AuthDriverLicense(AuthDriverLicenseReq req)
        {
            List <string> oldImgPath = new List <string>();

            req.FrontImgUrl    = req.FrontImgUrl.Replace(Common.Facade.Helper.DomainUrl, "").Replace(AppConfig.FileRootDir, "");
            req.AppendixImgUrl = req.FrontImgUrl.Replace(Common.Facade.Helper.DomainUrl, "").Replace(AppConfig.FileRootDir, "");
            if (!File.Exists(FileService.GetPhysicsFilePath(req.FrontImgUrl)) ||
                !File.Exists(FileService.GetPhysicsFilePath(req.AppendixImgUrl))
                )
            {
                Alert("图片不存在,请先上传图片");
                return(null);
            }
            var reginfo = HttpContext.Current.GetRegInfo();

            if (reginfo.Isconfirmed == 0)
            {
                Alert("您必须通过实名认证后才能绑定驾驶证");
                return(null);
            }
            var driveLicLog = db.TnetDriveLicLogSet.FirstOrDefault(w => w.Nodeid == req.Nodeid);

            if (driveLicLog != null)
            {
                if (req.FrontImgUrl == driveLicLog.Cardimg && req.FileNo.Equals(driveLicLog.Fileno))
                {
                    return(new DriverLicenseDto
                    {
                        DriverLicenseUrl = driveLicLog.Cardimg, AppendixUrl = driveLicLog.CardimgAppendix, FileNo = driveLicLog.Fileno, Name = driveLicLog.Name, Status = driveLicLog.Status
                    });
                }
                oldImgPath.Add(new Uri(driveLicLog.Cardimg).LocalPath.Replace("/driverlicense/", "/images2/driverlicense/"));
                oldImgPath.Add(new Uri(driveLicLog.CardimgAppendix).LocalPath.Replace("/driverlicense/", "/images2/driverlicense/"));
            }
            if (driveLicLog == null)
            {
                driveLicLog = new TnetDriveLicLog();
            }
            string photoPhysicalPath = FileService.GetPhysicsFilePath(req.FrontImgUrl); //(uri_driver.LocalPath);

            (bool success, string message, object result) = ScanLicense.GetInstance(LicenseTypeEnum.Driver).Execute(new ExecuteEntity()
            {
                PhotoPhysicalPath = photoPhysicalPath
            });
            if (!success)
            {
                Alert(message);
                return(null);
            }
            DriverResult driResult    = ((DriverResp)result).words_result;
            var          tnetNodeInfo = db.TnetNodeinfoSet.FirstOrDefault(w => w.Nodeid == req.Nodeid);

            if (tnetNodeInfo == null)
            {
                Alert("用户认证信息错误,请联系管理员");
                return(null);
            }
            if (tnetNodeInfo.Name.Trim() != driResult.姓名.words.Trim() || tnetNodeInfo.Idcardno.Trim() != driResult.证号.words.Trim())
            {
                Alert("驾驶证信息需要与身份证信息一致才能通过审核");
                //Alert("您上传的驾驶证姓名【" + driResult.姓名.words + "】与认证用户名字【" + tnetNodeInfo.Name + "】不一致");
                return(null);
            }
            //if (tnetNodeInfo.Idcardno.Trim() != driResult.证号.words.Trim())
            //{
            //    Alert("您上传的驾驶证证件号【" + driResult.证号.words + "】与认证用户证件号【" + tnetNodeInfo.Idcardno + "】不一致");
            //    return false;
            //}
            string datetime            = DateTime.Now.ToString("yyyyMMddHHmmss");
            string reallyPath_front    = driverImagePath + req.Nodeid + "-" + datetime + "-Driver" + Path.GetExtension(req.FrontImgUrl);
            string reallyPath_appendix = driverImagePath + req.Nodeid + "-" + datetime + "-Appendix" + Path.GetExtension(req.AppendixImgUrl);

            if (
                !Common.Facade.Helper.CopyFile(FileService.GetPhysicsFilePath(req.FrontImgUrl), HttpContext.Current.Server.MapPath(reallyPath_front)) ||
                !Common.Facade.Helper.CopyFile(FileService.GetPhysicsFilePath(req.AppendixImgUrl), HttpContext.Current.Server.MapPath(reallyPath_appendix))
                )
            {
                log.Info("拷贝图片失败:{" + req.FrontImgUrl + "}To{" + reallyPath_front + "}");
                log.Info("{" + req.AppendixImgUrl + "}To{" + reallyPath_appendix + "}");
                DeleteFile(new string[] { reallyPath_front });
                Alert("驾驶证绑定失败");
                return(null);
            }
            req.FrontImgUrl    = reallyPath_front;
            req.AppendixImgUrl = reallyPath_appendix;
            BuildTnetDriverLicLog(driveLicLog, driResult, req);
            if (driveLicLog.Id == 0)
            {
                db.TnetDriveLicLogSet.Add(driveLicLog);
            }
            if (db.SaveChanges() <= 0)
            {
                DeleteFile(new string[] { reallyPath_front, reallyPath_appendix });
                Alert("驾驶证绑定失败");
                return(null);
            }
            if (oldImgPath.Count > 0)
            {
                DeleteFile(oldImgPath.ToArray());
            }
            return(new DriverLicenseDto
            {
                DriverLicenseUrl = driveLicLog.Cardimg, AppendixUrl = driveLicLog.CardimgAppendix, FileNo = driveLicLog.Fileno, Name = driveLicLog.Name, Status = driveLicLog.Status
            });;
        }
예제 #3
0
        /// <summary>
        /// 识别驾驶证
        /// </summary>
        public bool DrivLicense(TnetReginfo regInfo, string imageurl, string imageurl2, string fileno)
        {
            TnetDriveLicLog driveLicLog = db.TnetDriveLicLogSet.FirstOrDefault(x => x.Nodeid == regInfo.Nodeid);

            if (driveLicLog != null)
            {
                if (imageurl == driveLicLog.Cardimg && fileno == driveLicLog.Fileno)
                {
                    Alert("修改驾驶证成功");
                    return(true);
                }
                if (driveLicLog.Status == 1)
                {
                    Alert("您的驾驶证不能修改");
                    return(false);
                }
            }

            string filePath1 = FileService.GetPhysicsFilePath(imageurl);
            string img       = HttpUtility.UrlEncode(GetImageBase64(filePath1));

            BaiduLicense.DrivReq req = new BaiduLicense.DrivReq
            {
                image            = img,
                detect_direction = "true"
            };
            BaiduLicense.DrivResp resp = null;
            try
            {
                //调用百度接口识别驾驶证
                resp = BaiduLicense.DrivSearch(req);
                if (!string.IsNullOrEmpty(resp.error_code))
                {
                    Alert("识别驾驶证错误");
                    return(false);
                }
                if (string.IsNullOrEmpty(resp.words_result.证号.words) || string.IsNullOrEmpty(resp.words_result.准驾车型.words) || string.IsNullOrEmpty(resp.words_result.姓名.words))
                {
                    Alert("识别驾驶证错误");
                    return(false);
                }
                TnetDriveLicLog driveLicLog1 = db.TnetDriveLicLogSet.FirstOrDefault(x => x.Cardno == resp.words_result.证号.words);
                if (driveLicLog1 != null)
                {
                    Alert("该驾驶证已被使用");
                    return(false);
                }
                //TnetNodeinfo tnet_Nodeinfo = db.TnetNodeinfoSet.FirstOrDefault(x => x.Nodeid == regInfo.Nodeid);
                //if (tnet_Nodeinfo == null)
                //{
                //    Alert("获取注册信息失败");
                //    return false;
                //}


                //if (tnet_Nodeinfo.NAME.Trim() != resp.words_result.姓名.words.Trim())
                //{
                //    Alert("您上传的驾驶证姓名【" + resp.words_result.姓名.words + "】与认证用户名字【" + tnet_Nodeinfo.NAME + "】不一致");
                //    return false;
                //}

                //if (tnet_Nodeinfo.IDCARDNO.Trim() != resp.words_result.证号.words.Trim())
                //{
                //    Alert("您上传的驾驶证证件号【" + resp.words_result.证号.words + "】与认证用户证件号【" + tnet_Nodeinfo.IDCARDNO + "】不一致");
                //    return false;
                //}
                if (driveLicLog == null)
                {
                    driveLicLog = new TnetDriveLicLog();
                }
                //识别成功添加到驾驶证识别表
                driveLicLog.Name     = resp.words_result.姓名.words;
                driveLicLog.Addr     = resp.words_result.住址 == null ? "" : resp.words_result.住址.words;
                driveLicLog.Birthday = resp.words_result.出生日期 == null ? "" : resp.words_result.出生日期.words;
                FileService fileService = new FileService();
                DateTime    now         = DateTime.Now;
                driveLicLog.Cardimg         = fileService.CombinePicUrl(imageurl, now, FileActionType.驾驶证行驶证);
                driveLicLog.CardimgAppendix = fileService.CombinePicUrl(imageurl2, now, FileActionType.驾驶证副页);
                driveLicLog.Cardno          = resp.words_result.证号 == null ? "" : resp.words_result.证号.words;
                driveLicLog.Country         = resp.words_result.国籍 == null ? "" : resp.words_result.国籍.words;
                driveLicLog.Enddate         = resp.words_result.至 == null ? "" : resp.words_result.至.words;
                driveLicLog.VehicleType     = resp.words_result.准驾车型 == null ? "" : resp.words_result.准驾车型.words;
                driveLicLog.ValidPeriod     = resp.words_result.效期限 == null ? "" : resp.words_result.效期限.words;
                driveLicLog.Sex             = resp.words_result.性别 == null ? "" : resp.words_result.性别.words;
                driveLicLog.Nodeid          = regInfo.Nodeid;
                driveLicLog.Firtdate        = resp.words_result.初次领证日期 == null ? "" : resp.words_result.初次领证日期.words;
                driveLicLog.Remarks         = "";
                driveLicLog.Status          = 1;
                driveLicLog.Fileno          = fileno;
                driveLicLog.Createtime      = DateTime.Now;


                if (driveLicLog.Id > 0)
                {
                    ////修改
                    //if (!driveLicLog.Update())
                    //{
                    //    log.Info("修改驾驶证失败,原因:" + driveLicLog.DebugInfo.SqlExecutable);
                    //    Alert("修改驾驶证失败");
                    //    return false;
                    //}
                }
                else
                {
                    //添加
                    db.TnetDriveLicLogSet.Add(driveLicLog);
                    //if (!driveLicLog.Insert())
                    //{
                    //    log.Info("添加驾驶证失败,原因:" + driveLicLog.DebugInfo.SqlExecutable);
                    //    Alert("添加驾驶证失败");
                    //    return false;
                    //}
                }
                if (db.SaveChanges() <= 0)
                {
                    Alert("保存驾驶证失败");
                    log.Info("保存驾驶证失败,原因:" + db.Message);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                Alert(ex.Message);
                return(false);
            }
            Alert("识别驾驶证成功");
            return(true);
        }