using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace Site_Interface.yfCallback { /// /// 健康码通行 内部人员 访客 陌生人只需绿码即可进出 /// public class callbackHealthFJM : IHttpHandler { public void ProcessRequest(HttpContext context) { string deviceKey = ""; string responseText = "", body = ""; Model.yfCallback.BackInfo bakinfo = null; Model.yfCallback.EventInfo info = null; Model.yfCallback.EventBackInfoJKM ret = new Model.yfCallback.EventBackInfoJKM(3); try { deviceKey = HttpContext.Current.Request.QueryString["deviceKey"]; string time = HttpContext.Current.Request.QueryString["time"]; string ip = HttpContext.Current.Request.QueryString["ip"]; string strevent = HttpContext.Current.Request.QueryString["event"]; System.IO.Stream s = System.Web.HttpContext.Current.Request.InputStream; byte[] b = new byte[s.Length]; s.Read(b, 0, (int)s.Length); body = System.Text.Encoding.UTF8.GetString(b); BLL.LogManage.WriteLog11(Model.AccessLog.AllLogType.人脸识别.ToString(), String.Format("健康码开始-callbackHealthFJM-{0}:{1}" , deviceKey, body)); bakinfo = Newtonsoft.Json.JsonConvert.DeserializeObject(body); info = bakinfo.@event; Model.LTPCache mac = DAL.cache.GetCache(deviceKey); if (mac != null && info != null) { Model.yfCallback.JKM_FJM_SFZ jkmSfz = new Model.yfCallback.JKM_FJM_SFZ(); Model.yfCallback.JKM_FJM_Ret.Root retJKM = null; BLL.MachineYzList bllYz = new BLL.MachineYzList(mac, Global.interType.ToString(), Global.HRServerPhotoPath); Model.EnumJKM enuJKM = Model.EnumJKM.代表未校验这块; string EmpID = "", Gonghao = "", Kaoqinhao = "", Shenfenzheng = "", Name = ""; bool FK = false; DateTime CheckTime = DateTime.Now; string imagUrl = ""; if (info.eventType == 5)//识别事件 人证比对事件 只刷身份证 { if (info.data == null) { if (info.personId == "STRANGERBABY" || string.IsNullOrEmpty(info.personId)) { ret.displayModColor = Model.yfCallback.EnumColor.red.ToString(); ret.ttsModContent = "访客禁止通行"; ret.displayModContent = "访客禁止通行"; ret.isOpenRelay = false; bllYz.Add(Model.EnumYzType.人脸识别, CheckTime, "STRANGERBABY", "陌生人", info.temperature, ret.isOpenRelay, info.img); } else { if (Global.interType == 1) { int strEmpID = 0; DAL.cache.GetGongDiEmp(mac.DeptID, info.personId, ref strEmpID, ref Shenfenzheng, ref Name); if (strEmpID > 0) EmpID = strEmpID.ToString(); } else { BLL.EmpInfo.GetEmpByKaoqinhao(mac, info.personId, ref EmpID, ref Gonghao, ref Shenfenzheng, ref Name, ref FK); } if (!string.IsNullOrEmpty(EmpID)) { ret.name = Name; ret.idCard = Shenfenzheng; if (string.IsNullOrEmpty(Shenfenzheng)) { ret.displayModColor = Model.yfCallback.EnumColor.red.ToString(); ret.ttsModContent = "无有效身份证号码"; ret.displayModContent = "无有效身份证号码"; ret.isOpenRelay = false; } else { jkmSfz.userName = Name; jkmSfz.userIdCard = Shenfenzheng; jkmSfz.checkTemperature = info.temperature; retJKM = BLL.yfCallback.E7SM4FJM.PostSfzByCache(jkmSfz); BLL.KqJLUpload.AddJL(mac, info.personId, info.img, DateTime.Now, Global.interType.ToString(), Global.HRServerPhotoPath, info.temperature, ref imagUrl); if (retJKM != null && retJKM.Response.Data != null && retJKM.Response.Data.CheckFlag == "TX") { ret.imgBase64 = BLL.JKMImage.GetCache("lvma_1.png"); ret.displayModColor = Model.yfCallback.EnumColor.green.ToString(); ret.ttsModContent = String.Format("{0},绿码请通行", string.IsNullOrEmpty(info.temperature) ? "" : info.temperature + "度"); ret.displayModContent = String.Format("{0}绿码请通行", string.IsNullOrEmpty(info.temperature) ? "" : info.temperature + "度"); ret.isOpenRelay = true; enuJKM = Model.EnumJKM.绿码; ret.qrCodeStatus = "00"; bllYz.AddJKM(Model.EnumYzType.人脸识别, CheckTime, Shenfenzheng, Name, info.temperature, ret.isOpenRelay, info.img, enuJKM); } else { if (retJKM != null && retJKM.Response.Data != null && retJKM.Response.Data.CheckFlag != "TX") { ret.imgBase64 = BLL.JKMImage.GetCache("huangma_1.png"); ret.displayModColor = Model.yfCallback.EnumColor.red.ToString(); ret.ttsModContent = String.Format("{0},黄码禁止通行", Name); ret.displayModContent = "黄码禁止通行"; ret.imgBase64 = BLL.JKMImage.GetCache("hongma_1.png"); ret.isOpenRelay = false; enuJKM = Model.EnumJKM.黄码; ret.qrCodeStatus = "01"; } else { ret.imgBase64 = BLL.JKMImage.GetCache("hongma_1.png"); ret.displayModColor = Model.yfCallback.EnumColor.red.ToString(); ret.ttsModContent = String.Format("{0},健康码检验失败", Name); ret.displayModContent = "健康码检验失败"; ret.isOpenRelay = false; } bllYz.AddJKM(Model.EnumYzType.人脸识别, CheckTime, Shenfenzheng, Name, info.temperature, ret.isOpenRelay, info.img, enuJKM); } } } else { ret.displayModColor = Model.yfCallback.EnumColor.red.ToString(); ret.ttsModContent = "非法用户,禁止通行"; ret.displayModContent = "非法用户,禁止通行"; ret.isOpenRelay = false; bllYz.Add(Model.EnumYzType.人脸识别, CheckTime, "STRANGERBABY", "陌生人", info.temperature, ret.isOpenRelay, info.img); // BLL.LogManage.WriteLog11(Model.AccessLog.AllLogType.人脸识别.ToString(), String.Format("非法用户,禁止通行-callbackHealthFJM-{0}:{1}", deviceKey, body)); } } } else { Model.yfCallback.EventInfo_IDCardFace cardInfo = info.data; Model.EnumYzType en; if (string.IsNullOrEmpty(info.idcardNum) && string.IsNullOrEmpty(info.personId)) //只刷身份证 { en = Model.EnumYzType.刷身份证; Shenfenzheng = cardInfo.idNumber; Name = cardInfo.name; } else { en = Model.EnumYzType.人证比对; Shenfenzheng = cardInfo.idNumber; Name = cardInfo.name; } ret.name = Name; ret.idCard = Shenfenzheng; if (string.IsNullOrEmpty(cardInfo.idNumber)) //只刷身份证 { ret.displayModColor = Model.yfCallback.EnumColor.red.ToString(); ret.ttsModContent = "未读取到身份证,禁止通行"; ret.displayModContent = "禁止通行"; ret.isOpenRelay = false; bllYz.Add(Model.EnumYzType.刷身份证, CheckTime, "STRANGERBABY", "陌生人", info.temperature, ret.isOpenRelay, info.data.photoPathBase64, info.img, 0); } else if (en == Model.EnumYzType.人证比对 && info.result != 1 && cardInfo != null && !String.IsNullOrEmpty(cardInfo.idNumber)) { ret.displayModColor = Model.yfCallback.EnumColor.red.ToString(); ret.ttsModContent = "人证比对失败,禁止通行"; ret.displayModContent = "人证比对失败,禁止通行"; ret.isOpenRelay = false; bllYz.Add(Model.EnumYzType.人证比对, CheckTime, "STRANGERBABY", info.result == 2 ? "人证比对失败" : "其他", info.temperature, ret.isOpenRelay, info.data.photoPathBase64, info.img, 0); } else { jkmSfz.userName = Name; jkmSfz.userIdCard = Shenfenzheng; jkmSfz.checkTemperature = info.temperature; retJKM = BLL.yfCallback.E7SM4FJM.PostSfzByCache(jkmSfz); if (retJKM != null && retJKM.Response.Data != null && retJKM.Response.Data.CheckFlag == "TX") { ret.displayModColor = Model.yfCallback.EnumColor.green.ToString(); if (Global.interType == 1) { int strEmpID=0; DAL.cache.GetGongDiEmpByShenFenzheng(mac.DeptID, Shenfenzheng, ref strEmpID, ref Gonghao, ref Kaoqinhao, ref Name); if (strEmpID > 0) EmpID = strEmpID.ToString(); } else { BLL.EmpInfo.GetEmpByShenfenzheng(mac, cardInfo.idNumber, ref EmpID, ref Gonghao, ref Kaoqinhao, ref Name, ref FK); } if (!string.IsNullOrEmpty(EmpID)) { ret.displayModColor = Model.yfCallback.EnumColor.green.ToString(); if (EmpID != "") { BLL.KqJLUpload.AddJL(mac, int.Parse(EmpID), Shenfenzheng, Name, Kaoqinhao,en == Model.EnumYzType.刷身份证? info.data.photoPathBase64: info.img, DateTime.Now, Global.interType.ToString(), Global.HRServerPhotoPath, info.temperature, ref imagUrl); enuJKM = Model.EnumJKM.绿码; ret.ttsModContent = String.Format("{0},绿码请通行", string.IsNullOrEmpty(info.temperature) ? "" : info.temperature + "度"); ret.displayModContent = String.Format("{0}绿码请通行", string.IsNullOrEmpty(info.temperature) ? "" : info.temperature + "度"); ret.isOpenRelay = true; ret.imgBase64 = BLL.JKMImage.GetCache("lvma_1.png"); } else { enuJKM = Model.EnumJKM.绿码; ret.ttsModContent = String.Format("{0},绿码请通行", string.IsNullOrEmpty(info.temperature) ? "" : info.temperature + "度"); ret.displayModContent = String.Format("{0}绿码请通行", string.IsNullOrEmpty(info.temperature) ? "" : info.temperature + "度"); ret.isOpenRelay = true; ret.imgBase64 = BLL.JKMImage.GetCache("lvma_1.png"); } } else { enuJKM = Model.EnumJKM.绿码; ret.ttsModContent = String.Format("{0},绿码请通行", string.IsNullOrEmpty(info.temperature) ? "" : info.temperature + "度"); ret.displayModContent = String.Format("{0}绿码请通行", string.IsNullOrEmpty(info.temperature) ? "" : info.temperature + "度"); ret.isOpenRelay = true; ret.imgBase64 = BLL.JKMImage.GetCache("lvma_1.png"); } ret.qrCodeStatus = "00"; } else { if (retJKM != null && retJKM.Response.Data != null && retJKM.Response.Data.CheckFlag != "TX") { ret.displayModColor = Model.yfCallback.EnumColor.yellow.ToString(); ret.ttsModContent = String.Format("{0},黄码禁止通行", cardInfo.name); ret.displayModContent = "黄码禁止通行"; ret.imgBase64 = BLL.JKMImage.GetCache("hongma_1.png"); ret.isOpenRelay = false; enuJKM = Model.EnumJKM.黄码; ret.qrCodeStatus = "01"; } else { ret.displayModColor = Model.yfCallback.EnumColor.red.ToString(); ret.ttsModContent = String.Format("{0},健康码检验失败", cardInfo.name); ret.displayModContent = "健康码检验失败"; ret.isOpenRelay = false; } } if (en == Model.EnumYzType.刷身份证) { bllYz.AddJKM(en, CheckTime, cardInfo.idNumber, cardInfo.name, info.temperature, ret.isOpenRelay, info.data.photoPathBase64, enuJKM); } else { bllYz.AddJKM(en, CheckTime, cardInfo.idNumber, cardInfo.name, info.temperature, ret.isOpenRelay, info.data.photoPathBase64, info.img, ret.isOpenRelay ? 1 : 0, enuJKM); } } } } } else { ret.displayModColor = Model.yfCallback.EnumColor.red.ToString(); ret.ttsModContent = String.Format("设备未授权"); ret.displayModContent = "设备未授权"; ret.isOpenRelay = false; } if (!string.IsNullOrEmpty(ret.idCard) && ret.idCard.Length >= 15) { ret.idCard = DBUtility.Util.ReplaceWithSpecialChar(ret.idCard, 3, 3, "x"); } if (!string.IsNullOrEmpty(ret.name) && ret.name != "陌生人") { ret.name = DBUtility.Util.ReplaceWithSpecialChar(ret.name, 1, 0, "x"); } } catch (Exception ex) { ret.displayModColor = Model.yfCallback.EnumColor.red.ToString(); ret.ttsModContent = "验证异常"; ret.displayModContent = "验证异常"; ret.isOpenRelay = false; BLL.LogManage.WriteLog11(Model.AccessLog.AllLogType.人脸识别.ToString(), ex.Message+ex.StackTrace); } finally { #region 支持跨域请求 responseText = Newtonsoft.Json.JsonConvert.SerializeObject(ret); BLL.LogManage.WriteLog11(Model.AccessLog.AllLogType.人脸识别.ToString(), String.Format("健康码-callbackHealthFJM-{0}:{1}", deviceKey , responseText)); context.Response.Clear(); context.Response.ClearHeaders(); string origin = context.Request.Headers["Origin"]; context.Response.AppendHeader("Access-Control-Allow-Origin", string.IsNullOrEmpty(origin) ? "*" : origin); string requestHeaders = context.Request.Headers["Access-Control-Request-Headers"]; context.Response.AppendHeader("Access-Control-Allow-Headers", string.IsNullOrEmpty(requestHeaders) ? "*" : requestHeaders); context.Response.AppendHeader("Access-Control-Allow-Methods", "POST, OPTIONS"); #endregion context.Response.Clear(); context.Response.Write(responseText); context.Response.End(); } } public bool IsReusable { get { return false; } } } }