From 39a5a45727dcec3e55d30abb1a0a8a89809daa9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=BD=87=E9=98=B3?= Date: Thu, 4 Jul 2024 10:48:25 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BA=AB=E4=BB=BD=E8=AF=81=E4=B8=8E=E5=8F=8C?= =?UTF-8?q?=E7=9B=AE=E8=AF=86=E5=88=AB=E5=88=86=E7=A6=BB=EF=BC=8C=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E5=8F=8C=E7=9B=AE=E8=AF=86=E5=88=AB=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CPF_Cef/Common/ChunkedUpload.cs | 49 +++++++++++++------ .../Common/WebSocketClientWithHeartbeat.cs | 25 +++++----- CPF_Cef/FrmMain.cs | 4 +- CPF_Cef/MainModel.cs | 26 +++------- CPF_Cef/Parame.cs | 2 +- 5 files changed, 56 insertions(+), 50 deletions(-) diff --git a/CPF_Cef/Common/ChunkedUpload.cs b/CPF_Cef/Common/ChunkedUpload.cs index 7044e8a..f021358 100644 --- a/CPF_Cef/Common/ChunkedUpload.cs +++ b/CPF_Cef/Common/ChunkedUpload.cs @@ -123,7 +123,7 @@ namespace AksWebBrowser.Common } catch (HttpRequestException e) { - //Log.Error(" get请求: " + e.Message); + Log.Error(" get请求: " + e.Message); } } @@ -250,6 +250,7 @@ namespace AksWebBrowser.Common } catch (Exception ex) { + Log.Error("获取签字版数据异常:" + ex.Message); //关闭签字版 await PublicSign("close", 2, timeout); if (ex.Message.Contains("HttpClient.Timeout")) @@ -273,17 +274,24 @@ namespace AksWebBrowser.Common public async Task PublicSign(string type, int typeCode, int timeout) { string body = string.Empty; - timeout = timeout == 0 ? Parame.timeout : timeout; - var client = new HttpClient(); - client.Timeout = TimeSpan.FromSeconds(timeout); - var request = new HttpRequestMessage(HttpMethod.Post, Parame.signUrl); - var content = new StringContent("{\r\n \"command\": \"sign\",\r\n \"command_num\": 111,\r\n \"data\": {\r\n \"operation\": \"" + type + "\",\r\n \"operation_code\": " + typeCode + ",\r\n \"parameters\": {\r\n \"data_type\": 1\r\n }\r\n }\r\n}", null, "application/json"); - request.Content = content; - var response = await client.SendAsync(request); - response.EnsureSuccessStatusCode(); - if (response.StatusCode.ToString() == "OK") + try + { + timeout = timeout == 0 ? Parame.timeout : timeout; + var client = new HttpClient(); + client.Timeout = TimeSpan.FromSeconds(timeout); + var request = new HttpRequestMessage(HttpMethod.Post, Parame.signUrl); + var content = new StringContent("{\r\n \"command\": \"sign\",\r\n \"command_num\": 111,\r\n \"data\": {\r\n \"operation\": \"" + type + "\",\r\n \"operation_code\": " + typeCode + ",\r\n \"parameters\": {\r\n \"data_type\": 1\r\n }\r\n }\r\n}", null, "application/json"); + request.Content = content; + var response = await client.SendAsync(request); + response.EnsureSuccessStatusCode(); + if (response.StatusCode.ToString() == "OK") + { + body = await response.Content.ReadAsStringAsync(); + } + } + catch (Exception ex) { - body = await response.Content.ReadAsStringAsync(); + Log.Error("签字版公共请求异常:" + ex.Message); } return body; } @@ -298,6 +306,9 @@ namespace AksWebBrowser.Common { if (tts_text.Length <= 2000) { + tts_text =Regex.Replace(tts_text, @" ", " ").Trim(); + tts_text = Regex.Replace(tts_text, @"\s+", "").Trim(); + Log.Info("处理后文字:"+tts_text); 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\": \"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"); @@ -389,6 +400,7 @@ namespace AksWebBrowser.Common } catch (Exception ex) { + Log.Error("文字转语音异常:" + ex.Message); return ""; } } @@ -500,6 +512,7 @@ namespace AksWebBrowser.Common } catch (Exception ex) { + Log.Error("获取指纹异常:" + ex.Message); await PublicFinger("close", 2, timeout); if (ex.Message.Contains("HttpClient.Timeout")) { @@ -537,9 +550,9 @@ namespace AksWebBrowser.Common body = await response.Content.ReadAsStringAsync(); } } - catch (Exception) + catch (Exception ex) { - + Log.Error("公共读取指纹异常:" + ex.Message); return ""; } return body; @@ -594,6 +607,8 @@ namespace AksWebBrowser.Common iDCardModel.StartDate = jo4["validity_begin"].ToString(); iDCardModel.EndDate = jo4["balidity_end"].ToString(); iDCardModel.ImageBase64 = "data:image/jpg;base64," + base64; + //当前刷身份证的人 + Parame.ImgBase64 = base64; var OBJ = new { Data = iDCardModel @@ -625,6 +640,7 @@ namespace AksWebBrowser.Common } catch (Exception ex) { + Log.Error("读取身份证"+ex.Message); //关闭身份证 await PublicIdcard(timeout); if (ex.Message.Contains("HttpClient.Timeout")) @@ -663,8 +679,9 @@ namespace AksWebBrowser.Common body = await response.Content.ReadAsStringAsync(); } } - catch (Exception) + catch (Exception ex) { + Log.Error("公共读取身份证异常:" + ex.Message); return ""; } return body; @@ -695,14 +712,14 @@ namespace AksWebBrowser.Common body = await response.Content.ReadAsStringAsync(); } } - catch (Exception) + catch (Exception ex) { + Log.Error("获取问题异常:" + ex.Message); return ""; } return body; } - /// /// 读取body数据 /// diff --git a/CPF_Cef/Common/WebSocketClientWithHeartbeat.cs b/CPF_Cef/Common/WebSocketClientWithHeartbeat.cs index 9050adf..4fec9c7 100644 --- a/CPF_Cef/Common/WebSocketClientWithHeartbeat.cs +++ b/CPF_Cef/Common/WebSocketClientWithHeartbeat.cs @@ -80,14 +80,7 @@ namespace AksWebBrowser.Common string results = Parame.ImgBase64; if (!string.IsNullOrEmpty(results)) { - JObject jo1 = (JObject)JsonConvert.DeserializeObject(results); - string data = jo1["data"].ToString(); - jo1 = (JObject)JsonConvert.DeserializeObject(data); - string data2 = jo1["Data"].ToString(); - jo1 = (JObject)JsonConvert.DeserializeObject(data2); - string ImageBase64 = jo1["ImageBase64"].ToString(); - //var faceA = "/data/home/aks/aks/wwwroot/TmpFile/faceA.jpg"; - //var faceB = "/data/home/aks/aks/wwwroot/TmpFile/faceB.jpg"; + string ImageBase64 = Parame.ImgBase64; string faceA = Utils.Base64ByImagesPath(ImageBase64.Replace("data:image/jpg;base64,", ""), "faceA"); string faceB = Utils.Base64ByImagesPath(jo["ImgBase64"].ToString(), "faceB"); var mode2 = new @@ -103,12 +96,11 @@ namespace AksWebBrowser.Common else { timer.Stop(); - results = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + "aks100101" + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "人证合一验证失败." + "\"}"; + results = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + "aks100120" + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "人证合一验证失败." + "\"}"; Parame.socket.Send(results); // 断开连接 _webSocket.Dispose(); } - } } } @@ -122,17 +114,24 @@ namespace AksWebBrowser.Common string results = string.Empty; if (status == "0") { - results = Parame.ImgBase64; + results = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + "aks100120" + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + "人证合一验证成功." + "\"}"; } else { - results = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + "aks100101" + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "人证合一验证失败." + "\"}"; + results = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + "aks100120" + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "人证合一验证失败." + "\"}"; } timer.Stop(); Parame.socket.Send(results); // 断开连接 _webSocket.Dispose(); } + else if (functionName == "VideoStream") + { + string VideoBase64 = jo["VideoBase64"].ToString(); + string src = "data:image/jpg;base64," + VideoBase64; + string results = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + "aks100121" + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + src + "\"}"; + Parame.socket.Send(results); + } } } } @@ -209,7 +208,7 @@ namespace AksWebBrowser.Common Send("{\"function\":\"CF_StopLiveDetect\"}", "CF_StopLiveDetect"); //关闭摄像头 Send("{\"function\":\"CF_CloseCamera\"}", "CF_CloseCamera"); - string results = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + "aks100101" + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "活体检测超时." + "\"}"; + string results = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + "aks100120" + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "活体检测超时." + "\"}"; Parame.socket.Send(results); } catch { } diff --git a/CPF_Cef/FrmMain.cs b/CPF_Cef/FrmMain.cs index 823a436..fe57627 100644 --- a/CPF_Cef/FrmMain.cs +++ b/CPF_Cef/FrmMain.cs @@ -81,9 +81,9 @@ namespace AksWebBrowser //浏览器大小 Parame.webBrowser.Width = w; Parame.webBrowser.Height = h; - //Parame.webBrowser.Url = "http://127.0.0.1:8096/#/main-out"; + Parame.webBrowser.Url = "http://127.0.0.1:8096/#/main-out"; //Parame.webBrowser.Url = "http://192.168.0.232:8848/html/index.html"; - Parame.webBrowser.Url = "http://192.168.0.34:8078/#/main-out"; + //Parame.webBrowser.Url = "http://192.168.0.34:8078/#/main-out"; //Parame.webBrowser.Url = Application.StartupPath + @"\html\index.html"; //开发者工具暂时只能支持Windows //webBrowser.ShowDev(); diff --git a/CPF_Cef/MainModel.cs b/CPF_Cef/MainModel.cs index 1f43fec..db9f86f 100644 --- a/CPF_Cef/MainModel.cs +++ b/CPF_Cef/MainModel.cs @@ -84,6 +84,11 @@ namespace AksWebBrowser case "aks100101": result = IDCardRead(content); break; + //aks100120 + //开启双目 {"code":"aks100120"} + case "aks100120": + StartFace(); + break; //aks100102 //打印排队票据 {"code":"aks100102","ph":"100101","ddrs":"中国检察","qrcode":"90087100100124433002","ywmc":"信访"} case "aks100102": @@ -284,23 +289,9 @@ namespace AksWebBrowser } else { - - if (Parame.isSM) - { - Task.Run(async () => - { - string results = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + param.code + "\",\"message\":\"seccse\",\"code\":\"200\",\"status\":true,\"data\":" + IdcardStr + "}"; - StartFace(results); - }); - result = ""; - } - else - { - result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + param.code + "\",\"message\":\"seccse\",\"code\":\"200\",\"status\":true,\"data\":" + IdcardStr + "}"; - } + string results = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + param.code + "\",\"message\":\"seccse\",\"code\":\"200\",\"status\":true,\"data\":" + IdcardStr + "}"; return result; } - } SubmitLogs(result, "IDCardRead"); return result; @@ -1725,16 +1716,15 @@ namespace AksWebBrowser /// private static string smresults = string.Empty; private static AutoResetEvent @event9 = new AutoResetEvent(false); - private static async void StartFace(string ImageBase64) + private static void StartFace() { try { WebSocketClientWithHeartbeat webSocket = new WebSocketClientWithHeartbeat(); - Parame.ImgBase64 = ImageBase64; var mode = new { function = "CF_OpenCamera", - show = 1, + show = 0, fx = 150, fy = 800, fw = 800, diff --git a/CPF_Cef/Parame.cs b/CPF_Cef/Parame.cs index 43b336d..baed01a 100644 --- a/CPF_Cef/Parame.cs +++ b/CPF_Cef/Parame.cs @@ -19,7 +19,7 @@ namespace AksWebBrowser public static Window frm { get; set; } public static List FuncObject { get; set; } //接口地址 - public static string apiUrl = "http://127.0.0.1:8098";// "http://192.168.0.34:92"; + public static string apiUrl = "http://127.0.0.1:8098";//"http://192.168.0.34:92";// //授权key public static string key = "1"; //硬件Ip