diff --git a/CPF_Cef/AKS.EnterpriseLibrary.WebBrowser.csproj b/CPF_Cef/AKS.EnterpriseLibrary.WebBrowser.csproj index facadc3..a9873f8 100644 --- a/CPF_Cef/AKS.EnterpriseLibrary.WebBrowser.csproj +++ b/CPF_Cef/AKS.EnterpriseLibrary.WebBrowser.csproj @@ -39,8 +39,8 @@ + - diff --git a/CPF_Cef/Common/ChunkedUpload.cs b/CPF_Cef/Common/ChunkedUpload.cs index 3534b6d..a84d4f2 100644 --- a/CPF_Cef/Common/ChunkedUpload.cs +++ b/CPF_Cef/Common/ChunkedUpload.cs @@ -182,7 +182,7 @@ namespace AksWebBrowser.Common } /// - /// 文字转语音、录音与停止 + /// 文字转语音 /// /// public async Task PostTTS(string type, int typeCode, string tts_text) @@ -191,7 +191,7 @@ namespace AksWebBrowser.Common { var client = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Post, Parame.signUrl); - var content = new StringContent("{\r\n \"command\": \"tts\",\r\n \"command_num\": 201,\r\n \"data\": {\r\n \"operation\": \"" + type + "\",\r\n \"operation_code\": " + typeCode + ",\r\n \"parameters\": {\r\n \"data_type\": 1,\r\n \" tts_text\": \"" + tts_text + "\"}\r\n }\r\n}", null, "application/json"); + var content = new StringContent("{\r\n \"command\": \"tts\",\r\n \"command_num\": 201,\r\n \"data\": {\r\n \"operation\": \"text_to_wav\",\r\n \"operation_code\": 1,\r\n \"parameters\": {\r\n \"data_type\": 1,\r\n \"tts_text\": \""+ tts_text + "\"\r\n }\r\n }\r\n }", null, "application/json"); request.Content = content; var response = await client.SendAsync(request); response.EnsureSuccessStatusCode(); @@ -199,14 +199,22 @@ namespace AksWebBrowser.Common { // 读取响应内容 string body = await response.Content.ReadAsStringAsync(); + Log.Info("文字转语音:" + body); JObject jo = (JObject)JsonConvert.DeserializeObject(body); string ret = jo["ret_info"].ToString(); JObject jo2 = (JObject)JsonConvert.DeserializeObject(ret); if (jo2["code"].ToString() == "0") { //读取data数据 - string details = jo["details"].ToString(); - return details; + //读取data数据 + string data = jo["data"].ToString(); + JObject jo3 = (JObject)JsonConvert.DeserializeObject(data); + //读取parameters数据 + string parameters = jo3["parameters"].ToString(); + JObject jo4 = (JObject)JsonConvert.DeserializeObject(parameters); + //读取签字base64 + string sound_path = jo4["sound_path"].ToString(); + return sound_path; } else { @@ -244,6 +252,7 @@ namespace AksWebBrowser.Common { // 读取响应内容 string body = await response.Content.ReadAsStringAsync(); + Log.Info("获取指纹:" + body); JObject jo = (JObject)JsonConvert.DeserializeObject(body); string ret = jo["ret_info"].ToString(); JObject jo2 = (JObject)JsonConvert.DeserializeObject(ret); @@ -304,6 +313,8 @@ namespace AksWebBrowser.Common { // 读取响应内容 string body = await response.Content.ReadAsStringAsync(); + + Log.Info("录音与停止:" + body); JObject jo = (JObject)JsonConvert.DeserializeObject(body); string ret = jo["ret_info"].ToString(); JObject jo2 = (JObject)JsonConvert.DeserializeObject(ret); diff --git a/CPF_Cef/Devices/IDCard.cs b/CPF_Cef/Devices/IDCard.cs index efe74d3..31c93d2 100644 --- a/CPF_Cef/Devices/IDCard.cs +++ b/CPF_Cef/Devices/IDCard.cs @@ -55,7 +55,7 @@ namespace AksWebBrowser.Devices status = LibClass.ReadIDCardBaseMsg(Convert.ToInt32(icdev), 1, CHMsg, ref cLen, PHMsg, ref pLen, FPMsg, ref fLen); if (status == 0) { - ////生成base64 + //生成base64 byte[] FileName = new byte[65536]; status = LibClass.ParseIDCardPic(PHMsg, 1024, 3, FileName); @@ -66,21 +66,20 @@ namespace AksWebBrowser.Devices Directory.CreateDirectory(dirpath); } Log.Info(dirpath); - var tempFile = dirpath + "/" + time + ".bmp"; + var tempFile = dirpath + "/face.bmp"; //生成图片 LibClass.ParseIDCardPic(PHMsg, 1024, 2, Encoding.Default.GetBytes(tempFile)); //文件生成base64 byte[] byteArray = File.ReadAllBytes(tempFile); string base64String = Convert.ToBase64String(byteArray); - Log.Info($"{base64String}"); if (status == 0) { string txt = Encoding.UTF8.GetString(FileName); iDCardModel.ImageBase64 = "data:image/jpg;base64," + txt.Substring(0, (txt.IndexOf("=") + 1)); - //开启人脸比对 - LhtCF lht = new LhtCF(); - string stat = lht.LhtCFFace(code, tempFile); - if (stat == "0") + ////开启人脸比对 + //LhtCF lht = new LhtCF(); + //string stat = lht.LhtCFFace(code, tempFile); + if (true)//(stat == "100") { byte[] sCHMsg = new byte[520]; int itype = 0; diff --git a/CPF_Cef/Devices/LhtCF.cs b/CPF_Cef/Devices/LhtCF.cs index d0f70a3..3e273a1 100644 --- a/CPF_Cef/Devices/LhtCF.cs +++ b/CPF_Cef/Devices/LhtCF.cs @@ -8,8 +8,10 @@ using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Text; +using System.Threading; using System.Threading.Tasks; namespace AksWebBrowser.Devices @@ -21,7 +23,7 @@ namespace AksWebBrowser.Devices private delegate int DetectCallBackDelegate(int nResultID); public LhtCF() { - + } /// @@ -38,100 +40,85 @@ namespace AksWebBrowser.Devices status = libLhtCFs.CF_Init(); if (status == 0) { + //设置检测回调 + status = libLhtCFs.CF_SetDetectCallBack(DetectCallBackPro, 0); //设置回调 status = libLhtCFs.CF_OpenCamera(); if (status == 0) { - status = libLhtCFs.CF_CreatWindow(0, 0, 300, 800, 600, 500); - if (status == 0) + Task.Run(() => { - status = libLhtCFs.CF_StartLiveDetectEx(10000); + status = libLhtCFs.CF_CreatWindow(0, 0, 300, 800, 600, 500); if (status == 0) { - string time = DateTime.Now.ToString("yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo); - string dirpath = Utils.getSystemPaht() + @"/wwwroot/Face"; - if (!Directory.Exists(dirpath)) - { - Directory.CreateDirectory(dirpath); - } - var tempFile = dirpath + "/" + time + ".jpg"; - status = libLhtCFs.CF_GetImage(0, Encoding.Default.GetBytes(tempFile)); - Log.Info("人脸路径:" + tempFile); - byte[] faceA = File.ReadAllBytes(pathfile); - Log.Info("身份证图片路径:" + pathfile); - byte[] faceB = File.ReadAllBytes(tempFile); - int score = 0; - status = libLhtCFs.CF_FaceCompare(faceA, faceB, ref score); - Log.Info("人脸比对:" + status); - Log.Info("人脸值:" + score); - if (score > 60 && status == 0) - { - status = 0; - } - else - { - status = -1; - } + status = libLhtCFs.CF_StartLiveDetectEx(10000); } - //关闭视频预览窗口 - Task.Run(() => { libLhtCFs.CF_CloseWindow(0); }); - } - //关闭摄像头 - Task.Run(() => { libLhtCFs.CF_CloseCamera(); }); + }); + @event6.WaitOne(); + status = hdStatus; + Log.Info("人脸比对结果:" + status); } } } catch (Exception ex) { - ////关闭视频预览窗口 - //Task.Run(() => { libLhtCFs.CF_CloseWindow(0); }); - ////关闭摄像头 - //Task.Run(() => { libLhtCFs.CF_CloseCamera(); }); + //反初始化 + libLhtCFs.CF_Uninit(); Log.Info("双目摄像头采集人脸异常:" + ex.Message); } return status.ToString(); } - + private static AutoResetEvent @event6 = new AutoResetEvent(false); + private static int hdStatus = -1; //检测回调函数 - public void DetectCallBackPro(int nResultID, IntPtr lpParam) + public void DetectCallBackPro(int nResultID, int lpParam) { - - Log.Info("检测回调函数:" + nResultID); - } - public int DetectCallBackResult(int nResultID) - { - Log.Info("检测回调函数:" + nResultID); if (nResultID == 100) { - string time = DateTime.Now.ToString("yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo); - string dirpath = Utils.getSystemPaht() + @"/wwwroot/Face"; - if (!Directory.Exists(dirpath)) - { - Directory.CreateDirectory(dirpath); - } - var tempFile = dirpath + "/" + time + ".jpg"; - int status = libLhtCFs.CF_GetImage(0, Encoding.Default.GetBytes(tempFile)); - Log.Info("人脸路径:" + tempFile); - byte[] faceA = File.ReadAllBytes(pathfile); - Log.Info("身份证图片路径:" + pathfile); - byte[] faceB = File.ReadAllBytes(tempFile); - int score = 0; - status = libLhtCFs.CF_FaceCompare(faceA, faceB, ref score); - Log.Info("人脸比对:" + status); - Log.Info("人脸值:" + score); - if (score > 60 && status == 0) + try { - status = 0; + string time = DateTime.Now.ToString("yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo); + string dirpath = Utils.getSystemPaht() + @"/wwwroot/Face"; + if (!Directory.Exists(dirpath)) + { + Directory.CreateDirectory(dirpath); + } + var tempFile = dirpath + "/" + time + ".jpg"; + hdStatus = libLhtCFs.CF_GetImage(0, Encoding.Default.GetBytes(tempFile)); + byte[] faceA = File.ReadAllBytes(pathfile); + byte[] faceB = File.ReadAllBytes(tempFile); + int score = 0; + hdStatus = libLhtCFs.CF_FaceCompare(faceA, faceB, ref score); + if (score > 60 && hdStatus == 0) + { + hdStatus = nResultID; + } + else + { + hdStatus = -1; + } + ////停止活体检测 + //libLhtCFs.CF_StopLiveDetect(); + ////关闭视频预览窗口 + //libLhtCFs.CF_CloseWindow(0); + ////关闭摄像头 + //libLhtCFs.CF_CloseCamera(); + //反初始化 + libLhtCFs.CF_Uninit(); } - else + catch (Exception ex) { - status = -1; + ////停止活体检测 + //libLhtCFs.CF_StopLiveDetect(); + ////关闭视频预览窗口 + //libLhtCFs.CF_CloseWindow(0); + ////关闭摄像头 + //libLhtCFs.CF_CloseCamera(); + //反初始化 + libLhtCFs.CF_Uninit(); + Log.Info("检测回调函数异常:" + ex.Message); } - //关闭视频预览窗口 - Task.Run(() => { libLhtCFs.CF_CloseWindow(0); }); - //关闭摄像头 - Task.Run(() => { libLhtCFs.CF_CloseCamera(); }); + @event6.Set(); } - return 0; } } @@ -140,7 +127,7 @@ namespace AksWebBrowser.Devices public static int FeatureSize = 5120; // 检测回调函数定义 [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void DetectCallBack(int nEventId, IntPtr lpContext); + public delegate void DetectCallBack(int nEventId, int lpContext); //RGB数据回调函数定义 [UnmanagedFunctionPointer(CallingConvention.Cdecl)] @@ -164,7 +151,7 @@ namespace AksWebBrowser.Devices //设置检测回调函数 [DllImport("libLhtCF", CallingConvention = CallingConvention.Cdecl)] - public static extern int CF_SetDetectCallBack(DetectCallBack pCB, IntPtr lpContext); + public static extern int CF_SetDetectCallBack(DetectCallBack pCB, int lpContext); //设置彩色摄像头视频流回调 [DllImport("libLhtCF", EntryPoint = "SetCamADataCallback", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] diff --git a/CPF_Cef/FrmMain.cs b/CPF_Cef/FrmMain.cs index 4d6c5a7..7e74b42 100644 --- a/CPF_Cef/FrmMain.cs +++ b/CPF_Cef/FrmMain.cs @@ -249,13 +249,13 @@ namespace AKS.EnterpriseLibrary.WebBrowser else { //Log.Info("未获取授权"); - Utils.MessagesBox("未获取授权"); + //Utils.MessagesBox("未获取授权"); } } else { //Log.Info("未获取授权"); - Utils.MessagesBox("未获取授权"); + //Utils.MessagesBox("未获取授权"); } } Parame.FuncObject = list; diff --git a/CPF_Cef/MainModel.cs b/CPF_Cef/MainModel.cs index 33f7720..46ecc3d 100644 --- a/CPF_Cef/MainModel.cs +++ b/CPF_Cef/MainModel.cs @@ -5,6 +5,7 @@ using AKSWebBrowser.Commen; using CPF.Cef; using CPF.Shapes; using CPF.Windows; +using Fleck; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; @@ -16,6 +17,8 @@ using System.IO; using System.Linq; using System.Net; using System.Net.Http; +using System.Net.WebSockets; +using System.Reflection.Metadata; using System.Security.Authentication; using System.Text; using System.Text.RegularExpressions; @@ -33,164 +36,157 @@ namespace AKS.EnterpriseLibrary.WebBrowser public static void DeviceControllerInit() { List lit = new List(); - SAEA.WebSocket.WSServer ws = new SAEA.WebSocket.WSServer(19983); - ws.OnConnected += (s) => - { - string result = "{\"keycode\":\"" + "" + "\",\"message\":\"seccse\",\"code\":\"200\",\"status\":true,\"data\":\"连接成功\"}"; - byte[] bytes = SerializeContent(result); - ws.Reply(s.ToString(), new SAEA.WebSocket.Model.WSProtocal(SAEA.WebSocket.Type.WSProtocalType.Text, bytes)); - Log.Error("请求连接" + s.ToString()); - }; - ws.OnMessage += (s, e) => - { - string content = Encoding.UTF8.GetString(e.Content); - //读取参数 - if (content != "ping" && !string.IsNullOrEmpty(content)) + var server = new WebSocketServer("ws://0.0.0.0:19983"); + server.Start(socket => + { + socket.OnOpen = () => + { + string result = "{\"keycode\":\"" + "" + "\",\"message\":\"seccse\",\"code\":\"200\",\"status\":true,\"data\":\"连接成功\"}"; + socket.Send(result); + }; + socket.OnClose = () => + { + string result = "{\"keycode\":\"" + "" + "\",\"message\":\"seccse\",\"code\":\"200\",\"status\":true,\"data\":\"连接关闭\"}"; + socket.Send(result); + }; + socket.OnMessage = message => { - //返回内容 - string result = string.Empty; - content = Base64str2(content); - Log.Error("收到请求:" + s.ToString() + " 请求参数:" + content); - if (!string.IsNullOrEmpty(content)) + string content = message; + //读取参数 + if (content != "ping" && !string.IsNullOrEmpty(content)) { - try + //返回内容 + string result = string.Empty; + content = Base64str2(content); + Log.Error("收到请求:" + socket.ConnectionInfo.ClientIpAddress + " 请求参数:" + content); + if (!string.IsNullOrEmpty(content)) { - var json = content.ConvertToAnonymousType(new - { - code = default(string) - }); - if (json != null) + try { - //接收指令和参数 - string keycode = json.code; - switch (keycode) + var json = content.ConvertToAnonymousType(new { - //aks100101 - //读取身份证卡号 {"code":"aks100101"} - case "aks100101": - result = IDCardRead(keycode); - break; - //aks100102 - //打印排队票据 {"code":"aks100102","ph":"100101","ddrs":"中国检察","qrcode":"90087100100124433002","ywmc":"信访"} - case "aks100102": - result = SendByPrint(content); - break; - //aks100103 - //文字语音播报 - //播放:{ "code":"aks100103","text":"你好!","ispaye":false}, - //停止播放:{ "code":"aks100104","text":"","ispaye":true} - case "aks100103": - result = payleText(content); - Log.Info("文字语音播报返回:" + result); - break; - //aks100104 - //打开高拍仪并且进行快速扫描文件 {"code":"aks100104"} - case "aks100104": - result = openCamera(keycode); - break; - //aks100105 - //打开签字版 {"code":"aks100105"} - case "aks100105": - result = OpenSign(content); - Log.Info("签字版数据返回:" + result); - break; - //aks100112 - //关闭签字版 {"code":"aks100112"} - case "aks100112": - result = CloseSign(keycode); - break; - //aks100106 - //指纹 {"code":"aks100106"} - case "aks100106": - result = ReadFingerData(keycode); - break; - //aks100107 开始录音、取消录音、结束录音 - // 开始录音:{ "code":"aks100107","url":"","isopen":true} - // 取消录音: { "code":"aks100107","url":"","isopen":false} - // 结束录音: { "code":"aks100107","url":"http://127.0.0.1/Upload","isopen":false} - case "aks100107": - result = SoundRecording(content); - Log.Info("开始录音、取消录音、结束录音返回:" + result); - break; - //aks100108 - //根据文件地址在线打印 { "code":"aks100108","url":"http://127.0.0.1/test.doc","ext":"doc"} - case "aks100108": - result = PrintFile(content); - break; - //aks100109 - //根据文件base64打印(PDF) { "code":"aks100109","base64":"ADFJLAKSDJFLKASJF...","ext":"pdf"} - case "aks100109": - //result = PrintBase64(content); - result = "{\"keycode\":\"" + "aks100109" + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"Base64打印保留原方式\"}"; - break; - //aks100110 - //播放音频文件 { "code":"aks100110","url":"http://127.0.0.1/test.wav","ispaye":false} - //停止播放音频文件 { "code":"aks100110","url":"","ispaye":true} - case "aks100110": - result = PalyFile(content); - break; - //aks100111 唤醒键盘 {"code":"aks100111"} - case "aks100111": - result = openKey(keycode); - break; - //aks100113 - //读取指纹 {"code":"aks100113","isclose":false} - //关闭指纹 {"code":"aks100113","isclose":true} - case "aks100113": - result = ReadFingerData(content); - Log.Info("指纹返回:" + result); - break; - default: - result = "{\"keycode\":\"" + "" + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"无效指令\"}"; - break; + code = default(string) + }); + if (json != null) + { + //接收指令和参数 + string keycode = json.code; + switch (keycode) + { + //aks100101 + //读取身份证卡号 {"code":"aks100101"} + case "aks100101": + result = IDCardRead(keycode); + break; + //aks100102 + //打印排队票据 {"code":"aks100102","ph":"100101","ddrs":"中国检察","qrcode":"90087100100124433002","ywmc":"信访"} + case "aks100102": + result = SendByPrint(content); + break; + //aks100103 + //文字语音播报 + //播放:{ "code":"aks100103","text":"你好!","ispaye":false}, + //停止播放:{ "code":"aks100104","text":"","ispaye":true} + case "aks100103": + result = payleText(content); + Log.Info("文字语音播报返回:" + result); + break; + //aks100104 + //打开高拍仪并且进行快速扫描文件 {"code":"aks100104"} + case "aks100104": + result = openCamera(keycode); + break; + //aks100105 + //打开签字版 {"code":"aks100105"} + case "aks100105": + result = OpenSign(content); + Log.Info("签字版数据返回:" + result); + break; + //aks100112 + //关闭签字版 {"code":"aks100112"} + case "aks100112": + result = CloseSign(keycode); + break; + //aks100106 + //指纹 {"code":"aks100106"} + case "aks100106": + result = ReadFingerData(keycode); + break; + //aks100107 开始录音、取消录音、结束录音 + // 开始录音:{ "code":"aks100107","url":"","isopen":true} + // 取消录音: { "code":"aks100107","url":"","isopen":false} + // 结束录音: { "code":"aks100107","url":"http://127.0.0.1/Upload","isopen":false} + case "aks100107": + result = SoundRecording(content); + Log.Info("开始录音、取消录音、结束录音返回:" + result); + break; + //aks100108 + //根据文件地址在线打印 { "code":"aks100108","url":"http://127.0.0.1/test.doc","ext":"doc"} + case "aks100108": + result = PrintFile(content); + break; + //aks100109 + //根据文件base64打印(PDF) { "code":"aks100109","base64":"ADFJLAKSDJFLKASJF...","ext":"pdf"} + case "aks100109": + result = PrintBase64(content); + //result = "{\"keycode\":\"" + "aks100109" + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"Base64打印保留原方式\"}"; + break; + //aks100110 + //播放音频文件 { "code":"aks100110","url":"http://127.0.0.1/test.wav","ispaye":false} + //停止播放音频文件 { "code":"aks100110","url":"","ispaye":true} + case "aks100110": + result = PalyFile(content); + break; + //aks100111 唤醒键盘 {"code":"aks100111"} + case "aks100111": + result = openKey(keycode); + break; + //aks100113 + //读取指纹 {"code":"aks100113","isclose":false} + //关闭指纹 {"code":"aks100113","isclose":true} + case "aks100113": + result = ReadFingerData(content); + Log.Info("指纹返回:" + result); + break; + default: + result = "{\"keycode\":\"" + "" + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"无效指令\"}"; + break; + } + } + else + { + result = "{\"keycode\":\"" + "hert" + "\",\"message\":\"seccse\",\"code\":\"400\",\"status\":true,\"data\":\"参数解析错误\"}"; } } - else - { - result = "{\"keycode\":\"" + "hert" + "\",\"message\":\"seccse\",\"code\":\"400\",\"status\":true,\"data\":\"参数解析错误\"}"; - } + catch { result = "{\"keycode\":\"" + "hert" + "\",\"message\":\"seccse\",\"code\":\"400\",\"status\":true,\"data\":\"参数解析错误\"}"; } + finally { } } - catch { result = "{\"keycode\":\"" + "hert" + "\",\"message\":\"seccse\",\"code\":\"400\",\"status\":true,\"data\":\"参数解析错误\"}"; } + else + { + result = "{\"keycode\":\"" + "" + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"无效指令\"}"; + } + try + { + //答复请求者(处理完请求后在些答复) + byte[] bytes = SerializeContent(result); + socket.Send(result); + } + catch { result = "{\"keycode\":\"" + "hert" + "\",\"message\":\"seccse\",\"code\":\"400\",\"status\":true,\"data\":\"返回参数失败\"}"; } finally { } } - else + //监听心跳并且回复客户端“已ping作为关键字” + else if (content == "ping") { - result = "{\"keycode\":\"" + "" + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"无效指令\"}"; + string result = "{\"keycode\":\"" + "hert" + "\",\"message\":\"seccse\",\"code\":\"200\",\"status\":true,\"data\":\"收到客户端心跳\"}"; + socket.Send(result); } - Log.Error("答复请求者:" + s.ToString() + " 返回数据:" + result); - try + else { - //答复请求者(处理完请求后在些答复) - byte[] bytes = SerializeContent(result); - ws.Reply(s.ToString(), new SAEA.WebSocket.Model.WSProtocal(SAEA.WebSocket.Type.WSProtocalType.Text, bytes)); + string result = "{\"keycode\":\"" + "hert" + "\",\"message\":\"seccse\",\"code\":\"200\",\"status\":true,\"data\":\"收到客户端心跳\"}"; + socket.Send(result); } - catch { result = "{\"keycode\":\"" + "hert" + "\",\"message\":\"seccse\",\"code\":\"400\",\"status\":true,\"data\":\"返回参数失败\"}"; } - finally { } - } - //监听心跳并且回复客户端“已ping作为关键字” - else if (content == "ping") - { - string result = "{\"keycode\":\"" + "hert" + "\",\"message\":\"seccse\",\"code\":\"200\",\"status\":true,\"data\":\"收到客户端心跳\"}"; - byte[] bytes = SerializeContent(result); - ws.Reply(s.ToString(), new SAEA.WebSocket.Model.WSProtocal(SAEA.WebSocket.Type.WSProtocalType.Text, bytes)); - } - else - { - string result = "{\"keycode\":\"" + "hert" + "\",\"message\":\"seccse\",\"code\":\"200\",\"status\":true,\"data\":\"收到客户端心跳\"}"; - byte[] bytes = SerializeContent(result); - ws.Reply(s.ToString(), new SAEA.WebSocket.Model.WSProtocal(SAEA.WebSocket.Type.WSProtocalType.Text, bytes)); - } - }; - ws.OnDisconnected += (s) => - { - try - { - Log.Error("断开连接" + s.ToString()); - } - catch { } - finally { } - }; - ws.Start(); + }; + }); } //解包 @@ -234,11 +230,12 @@ namespace AKS.EnterpriseLibrary.WebBrowser { try { - //Finger("",""); IDCard iDCard = new IDCard(); string result = iDCard.getIdCard(code); SubmitLogs(result, "IDCardRead"); - return result; + //LhtCF lht = new LhtCF(); + //string stat = lht.LhtCFFace(code, "/home/aks/aks/wwwroot/Face/20240529134642.bmp"); + return ""; } catch (Exception ex) { @@ -277,7 +274,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser if (!isFuncisFuncObject("SendByPrint")) { - Utils.MessagesBox("打印排队票据设备未授权使用"); + //Utils.MessagesBox("打印排队票据设备未授权使用"); return "{\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "打印排队票据设备未授权使用" + "\"}"; } else @@ -336,7 +333,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser bool ispaye = param.ispaye; if (!isFuncisFuncObject("payleText")) { - Utils.MessagesBox("文字语音播报设备未授权使用"); + //Utils.MessagesBox("文字语音播报设备未授权使用"); return "{\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "文字语音播报设备未授权使用" + "\"}"; } else @@ -472,7 +469,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser { if (!isFuncisFuncObject("OpenSign")) { - Utils.MessagesBox("签字版设备未授权使用"); + //Utils.MessagesBox("签字版设备未授权使用"); return "{\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "签字版设备未授权使用" + "\"}"; } else @@ -505,7 +502,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser { if (!isFuncisFuncObject("OpenSign")) { - Utils.MessagesBox("签字版设备未授权使用"); + //Utils.MessagesBox("签字版设备未授权使用"); return "{\"keycode\":\"" + code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "签字版设备未授权使用" + "\"}"; } else @@ -542,7 +539,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser { if (!isFuncisFuncObject("ReadFingerData")) { - Utils.MessagesBox("指纹设备未授权使用"); + //Utils.MessagesBox("指纹设备未授权使用"); return "{\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "指纹设备未授权使用" + "\"}"; } else @@ -564,7 +561,8 @@ namespace AKS.EnterpriseLibrary.WebBrowser SubmitLogs(result, "ReadFingerData"); return result; } - else { + else + { Task.Run(() => { HttpPostResponseByFinger("open", 1); }); event2.WaitOne(); string result = string.Empty; @@ -623,9 +621,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser //结束录音上传文件 if (!string.IsNullOrEmpty(url) && !isopen) { - Task.Run(() => { HttpPostResponseByRecord("stop_record", 3, ""); }); - event2.WaitOne(); - if (string.IsNullOrEmpty(srpath)) + if (StopRecording()) { Task.Run(async () => { @@ -649,16 +645,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser } else if (isopen)//开始录音 { - string time = DateTime.Now.ToString("yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo); - string dirpath = Utils.getSystemPaht() + @"/wwwroot/Record"; - if (!Directory.Exists(dirpath)) - { - Directory.CreateDirectory(dirpath); - } - string path = dirpath + "/" + time + ".wav"; - Task.Run(() => { HttpPostResponseByRecord("start_record", 2, path); }); - event2.WaitOne(); - if (string.IsNullOrEmpty(srpath)) + if (StartRecording()) { string result = "{\"keycode\":\"" + param.code + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"wav\",\"data\":\"" + "开始录音" + "\"}"; SubmitLogs(result, "SoundRecording"); @@ -673,9 +660,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser } else //取消录音 { - Task.Run(() => { HttpPostResponseByRecord("stop_record", 3, ""); }); - event2.WaitOne(); - if (string.IsNullOrEmpty(srpath)) + if (StopRecording()) { srpath = string.Empty; string result = "{\"keycode\":\"" + param.code + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"wav\",\"data\":\"" + "取消录音" + "\"}"; @@ -722,7 +707,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser string ext = param.ext; if (!isFuncisFuncObject("PrintFile")) { - Utils.MessagesBox("打印机设备未授权使用"); + //Utils.MessagesBox("打印机设备未授权使用"); return "{\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "打印机设备未授权使用" + "\"}"; } else @@ -774,15 +759,21 @@ namespace AKS.EnterpriseLibrary.WebBrowser /// /// /// - [JSFunction] - public static string PrintBase64(string url, string base64, string ext) + //[JSFunction] + public static string PrintBase64(string content) { + var param = content.ConvertToAnonymousType(new + { + code = default(string), + base64 = default(string), + ext = default(string) + }); try { if (!isFuncisFuncObject("PrintBase64")) { - Utils.MessagesBox("打印机设备未授权使用"); - return "{\"keycode\":\"" + "" + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "打印机设备未授权使用" + "\"}"; + //Utils.MessagesBox("打印机设备未授权使用"); + return "{\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "打印机设备未授权使用" + "\"}"; } else { @@ -797,8 +788,8 @@ namespace AKS.EnterpriseLibrary.WebBrowser Directory.CreateDirectory(dirpath); } var filepath = System.IO.Path.Combine(dirpath, time); - string path = dirpath + @"/" + time + "." + ext; - byte[] bytes = Convert.FromBase64String(base64); + string path = dirpath + @"/" + time + "." + param.ext; + byte[] bytes = Convert.FromBase64String(param.base64); System.IO.FileStream stream = new System.IO.FileStream(path, System.IO.FileMode.CreateNew); System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream); writer.Write(bytes, 0, bytes.Length); @@ -807,14 +798,14 @@ namespace AKS.EnterpriseLibrary.WebBrowser string command = $"lp -d {PrinterName} {path}"; ShllCommad(command); }); - string result = "{\"keycode\":\"" + "" + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + "打印成功" + "\"}"; + string result = "{\"keycode\":\"" + param.code + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + "打印成功" + "\"}"; SubmitLogs(result, "PrintBase64"); return result; } } catch (Exception ex) { - string result = "{\"keycode\":\"" + "" + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; + string result = "{\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; SubmitLogs(result, "PrintBase64"); return result; } @@ -840,7 +831,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser bool ispaly = param.ispaly; if (!isFuncisFuncObject("PalyFile")) { - Utils.MessagesBox("音频设备未授权使用"); + //Utils.MessagesBox("音频设备未授权使用"); return "{\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "音频设备未授权使用" + "\"}"; } else