Exemplo n.º 1
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
            });;
        }
Exemplo n.º 2
0
        /// <summary>
        /// 上传文件
        /// </summary>
        private Respbase <IdCardUploadFileDto> UploadImg(ReqUploadFile req)
        {
            FileService fileService = new FileService();

            if (!fileService.SaveFile(req))
            {
                return(new Respbase <IdCardUploadFileDto> {
                    Result = -1, Message = "保存文件失败", Data = null
                });
            }

            if (req.ImageActionType == FileActionType.身份证正面图片 || req.ImageActionType == FileActionType.身份证反面图片)
            {
                IdCardService idCardService = new IdCardService();
                var           res           = idCardService.IdCardPicRecognise((int)req.ImageActionType, fileService.PhysicsFilePath);
                if (res.Result == 1)
                {
                    return(new Respbase <IdCardUploadFileDto>
                    {
                        Result = res.Result,
                        Data = new IdCardUploadFileDto
                        {
                            Url = fileService.FilePath,
                            IdentCard = res.Data
                        },
                        Message = res.Message
                    });
                }
                return(new Respbase <IdCardUploadFileDto> {
                    Result = res.Result, Data = new IdCardUploadFileDto {
                        Url = fileService.Image2FilePath,
                    }, Message = res.Message
                });
            }

            if (req.ImageActionType == FileActionType.驾驶证行驶证)
            {
                string photoPhysicalPath = FileService.GetPhysicsFilePath(fileService.FilePath);
                (bool success, string message, object result) = ScanLicense.GetInstance(LicenseTypeEnum.Driver).Execute(new ExecuteEntity()
                {
                    PhotoPhysicalPath = photoPhysicalPath
                });
                if (!success)
                {
                    return(new Respbase <IdCardUploadFileDto> {
                        Result = -1, Message = "识别驾驶证失败", Data = new IdCardUploadFileDto {
                            Url = fileService.Image2FilePath
                        }
                    });
                }
                DriverResult driResult    = ((DriverResp)result).words_result;
                PXinContext  db           = HttpContext.Current.GetDbContext <PXinContext>();
                var          tnetNodeInfo = db.TnetNodeinfoSet.FirstOrDefault(w => w.Nodeid == req.Nodeid);
                if (tnetNodeInfo == null)
                {
                    return(new Respbase <IdCardUploadFileDto> {
                        Result = -1, Message = "用户未进行身份认证", Data = new IdCardUploadFileDto {
                            Url = fileService.Image2FilePath
                        }
                    });
                }
                if (tnetNodeInfo.Name.Trim() != driResult.姓名.words.Trim() || tnetNodeInfo.Idcardno.Trim() != driResult.证号.words.Trim())
                {
                    return(new Respbase <IdCardUploadFileDto> {
                        Result = -1, Message = "驾驶证信息与身份证信息不一致", Data = new IdCardUploadFileDto {
                            Url = fileService.Image2FilePath
                        }
                    });
                }
            }

            return(new Respbase <IdCardUploadFileDto> {
                Data = new IdCardUploadFileDto {
                    Url = fileService.Image2FilePath
                }
            });
        }