Пример #1
0
        /// <summary>
        /// 识别行驶证
        /// </summary>
        public bool VehicleLicense(TnetReginfo regInfo, string vehiclelicenseimg)
        {
            TnetVehicleLicLog vehicleLicLog = db.TnetVehicleLicLogSet.FirstOrDefault(x => x.Nodeid == regInfo.Nodeid);

            if (vehicleLicLog != null)
            {
                if (vehiclelicenseimg == vehicleLicLog.Cardimg)
                {
                    Alert("修改行驶证成功");
                    return(true);
                }
                if (vehicleLicLog.Status == 1)
                {
                    Alert("您的行驶证不能修改");
                    return(false);
                }
            }
            string filePath1 = HttpContext.Current.Server.MapPath(vehiclelicenseimg);
            string img       = HttpUtility.UrlEncode(GetImageBase64(filePath1));

            BaiduLicense.VehicleReq req = new BaiduLicense.VehicleReq
            {
                image            = img,
                detect_direction = "true"
            };
            BaiduLicense.VehicleResp resp = null;
            try
            {
                //调用百度接口识别行驶证
                resp = BaiduLicense.VehicleSearch(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);
                }
                TnetVehicleLicLog vehicleLicLog1 = db.TnetVehicleLicLogSet.FirstOrDefault(x => x.Licplateno == resp.words_result.号牌号码.words);
                if (vehicleLicLog1 != 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 (vehicleLicLog == null)
                {
                    vehicleLicLog = new TnetVehicleLicLog();
                }
                //识别成功添加到行驶证识别表
                vehicleLicLog.Belonger     = resp.words_result.所有人.words;
                vehicleLicLog.Address      = resp.words_result.住址 == null ? "" : resp.words_result.住址.words;
                vehicleLicLog.Brandmodel   = resp.words_result.品牌型号 == null ? "" : resp.words_result.品牌型号.words;
                vehicleLicLog.Cardimg      = vehiclelicenseimg;
                vehicleLicLog.Carliccode   = resp.words_result.车辆识别代号 == null ? "" : resp.words_result.车辆识别代号.words;
                vehicleLicLog.Createtime   = DateTime.Now;
                vehicleLicLog.Cartype      = resp.words_result.车辆类型 == null ? "" : resp.words_result.车辆类型.words;
                vehicleLicLog.Engineno     = resp.words_result.发动机号码 == null ? "" : resp.words_result.发动机号码.words;
                vehicleLicLog.Firtdate     = resp.words_result.发证日期 == null ? "" : resp.words_result.发证日期.words;
                vehicleLicLog.Registertime = resp.words_result.注册日期 == null ? "" : resp.words_result.注册日期.words;
                vehicleLicLog.Licplateno   = resp.words_result.号牌号码 == null ? "" : resp.words_result.号牌号码.words;
                vehicleLicLog.Usenature    = resp.words_result.使用性质 == null ? "" : resp.words_result.使用性质.words;
                vehicleLicLog.Nodeid       = regInfo.Nodeid;
                vehicleLicLog.Remarks      = "";
                vehicleLicLog.Status       = 1;

                if (vehicleLicLog.Id > 0)
                {
                    ////修改
                    //if (!vehicleLicLog.Update())
                    //{
                    //    log.Info("修改行驶证失败,原因:" + vehicleLicLog.DebugInfo.SqlExecutable);
                    //    Alert("修改行驶证失败");
                    //    return false;
                    //}
                }
                else
                {
                    //添加
                    db.TnetVehicleLicLogSet.Add(vehicleLicLog);
                    //if (!vehicleLicLog.Insert())
                    //{
                    //    log.Info("添加行驶证失败,原因:" + vehicleLicLog.DebugInfo.SqlExecutable);
                    //    Alert("添加行驶证失败");
                    //    return false;
                    //}
                }
                if (db.SaveChanges() <= 0)
                {
                    Alert("保存行驶证失败");
                    log.Info("保存行驶证失败,原因:" + db.Message);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                log.Info("行驶证改动异常,原因:" + ex);
                Alert(ex.Message);
                return(false);
            }
            Alert("验证行驶证成功");
            return(true);
        }
Пример #2
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);
        }