예제 #1
0
 public ActionResult SaveFileImgForm(string keyValue, string imgData, string type, string NewType)
 {
     try
     {
         #region 获取海康地址和秘钥
         DataItemDetailBLL data = new DataItemDetailBLL();
         var    pitem           = data.GetItemValue("Hikappkey");  //海康服务器密钥
         var    baseurl         = data.GetItemValue("HikBaseUrl"); //海康服务器地址
         string Key             = string.Empty;
         string Signature       = string.Empty;
         if (!string.IsNullOrEmpty(pitem))
         {
             Key       = pitem.Split('|')[0];
             Signature = pitem.Split('|')[1];
         }
         #endregion
         if (type == "1")
         {//门岗管理
             List <TemporaryUserEntity> list = new List <TemporaryUserEntity>();
             var tempdate = Tempbll.GetEmptyUserEntity(keyValue);
             if (tempdate != null)
             {
                 var facedata = ImgToBase64(HttpUtility.UrlDecode(imgData));
                 //调用海康平台接口验证人脸照片是否合格
                 int    NewTypes = NewType == "" ? 0 : 1;
                 string msg      = SocketHelper.FaceImgIsQualified(facedata.ImgData, baseurl, Key, Signature, NewTypes);
                 if (msg != null && !string.IsNullOrEmpty(msg))
                 {
                     FaceTestingEntity ress = JsonConvert.DeserializeObject <FaceTestingEntity>(msg);
                     if (!ress.data.checkResult)
                     {
                         return(Content("false", "1"));
                     }
                 }
                 if (string.IsNullOrEmpty(tempdate.UserImg))
                 {//未授权
                     FacedataEntity        face     = new FacedataEntity();
                     List <FacedataEntity> FaceList = new List <FacedataEntity>();
                     face.UserId  = tempdate.USERID;
                     face.ImgData = facedata.ImgData;
                     FaceList.Add(face);
                     SocketHelper.UploadFace(FaceList, baseurl, Key, Signature, NewTypes);
                     tempdate.UserImg = facedata.UserImg;
                     tempdate.ImgData = facedata.ImgData;
                     list.Add(tempdate);
                     Tempbll.SaveTemporaryList(tempdate.USERID, list);
                 }
                 else if (!string.IsNullOrEmpty(tempdate.PassPost))
                 {//已授权
                     tempdate.UserImg = facedata.UserImg;
                     tempdate.ImgData = facedata.ImgData;
                     tempdate.Remark  = "1";
                     if (NewTypes == 1)
                     {//新版本https调用
                         new PersonNewBLL().SaveUserFace(tempdate, keyValue, true);
                     }
                     else
                     {
                         Tempbll.SaveUserFace(tempdate, keyValue, true);
                     }
                 }
                 return(Success("操作成功。"));
             }
             else
             {
                 return(Success("1", "1"));
             }
         }
         else
         {//拜访车辆(门卫)
             CarUserFileImgEntity entity = new CarUserFileImgEntity();
             var facedata = ImgToBase64(HttpUtility.UrlDecode(imgData));
             //调用海康平台接口验证人脸照片是否合格
             string msg = SocketHelper.FaceImgIsQualified(facedata.ImgData, baseurl, Key, Signature);
             if (msg != null && !string.IsNullOrEmpty(msg))
             {
                 FaceTestingEntity ress = JsonConvert.DeserializeObject <FaceTestingEntity>(msg);
                 if (!ress.data.checkResult)
                 {
                     return(Content("false", "1"));
                 }
             }
             entity.ID      = keyValue;
             entity.Userimg = facedata.UserImg;
             entity.Imgdata = facedata.ImgData;
             new CarUserBLL().SaveFileImgForm(entity);
             return(Success("操作成功。"));
         }
     }
     catch (System.Exception er)
     {
         return(Success(er.Message));
     }
 }