diff --git a/CPF_Cef/Common/Log.cs b/CPF_Cef/Common/Log.cs index 923591c..7c0b1b9 100644 --- a/CPF_Cef/Common/Log.cs +++ b/CPF_Cef/Common/Log.cs @@ -68,13 +68,10 @@ namespace AKSWebBrowser.Commen { try { streamWriter = !File.Exists(directPath) ? File.CreateText(directPath) : File.AppendText(directPath); } catch { } finally { } } - else - { - streamWriter.WriteLine("***********************************************************************"); - streamWriter.WriteLine(DateTime.Now.ToString("HH:mm:ss")); - streamWriter.WriteLine("输出信息:信息"); - streamWriter.WriteLine("信息:\r\n" + message); - } + streamWriter.WriteLine("***********************************************************************"); + streamWriter.WriteLine(DateTime.Now.ToString("HH:mm:ss")); + streamWriter.WriteLine("输出信息:信息"); + streamWriter.WriteLine("信息:\r\n" + message); } catch { } finally diff --git a/CPF_Cef/Devices/IDCard.cs b/CPF_Cef/Devices/IDCard.cs index d4d4021..c5d1da2 100644 --- a/CPF_Cef/Devices/IDCard.cs +++ b/CPF_Cef/Devices/IDCard.cs @@ -59,30 +59,48 @@ namespace AksWebBrowser.Devices { string txt = Encoding.UTF8.GetString(FileName); iDCardModel.ImageBase64 = "data:image/jpg;base64," + txt.Substring(0, (txt.IndexOf("=") + 1)); + //开启人脸比对 + string stat = LhtCF.LhtCFFace(code, txt); + if (stat == "0") + { + byte[] sCHMsg = new byte[520]; + int itype = 0; + status = LibClass.ParseIDCardInfo(CHMsg, cLen, ref itype, sCHMsg); + if (status == 0) + { + string[] baseinfo = Encoding.UTF8.GetString(sCHMsg).Split("|"); + iDCardModel.Name = baseinfo[0]; + iDCardModel.Sex = baseinfo[1]; + iDCardModel.Nation = baseinfo[2]; + iDCardModel.BirthDay = baseinfo[3]; + iDCardModel.Addr = baseinfo[4]; + iDCardModel.Id = baseinfo[5]; + iDCardModel.Regorg = baseinfo[6]; + iDCardModel.StartDate = baseinfo[7]; + iDCardModel.EndDate = baseinfo[8]; + } + var OBJ = new + { + Data = iDCardModel + }; + //关闭 + LibClass.ICReaderClose(icdev); + return "{\"keycode\":\"" + code + "\",\"message\":\"seccse\",\"code\":\"200\",\"status\":true,\"data\":" + JsonConvert.SerializeObject(OBJ) + "}"; + } + else + { + //关闭 + LibClass.ICReaderClose(icdev); + return "{\"keycode\":\"" + code + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "身份证不是同一人" + "\"}"; + + } } - byte[] sCHMsg = new byte[520]; - int itype = 0; - status = LibClass.ParseIDCardInfo(CHMsg, cLen, ref itype, sCHMsg); - if (status == 0) + else { - string[] baseinfo = Encoding.UTF8.GetString(sCHMsg).Split("|"); - iDCardModel.Name = baseinfo[0]; - iDCardModel.Sex = baseinfo[1]; - iDCardModel.Nation = baseinfo[2]; - iDCardModel.BirthDay = baseinfo[3]; - iDCardModel.Addr = baseinfo[4]; - iDCardModel.Id = baseinfo[5]; - iDCardModel.Regorg = baseinfo[6]; - iDCardModel.StartDate = baseinfo[7]; - iDCardModel.EndDate = baseinfo[8]; + //关闭 + LibClass.ICReaderClose(icdev); + return "{\"keycode\":\"" + code + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "读取身份证失败" + "\"}"; } - var OBJ = new - { - Data = iDCardModel - }; - //关闭 - LibClass.ICReaderClose(icdev); - return "{\"keycode\":\"" + code + "\",\"message\":\"seccse\",\"code\":\"200\",\"status\":true,\"data\":" + JsonConvert.SerializeObject(OBJ) + "}"; } else { @@ -100,7 +118,7 @@ namespace AksWebBrowser.Devices } catch (Exception ex) { - // Log.Info("获取身份证异常:" + ex.Message); + // Log.Info("获取身份证异常:" + ex.Message); if (icdev != -1) { LibClass.ICReaderClose(icdev); diff --git a/CPF_Cef/Devices/LhtCF.cs b/CPF_Cef/Devices/LhtCF.cs index a1ef7db..ee28fd3 100644 --- a/CPF_Cef/Devices/LhtCF.cs +++ b/CPF_Cef/Devices/LhtCF.cs @@ -1,8 +1,11 @@ using AKSWebBrowser.Commen; +using CPF.Linux; +using CPF.Mac.CoreGraphics; using CPF.Windows; using System; using System.Collections.Generic; using System.Globalization; +using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Text; @@ -12,6 +15,7 @@ namespace AksWebBrowser.Devices { public class LhtCF { + public static string face = string.Empty; public LhtCF() { } /// @@ -19,56 +23,67 @@ namespace AksWebBrowser.Devices /// /// /// - public static string LhtCFFace(string code,string face) + public static string LhtCFFace(string code, string _face) { - string result = string.Empty; + int status = -1; try { - int status = libLhtCFs.CF_Init(); - // Log.Info("初始化函数" + status); + face = _face; + status = libLhtCFs.CF_Init(); if (status == 0) { - status = libLhtCFs.CF_GetCameraStatus(0); - // Log.Info("获取摄像头状态" + status); + status = libLhtCFs.CF_OpenCamera(); if (status == 0) { - status = libLhtCFs.CF_OpenCamera(); - // Log.Info("打开摄像头" + status); + status = libLhtCFs.CF_CreatWindow(0, 0, 300, 800, 600, 500); if (status == 0) { - status = libLhtCFs.CF_CreatWindow(0, 0, 300, 800, 600, 500); - // Log.Info("创建视频预览窗口" + status); + status = libLhtCFs.CF_StartLiveDetectEx(10000); if (status == 0) { - status = libLhtCFs.CF_StartLiveDetectEx(10000); - // Log.Info("活体检测超时时间:" + status); - if (status == 0) + //status = libLhtCFs.SetCamADataCallbackEx(GetMjpegStream); + //Log.Info("设置回调:" + status); + + string time = DateTime.Now.ToString("yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo); + string dirpath = System.IO.Directory.GetCurrentDirectory(); + string[] array = dirpath.Split("/"); + var groupCount = array.GroupBy(x => x).Select(group => new { Element = group.Key, Count = group.Count() }).Where(x => x.Count > 0); + if (groupCount.Count() == 1) { - string time = DateTime.Now.ToString("yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo); - var tmpFile = "/tmp/" + time + ".jpg"; - byte[] faceA = Convert.FromBase64String(face); - byte[] faceB = Encoding.UTF8.GetBytes(tmpFile); - status = libLhtCFs.CF_FaceCompare(faceA, faceB, 60); - // Log.Info("人脸比对:" + status); - - //停止活体检测 - Task.Run(() => { libLhtCFs.CF_StopLiveDetect(); }); + dirpath = dirpath + "/aks"; } - //关闭视频预览窗口 - Task.Run(() => { libLhtCFs.CF_CloseWindow(0); }); + else if (groupCount.Count() == 0) + { + dirpath = dirpath + "/aks/aks"; + } + dirpath = dirpath + @"/wwwroot/Face"; + if (!Directory.Exists(dirpath)) + { + Directory.CreateDirectory(dirpath); + } + Log.Info(dirpath); + var tempFile = dirpath + "/" + time + ".jpg"; + Log.Info("人脸路径:" + tempFile); + status = libLhtCFs.CF_GetImage(0, Encoding.Default.GetBytes(tempFile)); + Log.Info("获取人脸:" + status); } - //关闭摄像头 - Task.Run(() => { libLhtCFs.CF_CloseCamera(); }); + //关闭视频预览窗口 + Task.Run(() => { libLhtCFs.CF_CloseWindow(0); }); } + //关闭摄像头 + Task.Run(() => { libLhtCFs.CF_CloseCamera(); }); } } - } catch (Exception ex) { - //Log.Error("双目摄像头采集人脸异常:" + ex.Message); + //关闭视频预览窗口 + Task.Run(() => { libLhtCFs.CF_CloseWindow(0); }); + //关闭摄像头 + Task.Run(() => { libLhtCFs.CF_CloseCamera(); }); + Log.Info("双目摄像头采集人脸异常:" + ex.Message); } - return ""; + return status.ToString(); } } @@ -80,11 +95,11 @@ namespace AksWebBrowser.Devices //RGB数据回调函数定义 [System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.Cdecl)] - public delegate void GetVideoStream([MarshalAs(UnmanagedType.LPArray)] byte[] rgbData, int width, int height); + public delegate void GetVideoStream(byte[] rgbData, int width, int height); //mjpeg数据回调函数定义 [System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.Cdecl)] - public delegate void GetMjpegStream([MarshalAs(UnmanagedType.LPArray)] byte[] mjpegData, int dataLen); + public delegate void GetMjpegStream(byte[] mjpegData, int dataLen); //初始化 [DllImport("libLhtCF", EntryPoint = "CF_Init", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] @@ -143,12 +158,12 @@ namespace AksWebBrowser.Devices public static extern int CF_StopLiveDetect(); //获取采集图像 - [DllImport("libLhtCF", EntryPoint = "CF_GetImage", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] - public static extern int CF_GetImage(int nImageType, [MarshalAs(UnmanagedType.LPArray)] byte[] FilePath); + [DllImport("libLhtCF", CallingConvention = CallingConvention.Cdecl)] + public extern static int CF_GetImage(int nImageType, byte[] FilePath); //人脸比对 - [DllImport("libLhtCF", EntryPoint = "CF_GetImage", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] - public static extern int CF_FaceCompare(byte[] picPathA, byte[] picPathB, int score); + [DllImport("LhtCF.dll", CallingConvention = CallingConvention.Cdecl)] + public extern static int CF_FaceCompare(byte[] picPathA, byte[] picPathB, ref int score); //创建视频预览窗口 [DllImport("libLhtCF", EntryPoint = "CF_CreatWindow", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] diff --git a/CPF_Cef/MainModel.cs b/CPF_Cef/MainModel.cs index 501e278..d123480 100644 --- a/CPF_Cef/MainModel.cs +++ b/CPF_Cef/MainModel.cs @@ -137,7 +137,8 @@ namespace AKS.EnterpriseLibrary.WebBrowser break; } } - else { + else + { result = "{\"keycode\":\"" + "hert" + "\",\"message\":\"seccse\",\"code\":\"400\",\"status\":true,\"data\":\"参数解析错误\"}"; } } @@ -664,6 +665,16 @@ namespace AKS.EnterpriseLibrary.WebBrowser string time = DateTime.Now.ToString( "yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo); string dirpath = System.IO.Directory.GetCurrentDirectory(); + string[] array = dirpath.Split("/"); + var groupCount = array.GroupBy(x => x).Select(group => new { Element = group.Key, Count = group.Count() }).Where(x => x.Count > 0); + if (groupCount.Count() == 1) + { + dirpath = dirpath + "/aks"; + } + else if (groupCount.Count() == 0) + { + dirpath = dirpath + "/aks/aks"; + } dirpath = dirpath + @"/wwwroot/PrintFile"; if (!Directory.Exists(dirpath)) { @@ -724,6 +735,16 @@ namespace AKS.EnterpriseLibrary.WebBrowser string time = DateTime.Now.ToString( "yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo); string dirpath = System.IO.Directory.GetCurrentDirectory(); + string[] array = dirpath.Split("/"); + var groupCount = array.GroupBy(x => x).Select(group => new { Element = group.Key, Count = group.Count() }).Where(x => x.Count > 0); + if (groupCount.Count() == 1) + { + dirpath = dirpath + "/aks"; + } + else if (groupCount.Count() == 0) + { + dirpath = dirpath + "/aks/aks"; + } dirpath = dirpath + @"/wwwroot/PrintFile"; if (!Directory.Exists(dirpath)) { @@ -812,6 +833,16 @@ namespace AKS.EnterpriseLibrary.WebBrowser string time = DateTime.Now.ToString( "yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo); string dirpath = System.IO.Directory.GetCurrentDirectory(); + string[] array = dirpath.Split("/"); + var groupCount = array.GroupBy(x => x).Select(group => new { Element = group.Key, Count = group.Count() }).Where(x => x.Count > 0); + if (groupCount.Count() == 1) + { + dirpath = dirpath + "/aks"; + } + else if (groupCount.Count() == 0) + { + dirpath = dirpath + "/aks/aks"; + } dirpath = dirpath + @"/wwwroot/WaveOutFile"; if (!Directory.Exists(dirpath)) { @@ -1258,6 +1289,16 @@ namespace AKS.EnterpriseLibrary.WebBrowser string time = DateTime.Now.ToString( "yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo); string dirpath = System.IO.Directory.GetCurrentDirectory(); + string[] array = dirpath.Split("/"); + var groupCount = array.GroupBy(x => x).Select(group => new { Element = group.Key, Count = group.Count() }).Where(x => x.Count > 0); + if (groupCount.Count() == 1) + { + dirpath = dirpath + "/aks"; + } + else if (groupCount.Count() == 0) + { + dirpath = dirpath + "/aks/aks"; + } dirpath = dirpath + @"/wwwroot/Record"; if (!Directory.Exists(dirpath)) { @@ -1354,6 +1395,16 @@ namespace AKS.EnterpriseLibrary.WebBrowser string time = DateTime.Now.ToString( "yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo); string dirpath = System.IO.Directory.GetCurrentDirectory(); + string[] array = dirpath.Split("/"); + var groupCount = array.GroupBy(x => x).Select(group => new { Element = group.Key, Count = group.Count() }).Where(x => x.Count > 0); + if (groupCount.Count() == 1) + { + dirpath = dirpath + "/aks"; + } + else if (groupCount.Count() == 0) + { + dirpath = dirpath + "/aks/aks"; + } dirpath = dirpath + @"/wwwroot/WavFile"; // Log.Info(dirpath); if (!Directory.Exists(dirpath))