From 27bcde5daf385a598009f957bdad2478b735fcc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=BD=87=E9=98=B3?= Date: Tue, 28 May 2024 12:22:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E7=A1=AC=E4=BB=B6=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AKS.EnterpriseLibrary.WebBrowser.csproj | 8 +- CPF_Cef/Common/ChunkedUpload.cs | 47 +- CPF_Cef/Common/JsonAssist.cs | 201 +++ CPF_Cef/Devices/Fingerprint.cs | 6 +- CPF_Cef/Devices/IDCard.cs | 10 +- CPF_Cef/FrmMain.cs | 26 +- CPF_Cef/MainModel - 副本.cs | 1236 +++++++++++++++++ CPF_Cef/MainModel.cs | 444 ++++-- 8 files changed, 1775 insertions(+), 203 deletions(-) create mode 100644 CPF_Cef/Common/JsonAssist.cs create mode 100644 CPF_Cef/MainModel - 副本.cs diff --git a/CPF_Cef/AKS.EnterpriseLibrary.WebBrowser.csproj b/CPF_Cef/AKS.EnterpriseLibrary.WebBrowser.csproj index 077af2d..facadc3 100644 --- a/CPF_Cef/AKS.EnterpriseLibrary.WebBrowser.csproj +++ b/CPF_Cef/AKS.EnterpriseLibrary.WebBrowser.csproj @@ -22,6 +22,10 @@ AnyCPU + + + + @@ -35,13 +39,13 @@ - - + + diff --git a/CPF_Cef/Common/ChunkedUpload.cs b/CPF_Cef/Common/ChunkedUpload.cs index efe1799..39db7d8 100644 --- a/CPF_Cef/Common/ChunkedUpload.cs +++ b/CPF_Cef/Common/ChunkedUpload.cs @@ -12,6 +12,7 @@ using CPF.Controls; using AKSWebBrowser.Commen; using System.Collections; using System.Net.NetworkInformation; +using AKS.EnterpriseLibrary.WebBrowser; namespace AksWebBrowser.Common { @@ -94,11 +95,10 @@ namespace AksWebBrowser.Common /// 获取签字版数据 /// /// - public async Task PostSign(string type, int typeCode, string _callback) + public async Task PostSign(string type, int typeCode, string code) { try { - callback = _callback; var client = new HttpClient(); 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"); @@ -125,53 +125,36 @@ namespace AksWebBrowser.Common //读取签字base64 string sign_pic = jo4["sign_pic"].ToString(); //读取签字版主动回复数据 - string result = "{\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"png\",\"data\":\"" + sign_pic + "\"}"; - string _parm = callback + "('" + result + "')"; - Task.Run(async () => - { - await Parame.webBrowser.ExecuteJavaScript(_parm); - }); - Log.Info(sign_pic); + //"data:image/png;base64, " + + return "{\"keycode\":\"" + code + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"png\",\"data\":\"" + sign_pic + "\"}"; } else { Log.Error("请求签字失败" + jo["message"].ToString()); - string result = "{\"message\":\"fail\",\"code\":\"400\",\"status\":false,\"suffix\":\"png\",\"data\":\"" + "签字失败" + "\"}"; - string _parm = callback + "('" + result + "')"; - Task.Run(async () => - { - await Parame.webBrowser.ExecuteJavaScript(_parm); - }); + return "{\"keycode\":\"" + code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"suffix\":\"png\",\"data\":\"" + "签字失败" + "\"}"; } } + else + { + return "{\"keycode\":\"" + code + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"png\",\"data\":\"" + "关闭成功" + "\"}"; + } } else { if (type == "open" && typeCode == 1) { - string result = "{\"message\":\"fail\",\"code\":\"400\",\"status\":false,\"suffix\":\"png\",\"data\":\"" + "签字失败" + "\"}"; - string _parm = callback + "('" + result + "')"; - Task.Run(async () => - { - await Parame.webBrowser.ExecuteJavaScript(_parm); - }); - + return "{\"keycode\":\"" + code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"suffix\":\"png\",\"data\":\"" + "签字失败" + "\"}"; + } + else + { + return "{\"keycode\":\"" + code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"suffix\":\"png\",\"data\":\"" + "关闭签字失败" + "\"}"; } - Log.Error("请求签字失败"); } } catch (Exception ex) { - if (type == "open" && typeCode == 1) - { - string result = "{\"message\":\"fail\",\"code\":\"400\",\"status\":false,\"suffix\":\"png\",\"data\":\"" + "签字失败" + "\"}"; - string _parm = "callback('" + result + "')"; - Task.Run(async () => - { - await Parame.webBrowser.ExecuteJavaScript(_parm); - }); - } Log.Error("签字异常:" + ex.Message); + return "{\"keycode\":\"" + code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"suffix\":\"png\",\"data\":\"" + "签字异常" + "\"}"; } } } diff --git a/CPF_Cef/Common/JsonAssist.cs b/CPF_Cef/Common/JsonAssist.cs new file mode 100644 index 0000000..904e266 --- /dev/null +++ b/CPF_Cef/Common/JsonAssist.cs @@ -0,0 +1,201 @@ +using Newtonsoft.Json; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System; +using System.Text.RegularExpressions; + + +namespace AksWebBrowser.Common +{ + public static class JsonAssist + { + /// + /// model=>json string + /// + /// + /// + /// + + private readonly static JsonSerializerSettings settings = new JsonSerializerSettings() + { + NullValueHandling = NullValueHandling.Ignore, + ReferenceLoopHandling = ReferenceLoopHandling.Ignore + }; + public static string ConvertToJsonStr(this T t) + { + try + { + return JsonConvert.SerializeObject(t, Formatting.None, settings); + + } + catch + { + return default; + } + } + public static T DeepCopy(this T t) + { + return t.ConvertToJsonStr().ConvertToModel(); + } + /// + /// json转为匿名对象 + /// + /// + /// + /// + /// + public static T ConvertToAnonymousType(this object json, T anonymousTypeObject) + { + try + { + return JsonConvert.DeserializeAnonymousType(json.ToString(), anonymousTypeObject); + } + catch + { + return default; + } + } + /// + /// object 转匿名类 + /// + /// + /// + /// + /// + public static T ConvertToAnonymous(this object anonymous, T anonymousType) + { + try + { + if (anonymous != null) + { + return (T)anonymous; + } + else + { + return default; + } + } + catch + { + return default; + + } + } + /// + /// json string=>mdoel + /// + /// + /// + /// + public static T ConvertToModel(this string str, [CallerMemberName] string methodname = "") + { + try + { + return JsonConvert.DeserializeObject(str); + } + catch (Exception) + { + return default; + } + } + public static string ConvertToBase64(this string str) + { + return Convert.ToBase64String(Encoding.Default.GetBytes(str)); + } + public static string ConvertToGetParam(this object obj) + { + StringBuilder strBui = new StringBuilder(); + + System.Reflection.PropertyInfo[] proArray = obj.GetType().GetProperties(); + foreach (System.Reflection.PropertyInfo pro in proArray) + { + if (strBui.Length < 1) + { + strBui.Append("?"); + } + else + { + strBui.Append("&"); + } + strBui.Append(string.Format("{0}={1}", pro.Name, pro.GetValue(obj, null))); + } + return strBui.ToString(); + } + // DateTime --> long + public static long ConvertDateTimeToLong(DateTime dt) + { + DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); + TimeSpan toNow = dt.Subtract(dtStart); + long timeStamp = toNow.Ticks; + timeStamp = long.Parse(timeStamp.ToString().Substring(0, timeStamp.ToString().Length - 4)); + return timeStamp; + } + // long --> DateTime + public static DateTime ConvertLongToDateTime(long d) + { + DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); + long lTime = long.Parse(d + "0000"); + TimeSpan toNow = new TimeSpan(lTime); + DateTime dtResult = dtStart.Add(toNow); + return dtResult; + } + + } + + public static class DateHelper + { + public static DateTime GetStartDateOfDay(DateTime date) + { + return date.Date; + } + public static DateTime GetEndDateOfDay(DateTime date) + { + return date.Date.AddDays(1).AddSeconds(-1); + } + public static DateTime GetStartDateOfMonth(DateTime date) + { + return date.AddDays(1 - date.Day).Date; + } + public static DateTime GetEndDateOfMonth(DateTime date) + { + return GetStartDateOfMonth(date).AddMonths(1).AddSeconds(-1); + } + public static DateTime GetStartDateOfYear(DateTime date) + { + return date.AddDays(1 - date.Day).AddMonths(1 - date.Month).Date; + } + public static DateTime GetEndDateOfYear(DateTime date) + { + return GetStartDateOfYear(date).AddYears(1).AddSeconds(-1); + } + public static List GetArrayByDay(DateTime starttime, DateTime endtime) + { + var list = new List(); + for (DateTime dt = starttime; dt.Date <= endtime.Date; dt = dt.AddDays(1)) + { + list.Add(dt.Date); + } + return list; + } + public static List GetArrayByMonth(DateTime starttime, DateTime endtime) + { + var list = new List(); + for (DateTime dt = starttime; dt.Date <= endtime.Date; dt = dt.AddMonths(1)) + { + list.Add(GetStartDateOfMonth(dt.Date)); + } + return list; + } + public static List GetArrayByYear(DateTime starttime, DateTime endtime) + { + var list = new List(); + for (DateTime dt = starttime; dt.Date <= endtime.Date; dt = dt.AddYears(1)) + { + list.Add(GetStartDateOfYear(dt.Date)); + } + return list; + } + } +} \ No newline at end of file diff --git a/CPF_Cef/Devices/Fingerprint.cs b/CPF_Cef/Devices/Fingerprint.cs index 8fc2a97..b36fd57 100644 --- a/CPF_Cef/Devices/Fingerprint.cs +++ b/CPF_Cef/Devices/Fingerprint.cs @@ -25,11 +25,10 @@ namespace AksWebBrowser.Devices public Fingerprint() { } //读取指纹 - public static string LIVESCANFinger(string _callback) + public static string LIVESCANFinger(string code) { try { - callback = _callback; init = LibFingerprint.LIVESCAN_Init(); if (init == 1) { @@ -37,9 +36,6 @@ namespace AksWebBrowser.Devices td = LibFingerprint.LIVESCAN_GetChannelCount(); if (td > 0) { - - - Log.Info("获得采集器通道数量成功"); int pnBright = 254; int status = LibFingerprint.LIVESCAN_GetBright(td, ref pnBright); diff --git a/CPF_Cef/Devices/IDCard.cs b/CPF_Cef/Devices/IDCard.cs index 09213f3..a20948c 100644 --- a/CPF_Cef/Devices/IDCard.cs +++ b/CPF_Cef/Devices/IDCard.cs @@ -33,7 +33,7 @@ namespace AksWebBrowser.Devices /// 获取身份证 /// /// - public string getIdCard() + public string getIdCard(string code) { try { @@ -82,20 +82,20 @@ namespace AksWebBrowser.Devices }; //关闭 LibClass.ICReaderClose(icdev); - return "{\"message\":\"seccse\",\"code\":\"200\",\"status\":true,\"data\":" + JsonConvert.SerializeObject(OBJ) + "}"; + return "{\"keycode\":\"" + code + "\",\"message\":\"seccse\",\"code\":\"200\",\"status\":true,\"data\":" + JsonConvert.SerializeObject(OBJ) + "}"; } else { //关闭 LibClass.ICReaderClose(icdev); - return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "读取身份证失败" + "\"}"; + return "{\"keycode\":\"" + code + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "读取身份证失败" + "\"}"; } } else { //关闭 LibClass.ICReaderClose(icdev); - return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "读取身份证失败" + "\"}"; + return "{\"keycode\":\"" + code + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "读取身份证失败" + "\"}"; } } catch (Exception ex) @@ -105,7 +105,7 @@ namespace AksWebBrowser.Devices { LibClass.ICReaderClose(icdev); } - return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; + return "{\"keycode\":\"" + code + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; } } diff --git a/CPF_Cef/FrmMain.cs b/CPF_Cef/FrmMain.cs index 97fa598..1193c84 100644 --- a/CPF_Cef/FrmMain.cs +++ b/CPF_Cef/FrmMain.cs @@ -1,20 +1,18 @@ using AksWebBrowser; +using AksWebBrowser.Common; +using AKSWebBrowser.Commen; using CPF; using CPF.Cef; using CPF.Controls; -using CPF.Platform; -using Newtonsoft.Json.Linq; using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using System; +using System.Collections.Generic; using System.IO; using System.Net.Http; using System.Text; -using System.Threading.Tasks; -using AKSWebBrowser.Commen; -using System.Collections.Generic; -using System.Reflection.Metadata; -using AksWebBrowser.Common; using System.Threading; +using System.Threading.Tasks; namespace AKS.EnterpriseLibrary.WebBrowser { @@ -31,7 +29,15 @@ namespace AKS.EnterpriseLibrary.WebBrowser Title = "控申业务专用浏览器"; CanResize = false; ShowInTaskbar = true; - WindowState = WindowState.Maximized; + WindowState = WindowState.FullScreen; + var v = new VideoView + { + Name = "player", + PresenterFor = this, + MarginTop = 0, + Width = 300, + Height = 300 + }; Children.Add( new Border { @@ -42,6 +48,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser Size = SizeField.Fill, Children = { + v, new CusWebBrowser { PresenterFor = this, @@ -73,6 +80,9 @@ namespace AKS.EnterpriseLibrary.WebBrowser this.Height = h; //SetTaskStatus.Hidetask(); base.OnInitialized(); + + //初始化网络连接(硬件服务响应) + MainModel.DeviceControllerInit(); Parame.webBrowser = FindPresenterByName(nameof(Parame.webBrowser)); textBox = FindPresenterByName(nameof(textBox)); Parame.webBrowser.CusRequest.CusResquestEvent += CusRequest_CusResquestEvent; diff --git a/CPF_Cef/MainModel - 副本.cs b/CPF_Cef/MainModel - 副本.cs new file mode 100644 index 0000000..8c53875 --- /dev/null +++ b/CPF_Cef/MainModel - 副本.cs @@ -0,0 +1,1236 @@ +using AksWebBrowser; +using AksWebBrowser.Common; +using AKSWebBrowser.Commen; +using AKSWebBrowser.Common; +using CPF.Cef; +using CPF.Mac.AppKit; +using DevicesService.Devices; +using NAudio.Wave; +using NAudio.Wave.SampleProviders; +using Newtonsoft.Json.Linq; +using Newtonsoft.Json; +using SkiaSharp; +using System; +using System.Buffers.Text; +using System.Diagnostics; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Net.Sockets; +using System.Text.RegularExpressions; +using System.Threading; +using System.Threading.Tasks; +using System.Web; +using System.Xml.Linq; +using static System.Net.Mime.MediaTypeNames; +using AksWebBrowser.Devices; +using System.Reflection; +using System.Text; + +namespace AKS.EnterpriseLibrary.WebBrowser +{ + public class MainModel : CPF.CpfObject + { + + //初始化网络连接 + public static void DeviceControllerInit() + { + + SAEA.WebSocket.WSServer ws = new SAEA.WebSocket.WSServer(9983); + ws.OnConnected += (s) => + { + byte[] bytes = SerializeContent("连接成功"); + ws.Reply(s.ToString(), new SAEA.WebSocket.Model.WSProtocal(SAEA.WebSocket.Type.WSProtocalType.Text, bytes)); + }; + ws.OnMessage += (s, e) => + { + //接收指令和参数 + string keycode = Encoding.UTF8.GetString(e.Content); + switch (keycode) + { + default: + break; + } + //答复请求者(处理完请求后在些答复) + byte[] bytes = SerializeContent("这里返回参数"); + ws.Reply(s.ToString(), new SAEA.WebSocket.Model.WSProtocal(SAEA.WebSocket.Type.WSProtocalType.Text, bytes)); + }; + ws.Start(); + } + + //解包 + private static string DeserializeContent(byte[] param) + { + try + { + return Encoding.UTF8.GetString(param); + } + catch + { + return "参数无效"; + } + } + //封包 + private static byte[] SerializeContent(string param) + { + try + { + return Encoding.UTF8.GetBytes(param); + } + catch + { + return null; + //return "参数无效"; + } + } + + public string callback = string.Empty; + public string PrinterName = "Lexmark-MS430-Series"; + public static Process recordingProcess; + public static Process Typrocess; + private string srpath = string.Empty; + + /// + /// aks100101 读取身份证卡号(已国产化) + /// + /// + /// + [JSFunction] + public string IDCardRead(string paramsString) + { + try + { + //Finger("",""); + IDCard iDCard = new IDCard(); + string result = iDCard.getIdCard(); + SubmitLogs(result, "IDCardRead"); + return result; + } + catch (Exception ex) + { + Log.Error("读取身份证卡号异常: " + ex.Message + ""); + string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; + SubmitLogs(result, "IDCardRead"); + return result; + } + } + + /// + /// 打印排队票据(已国产化) + /// + /// 排号 + /// 等待人数 + /// 二维码 + /// 办理业务名称 + /// + [JSFunction] + public string SendByPrint(string ph, string ddrs, string qrcode, string ywmc) + { + try + { + if (!isFuncisFuncObject("SendByPrint")) + { + Utils.MessagesBox("打印排队票据设备未授权使用"); + return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "打印排队票据设备未授权使用" + "\"}"; + } + else + { + PrintPJ print = new PrintPJ(Parame.pritPj, Parame.pritPjPort); + var data = print.SendPrint(ph, ddrs, qrcode, ywmc); + if (data == 0) + { + string result = "{\"message\":\"seccse\",\"code\":\"200\",\"status\":true,\"data\":\"" + "打印成功" + "\"}"; + SubmitLogs(result, "SendByPrint"); + return result; + } + else + { + string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + (data == 1 ? "打印失败" : (data == 2 ? "打印机未连接" : "打印机初始化失败")) + "\"}"; + SubmitLogs(result, "SendByPrint"); + return result; + } + } + } + catch (Exception ex) + { + Log.Error("打印排队票据异常: " + ex.Message + ""); + string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; + SubmitLogs(result, "SendByPrint"); + return result; + } + } + + /// + /// 文字语音播报(已国产化) + /// apt install sox + /// apt install libsox-fmt-all + /// + /// + /// + /// + public WaveOutEvent playerTxt = null; + public static string tempWav = string.Empty; + [JSFunction] + public string payleText(string text, bool ispaye) + { + try + { + if (!isFuncisFuncObject("payleText")) + { + Utils.MessagesBox("文字语音播报设备未授权使用"); + return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "文字语音播报设备未授权使用" + "\"}"; + } + else + { + if (ispaye) + { + Task.Run(() => + { + if (Typrocess != null) + { + // 如果进程还在运行 + if (!Typrocess.HasExited) + { + // 发送SIGTERM信号来停止进程 + Typrocess.Kill(); + // 等待进程真正停止 + Typrocess.WaitForExit(); + } + } + }); + string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":" + "停止播放成功" + "}"; + SubmitLogs(result, "payleText"); + return result; + } + else + { + Task.Run(() => + { + //形成语音 + tempWav = GenerateWavFromText(text); + //开始播放 + string command = $"sox {tempWav} -d"; + ShllCommad(command); + }); + string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":" + "开始播放" + "}"; + SubmitLogs(result, "payleText"); + return result; + } + } + } + catch (Exception ex) + { + Log.Error("文字语音播报异常2: " + ex.Message + ""); + string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; + SubmitLogs(result, "payleText"); + return result; + } + } + + /// + /// 打开高拍仪并且进行快速扫描文件 (已国产化) + /// + /// + /// + [JSFunction] + public string openCamera(string url) + { + try + { + string devIndex = GetSnIndex(); + if (string.IsNullOrEmpty(devIndex)) + { + string result = "{\"callback\":\"" + callback + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"suffix\":\"jpg\",\"data\":\"" + "扫描仪打开失败" + "\"}"; + SubmitLogs(result, "openCamera"); + return result; + } + else + { + //打开高拍仪 + string param = OpenSn(devIndex); + if (string.IsNullOrEmpty(param)) + { + string result = "{\"callback\":\"" + callback + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"suffix\":\"jpg\",\"data\":\"" + "扫描仪打开失败" + "\"}"; + SubmitLogs(result, "openCamera"); + return result; + } + else + { + //拍照 + param = getFrame(); + if (string.IsNullOrEmpty(param)) + { + string result = "{\"callback\":\"" + callback + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"suffix\":\"jpg\",\"data\":\"" + "获取图片失败" + "\"}"; + SubmitLogs(result, "openCamera"); + return result; + } + else + { + Task.Run(() => + { + //关闭 + StopSn(devIndex); + }); + string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"jpg\",\"data\":\"" + param + "\"}"; + SubmitLogs(result, "openCamera"); + return result; + } + + } + } + } + catch (Exception ex) + { + Log.Error("打开高拍仪并且进行快速扫描文件异常: " + ex.Message + ""); + string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; + SubmitLogs(result, "openCamera"); + return result; + } + } + + /// + /// 打开签字版 sudo apt-get install libgdiplus (已国产化) + /// + /// + /// + [JSFunction] + public string OpenSign(string paramsString, string callback) + { + try + { + if (!isFuncisFuncObject("OpenSign")) + { + Utils.MessagesBox("签字版设备未授权使用"); + return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "签字版设备未授权使用" + "\"}"; + } + else + { + Task.Run(() => HttpPostResponseBySign("open", 1, callback)); + string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"jpg\",\"data\":\"" + "签字版已打开" + "\"}"; + SubmitLogs(result, "openCamera"); + return result; + } + } + catch (Exception ex) + { + Log.Error("打开签字版异常: " + ex.Message + ""); + string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; + SubmitLogs(result, "OpenSign"); + return result; + } + } + + /// + /// 关闭签字版 (已国产化) + /// + /// + /// + [JSFunction] + public string CloseSign(string paramsString) + { + try + { + if (!isFuncisFuncObject("OpenSign")) + { + Utils.MessagesBox("签字版设备未授权使用"); + return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "签字版设备未授权使用" + "\"}"; + } + else + { + Task.Run(() => HttpPostResponseBySign("close", 2, "")); + string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"jpg\",\"data\":\"" + "签字版已关闭" + "\"}"; + SubmitLogs(result, "openCamera"); + return result; + } + } + catch (Exception ex) + { + Log.Error("关闭签字版异常: " + ex.Message + ""); + string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; + SubmitLogs(result, "OpenSign"); + return result; + } + } + + /// + /// 指纹 (已国产化,未完成测试) + /// + /// + /// + [JSFunction] + public string ReadFingerData(string callback) + { + try + { + if (false)//!isFuncisFuncObject("Finger") + { + Utils.MessagesBox("指纹设备未授权使用"); + return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "指纹设备未授权使用" + "\"}"; + } + else + { + + string result = Fingerprint.LIVESCANFinger(callback); + SubmitLogs(result, "Finger"); + return result; + } + } + catch (Exception ex) + { + Log.Error("指纹异常: " + ex.Message + ""); + string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; + SubmitLogs(result, "Finger"); + return result; + } + } + + /// + /// 开始录音、取消录音、结束录音 (已国产化) + /// sudo apt-get update + /// sudo apt-get install alsa-utils + /// + /// + /// + /// + [JSFunction] + public string SoundRecording(bool isopen, string url) + { + try + { + if (!isFuncisFuncObject("SoundRecording")) + { + Utils.MessagesBox("录音设备未授权使用"); + return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "录音设备未授权使用" + "\"}"; + } + else + { + //结束录音上传文件 + if (!string.IsNullOrEmpty(url) && !isopen) + { + if (StopRecording()) + { + Task.Run(async () => + { + UploadInfo(url, srpath); + }); + @event2.WaitOne(); + Regex re = new Regex(@"(((?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(:[0-9]+)?|(?:ww‌​w.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?‌​(?:[\w]*))?)"); + MatchCollection mc = re.Matches(url);//获取的是一个数组 + string reurl = mc[0].ToString() + "://" + mc[1].ToString() + urlpath; + string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"wav\",\"data\":\"" + reurl + "\"}"; + SubmitLogs(result, "SoundRecording"); + return result; + } + else + { + string result = "{\"callback\":\"" + callback + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"suffix\":\"wav\",\"data\":\"" + "结束录音失败" + "\"}"; + SubmitLogs(result, "SoundRecording"); + return result; + } + } + else if (isopen)//开始录音 + { + if (StartRecording()) + { + string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"wav\",\"data\":\"" + "开始录音" + "\"}"; + SubmitLogs(result, "SoundRecording"); + return result; + } + else + { + string result = "{\"callback\":\"" + callback + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"suffix\":\"wav\",\"data\":\"" + "录音失败" + "\"}"; + SubmitLogs(result, "SoundRecording"); + return result; + } + } + else //取消录音 + { + if (StopRecording()) + { + srpath = string.Empty; + string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"wav\",\"data\":\"" + "取消录音" + "\"}"; + SubmitLogs(result, "SoundRecording"); + return result; + } + else + { + srpath = string.Empty; + string result = "{\"callback\":\"" + callback + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"suffix\":\"wav\",\"data\":\"" + "取消录音失败" + "\"}"; + SubmitLogs(result, "SoundRecording"); + return result; + } + + } + } + } + catch (Exception ex) + { + Log.Error("开始录音、取消录音、结束录音异常: " + ex.Message + ""); + string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; + SubmitLogs(result, "SoundRecording"); + return result; + } + } + + /// + /// 根据文件地址在线打印 (已国产化) + /// + /// + /// + [JSFunction] + public string PrintFile(string url, string ext) + { + try + { + if (!isFuncisFuncObject("PrintFile")) + { + Utils.MessagesBox("打印机设备未授权使用"); + return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "打印机设备未授权使用" + "\"}"; + } + else + { + Task.Run(async () => + { + DateTime dateTime = DateTime.Now; + string time = DateTime.Now.ToString( + "yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo); + string dirpath = System.IO.Directory.GetCurrentDirectory(); + dirpath = dirpath + @"/wwwroot/PrintFile"; + if (!Directory.Exists(dirpath)) + { + Directory.CreateDirectory(dirpath); + } + var filepath = System.IO.Path.Combine(dirpath, time); + string path = dirpath + @"/" + time + "." + ext; + WebRequest request = WebRequest.Create(url); + WebResponse response = request.GetResponse(); + using (Stream stream = response.GetResponseStream()) + { + using (FileStream fileStream = new FileStream(path, FileMode.Create)) + { + stream.CopyTo(fileStream); + } + } + response.Close(); + //Log.Info("根据文件base64打印: " + path + ""); + string command = $"lp -d {PrinterName} {path}"; + ShllCommad(command); + }); + string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + "打印成功" + "\"}"; + SubmitLogs(result, "PrintFile"); + return result; + } + } + catch (Exception ex) + { + Log.Error("根据文件地址在线打印异常: " + ex.Message + ""); + string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; + SubmitLogs(result, "PrintFile"); + return result; + } + + } + + /// + /// 根据文件base64打印 (已国产化) + /// + /// + /// + /// + [JSFunction] + public string PrintBase64(string url, string base64, string ext) + { + try + { + if (!isFuncisFuncObject("PrintBase64")) + { + Utils.MessagesBox("打印机设备未授权使用"); + return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "打印机设备未授权使用" + "\"}"; + } + else + { + Task.Run(async () => + { + DateTime dateTime = DateTime.Now; + string time = DateTime.Now.ToString( + "yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo); + string dirpath = System.IO.Directory.GetCurrentDirectory(); + dirpath = dirpath + @"/wwwroot/PrintFile"; + if (!Directory.Exists(dirpath)) + { + Directory.CreateDirectory(dirpath); + } + var filepath = System.IO.Path.Combine(dirpath, time); + string path = dirpath + @"/" + time + "." + ext; + byte[] bytes = Convert.FromBase64String(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); + writer.Close(); + //Log.Info("根据文件base64打印: " + path + ""); + string command = $"lp -d {PrinterName} {path}"; + ShllCommad(command); + }); + string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + "打印成功" + "\"}"; + SubmitLogs(result, "PrintBase64"); + return result; + } + } + catch (Exception ex) + { + string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; + SubmitLogs(result, "PrintBase64"); + return result; + } + } + + /// + /// 播放音频文件 (已国产化) + /// + /// + /// + public static WaveOutEvent player = null; + public static AudioFileReader audioFileReader = null; + public static string WaveOutPath = string.Empty; + [JSFunction] + public string PalyFile(string url, bool ispaly) + { + try + { + if (!isFuncisFuncObject("PalyFile")) + { + Utils.MessagesBox("音频设备未授权使用"); + return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "音频设备未授权使用" + "\"}"; + } + else if (Parame.tcpClient == null) + { + return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "硬件服务未启动" + "\"}"; + } + else + { + if (ispaly) + { + Task.Run(() => + { + Uri uri = new Uri(url); + //返回 123.xlsx + var filename = HttpUtility.UrlDecode(uri.Segments.Last()); + //获取文件后缀 + string ext = System.IO.Path.GetExtension(filename); + DateTime dateTime = DateTime.Now; + string time = DateTime.Now.ToString( + "yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo); + string dirpath = System.IO.Directory.GetCurrentDirectory(); + dirpath = dirpath + @"/wwwroot/WaveOutFile"; + if (!Directory.Exists(dirpath)) + { + Directory.CreateDirectory(dirpath); + } + string path = dirpath + @"/" + time + ext; + WebRequest request = WebRequest.Create(url); + WebResponse response = request.GetResponse(); + using (Stream stream = response.GetResponseStream()) + { + using (FileStream fileStream = new FileStream(path, FileMode.Create)) + { + stream.CopyTo(fileStream); + } + } + response.Close(); + + //开始播放 + string command = $"sox {path} -d"; + ShllCommad(command); + }); + string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":" + "开始播放" + "}"; + SubmitLogs(result, "PalyFile"); + return result; + } + else + { + Task.Run(() => + { + if (Typrocess != null) + { + // 如果进程还在运行 + if (!Typrocess.HasExited) + { + // 发送SIGTERM信号来停止进程 + Typrocess.Kill(); + // 等待进程真正停止 + Typrocess.WaitForExit(); + } + } + }); + string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":" + "停止播放成功" + "}"; + SubmitLogs(result, "PalyFile"); + return result; + } + } + } + catch (Exception ex) + { + string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; + SubmitLogs(result, "PalyFile"); + return result; + } + } + + /// + /// 播放完成 + /// + /// + /// + private void waveOut_PlaybackStopped(object sender, StoppedEventArgs e) + { + try + { + player.Stop(); + // 释放资源 + player.Dispose(); + audioFileReader.Dispose(); + player = null; + File.Delete(WaveOutPath); + //Log.Info("播放完成"); + } + catch (Exception ex) + { + //Log.Info("播放完成,清除本地文件异常" + ex.Message); + } + } + + /// + /// 唤醒键盘 (已国产化) + /// + /// + /// + [JSFunction] + public string openKey(string paramsString) + { + try + { + Task.Run(() => + { + Bash("/usr/bin/python3 /usr/bin/onboard"); + }); + return "{\"message\":\"seccse\",\"code\":\"200\",\"status\":true,\"data\":\"" + "唤醒键盘成功" + "\"}"; + } + catch (Exception ex) + { + Log.Error("唤醒键盘异常: " + ex.Message + ""); + return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; + } + } + + /// + /// 执行文件 + /// + /// + /// + public static string Bash(string command) + { + var escapedArgs = command.Replace("\"", "\\\""); + var process = new Process() + { + StartInfo = new ProcessStartInfo + { + FileName = "/bin/bash", + Arguments = $"-c \"{escapedArgs}\"", + RedirectStandardOutput = true, + UseShellExecute = false, + CreateNoWindow = true, + } + }; + process.Start(); + string result = process.StandardOutput.ReadToEnd(); + process.WaitForExit(); + process.Dispose(); + return result; + } + + /// + /// 获取设备index + /// + /// + public string GetSnIndex() + { + //获取设备信息 + string param = "/GetAllDisplayInfo"; + Task.Run(() => HttpResponse(param)); + @event6.WaitOne(); + if (string.IsNullOrEmpty(gpyStr)) + { + return ""; + } + else + { + JObject jo = (JObject)JsonConvert.DeserializeObject(gpyStr); + if (jo["returnCode"].ToString() == "0") + { + string result = jo["data"].ToString(); + Log.Info(result); + JArray jo1 = (JArray)JsonConvert.DeserializeObject(result); + string devidx = string.Empty; + string name = string.Empty; + foreach (JObject jo2 in jo1) + { + devidx = jo2["dev_idx"].ToString(); + name = jo2["name"].ToString(); + Log.Info(name); + break; + } + return devidx; + } + else + { + Log.Info(jo["returnMsg"].ToString()); + return ""; + } + } + } + + /// + /// 打开高拍仪 + /// + /// + public string OpenSn(string dev_idx) + { + //获取设备信息 + string param = "/StartPreview?dev_idx=" + dev_idx + "&res_id=0"; + Task.Run(() => HttpResponse(param)); + @event6.WaitOne(); + if (string.IsNullOrEmpty(gpyStr)) + { + return ""; + } + else + { + JObject jo = (JObject)JsonConvert.DeserializeObject(gpyStr); + if (jo["returnCode"].ToString() == "0") + { + return "200"; + } + if (jo["returnCode"].ToString() == "2") + { + return "200"; + } + else + { + Log.Info(jo["returnMsg"].ToString()); + return ""; + } + } + } + + /// + /// 关闭高拍仪 + /// + /// + public string StopSn(string dev_idx) + { + //获取设备信息 + string param = "/StopPreview?dev_idx=" + dev_idx; + Task.Run(() => HttpResponse(param)); + @event6.WaitOne(); + if (string.IsNullOrEmpty(gpyStr)) + { + return ""; + } + else + { + JObject jo = (JObject)JsonConvert.DeserializeObject(gpyStr); + if (jo["returnCode"].ToString() == "0") + { + return "200"; + } + else + { + Log.Info(jo["returnMsg"].ToString()); + return ""; + } + } + } + + /// + /// 拍照 + /// + /// + public string getFrame() + { + //获取设备信息 + string param = "/getFrame"; + Task.Run(() => HttpResponse(param)); + @event6.WaitOne(); + if (string.IsNullOrEmpty(gpyStr)) + { + return ""; + } + else + { + JObject jo = (JObject)JsonConvert.DeserializeObject(gpyStr); + if (jo["returnCode"].ToString() == "0") + { + string result = jo["data"].ToString(); + JObject jo1 = (JObject)JsonConvert.DeserializeObject(result); + return jo1["img"].ToString(); + } + else + { + Log.Info(jo["returnMsg"].ToString()); + return ""; + } + } + } + + /// + /// 右转 + /// + /// + public string RotateRight() + { + //获取设备信息 + string param = "/rotate/right"; + Task.Run(() => HttpResponse(param)); + @event6.WaitOne(); + if (string.IsNullOrEmpty(gpyStr)) + { + return ""; + } + else + { + JObject jo = (JObject)JsonConvert.DeserializeObject(gpyStr); + if (jo["returnCode"].ToString() == "0") + { + return "200"; + } + else + { + Log.Info(jo["returnMsg"].ToString()); + return ""; + } + } + } + + /// + /// 左转 + /// + /// + public string RotateLeft() + { + //获取设备信息 + string param = "/rotate/left"; + Task.Run(() => HttpResponse(param)); + @event6.WaitOne(); + if (string.IsNullOrEmpty(gpyStr)) + { + return ""; + } + else + { + JObject jo = (JObject)JsonConvert.DeserializeObject(gpyStr); + if (jo["returnCode"].ToString() == "0") + { + return "200"; + } + else + { + Log.Info(jo["returnMsg"].ToString()); + return ""; + } + } + } + + /// + /// 高拍仪 + /// + private string gpyStr = string.Empty; + private AutoResetEvent @event6 = new AutoResetEvent(false); + private async void HttpResponse(string param) + { + var httpClient = new HttpClient(); + var uploader = new ChunkedUpload(httpClient); + gpyStr = await uploader.getReq(param); + @event6.Set(); + } + + /// + /// 签字版 + /// + private async void HttpPostResponseBySign(string type, int typeCode, string callback) + { + var httpClient = new HttpClient(); + var uploader = new ChunkedUpload(httpClient); + await uploader.PostSign(type, typeCode, callback); + } + + /// + /// 初始文件上传 + /// + private string urlpath = string.Empty; + private AutoResetEvent @event2 = new AutoResetEvent(false); + private async void UploadInfo(string url, string srpath) + { + var httpClient = new HttpClient(); + var uploader = new ChunkedUpload(httpClient); + urlpath = await uploader.UploadFileAsync(url, srpath); + @event2.Set(); + } + + //上传本地文件中转 + private string urlP = string.Empty; + private AutoResetEvent @event5 = new AutoResetEvent(false); + private async void UploadInfoByFile(string url, string strpath) + { + var httpClient = new HttpClient(); + var uploader = new ChunkedUpload(httpClient); + urlP = await uploader.UploadFileAsync(url, strpath); + File.Delete(strpath); + @event5.Set(); + } + + /// + /// string 转换为 base64 + /// + /// + public static string str2Base64(string str) + { + byte[] b = System.Text.Encoding.UTF8.GetBytes(str); + string result = Convert.ToBase64String(b); + return result; + } + + /// + /// base64 转换为 string + /// + /// + public static string Base64str2(string data) + { + byte[] c = Convert.FromBase64String(data); + string result = System.Text.Encoding.UTF8.GetString(c); + //Log.Info("接收返回数据:" + result); + return result; + } + + //根据程序名称杀死进程 + public static void KillProcessByName(string processName) + { + Process[] processes = Process.GetProcessesByName(processName); + + foreach (Process process in processes) + { + try + { + process.Kill(); + process.WaitForExit(); // 等待进程退出 + } + catch (Exception ex) { } + } + } + + /// + /// 开始录音 + /// + /// + public bool StartRecording() + { + try + { + if (recordingProcess != null) + { + // 如果进程还在运行 + if (!recordingProcess.HasExited) + { + // 发送SIGTERM信号来停止arecord进程 + recordingProcess.Kill(); + recordingProcess.WaitForExit(); // 等待进程真正停止 + } + } + string time = DateTime.Now.ToString( + "yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo); + string dirpath = System.IO.Directory.GetCurrentDirectory(); + dirpath = dirpath + @"/wwwroot/Record"; + if (!Directory.Exists(dirpath)) + { + Directory.CreateDirectory(dirpath); + } + srpath = dirpath + "/" + time + ".wav"; + string outputFile = srpath; // 输出文件名 + string device = "default"; // 音频设备,可以通过arecord -l来列出所有设备 + // 构建arecord命令 + string command = $"arecord --device={device} --file-type=wav --duration=10 --quiet {outputFile}"; + // 启动进程 + recordingProcess = new Process + { + StartInfo = new ProcessStartInfo + { + FileName = "/bin/bash", + Arguments = $"-c \"{command}\"", + UseShellExecute = false, + RedirectStandardOutput = true, + RedirectStandardError = true + } + }; + recordingProcess.Start(); + return true; + } + catch (Exception ex) + { + Log.Error("开始录音异常:" + ex.Message); + return false; + } + } + + /// + /// 结束录音 + /// + public bool StopRecording() + { + try + { + // 如果进程还在运行 + if (!recordingProcess.HasExited) + { + // 发送SIGTERM信号来停止arecord进程 + recordingProcess.Kill(); + recordingProcess.WaitForExit(); // 等待进程真正停止 + } + return true; + } + catch (Exception ex) + { + Log.Error("结束录音异常:" + ex.Message); + return false; + } + } + + /// + /// 执行命令 + /// + public static void ShllCommad(string command) + { + //Log.Info("执行命令:" + command); + // 启动进程 + Typrocess = new Process + { + StartInfo = new ProcessStartInfo + { + FileName = "/bin/bash", + Arguments = $"-c \"{command}\"", + UseShellExecute = false, + RedirectStandardOutput = true, + RedirectStandardError = true, + CreateNoWindow = true + } + }; + Typrocess.Start(); + Typrocess.WaitForExit(); + } + + /// + /// 开源文字转语音 + /// sudo apt-get install espeak + /// + /// + /// + static string GenerateWavFromText(string text) + { + string time = DateTime.Now.ToString( + "yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo); + string dirpath = System.IO.Directory.GetCurrentDirectory(); + dirpath = dirpath + @"/wwwroot/WavFile"; + if (!Directory.Exists(dirpath)) + { + Directory.CreateDirectory(dirpath); + } + var tempFile = dirpath + "/" + time + ".wav"; + text = text.Replace("(", "").Replace(")", "、"); + ProcessStartInfo startInfo = new ProcessStartInfo + { + FileName = "espeak", + Arguments = $" -vzh -s 150 \"{text}\" -w {tempFile}", // 设置语速为150,输出为WAV文件 + UseShellExecute = false, + RedirectStandardOutput = true, + CreateNoWindow = true + }; + using (Process process = Process.Start(startInfo)) + { + process.WaitForExit(); // 等待进程结束 + process.Close(); + process.Dispose(); + } + return tempFile; + } + + /// + /// 是否已获取收取 + /// + /// + /// + public bool isFuncisFuncObject(string funcName) + { + bool isFunc = false; + if (Parame.FuncObject.Count > 0) + { + foreach (Func func in Parame.FuncObject) + { + if (func.Interfaceaddress.Contains(funcName)) + { + isFunc = true; + break; + } + } + } + return isFunc; + } + + /// + /// 提交设备操作日志 + /// + /// + /// + public static void SubmitLogs(string Describer, string funcName) + { + Task.Run(async () => + { + string ApiId = string.Empty; + string Name = string.Empty; + string Interfaceaddress = string.Empty; + bool isFunc = false; + if (Parame.FuncObject != null) + { + if (Parame.FuncObject.Count > 0) + { + foreach (Func func in Parame.FuncObject) + { + if (func.Interfaceaddress.Contains(funcName)) + { + isFunc = true; + ApiId = func.Id; + Name = func.Platform; + Interfaceaddress = func.Interfaceaddress; + break; + } + } + } + } + if (isFunc) + { + var client = new HttpClient(); + var request = new HttpRequestMessage(HttpMethod.Post, $"{Parame.apiUrl}/api/Interface/JournalAdd"); + var content = new StringContent("{\"Name\": \"" + Name + "\",\"Describer\": \"" + str2Base64(Describer) + "\", \"Interfaceaddress\": \"" + Interfaceaddress + "\", \"ApiId\": \"" + ApiId + "\"}", null, "application/json"); + request.Content = content; + var response = await client.SendAsync(request); + if (response.StatusCode.ToString() == "200") + { + response.EnsureSuccessStatusCode(); + var body = await response.Content.ReadAsStringAsync(); + //Log.Info(body); + } + } + }); + } + } +} diff --git a/CPF_Cef/MainModel.cs b/CPF_Cef/MainModel.cs index 1c520fd..d72a300 100644 --- a/CPF_Cef/MainModel.cs +++ b/CPF_Cef/MainModel.cs @@ -1,86 +1,212 @@ using AksWebBrowser; using AksWebBrowser.Common; +using AksWebBrowser.Devices; using AKSWebBrowser.Commen; -using AKSWebBrowser.Common; -using CPF.Cef; -using CPF.Mac.AppKit; -using DevicesService.Devices; -using NAudio.Wave; -using NAudio.Wave.SampleProviders; -using Newtonsoft.Json.Linq; using Newtonsoft.Json; -using SkiaSharp; +using Newtonsoft.Json.Linq; using System; -using System.Buffers.Text; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Net; using System.Net.Http; -using System.Net.Http.Headers; -using System.Net.Sockets; +using System.Text; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using System.Web; -using System.Xml.Linq; -using static System.Net.Mime.MediaTypeNames; -using AksWebBrowser.Devices; -using System.Reflection; namespace AKS.EnterpriseLibrary.WebBrowser { public class MainModel : CPF.CpfObject { - public string callback = string.Empty; - public string PrinterName = "Lexmark-MS430-Series"; + + //初始化网络连接 + public static void DeviceControllerInit() + { + SAEA.WebSocket.WSServer ws = new SAEA.WebSocket.WSServer(19983); + ws.OnConnected += (s) => + { + byte[] bytes = SerializeContent("连接成功"); + ws.Reply(s.ToString(), new SAEA.WebSocket.Model.WSProtocal(SAEA.WebSocket.Type.WSProtocalType.Text, bytes)); + }; + ws.OnMessage += (s, e) => + { + string content = Encoding.UTF8.GetString(e.Content); + var json = content.ConvertToAnonymousType(new + { + code = default(string) + }); + //接收指令和参数 + string keycode = json.code; + //返回内容 + string result = string.Empty; + 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); + break; + //aks100104 + //打开高拍仪并且进行快速扫描文件 {"code":"aks100104"} + case "aks100104": + result = openCamera(keycode); + break; + //aks100105 + //打开签字版 {"code":"aks100105"} + case "aks100105": + result = OpenSign(content); + 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); + 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); + break; + //aks100110 播放音频文件 {"code":"aks100110"} + case "aks100110": + result = PalyFile(content); + break; + //aks100111 唤醒键盘 {"code":"aks100111"} + case "aks100111": + result = openKey(keycode); + break; + //aks100113 指纹 {"code":"aks100113"} + case "aks100113": + result = ReadFingerData(keycode); + break; + default: + result = "{\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"无效指令\"}"; + break; + } + //答复请求者(处理完请求后在些答复) + byte[] bytes = SerializeContent(result); + ws.Reply(s.ToString(), new SAEA.WebSocket.Model.WSProtocal(SAEA.WebSocket.Type.WSProtocalType.Text, bytes)); + }; + ws.Start(); + } + + //解包 + private static string DeserializeContent(byte[] param) + { + try + { + return Encoding.UTF8.GetString(param); + } + catch + { + return "参数无效"; + } + } + //封包 + private static byte[] SerializeContent(string param) + { + try + { + return Encoding.UTF8.GetBytes(param); + } + catch + { + return null; + //return "参数无效"; + } + } + + public static string callback = string.Empty; + public static string PrinterName = "Lexmark-MS430-Series"; public static Process recordingProcess; public static Process Typrocess; - private string srpath = string.Empty; + private static string srpath = string.Empty; /// - /// 读取身份证卡号(已国产化) + /// aks100101 读取身份证卡号(已国产化) /// /// /// - [JSFunction] - public string IDCardRead(string paramsString) + public static string IDCardRead(string code) { try { //Finger("",""); IDCard iDCard = new IDCard(); - string result = iDCard.getIdCard(); + string result = iDCard.getIdCard(code); SubmitLogs(result, "IDCardRead"); return result; } catch (Exception ex) { Log.Error("读取身份证卡号异常: " + ex.Message + ""); - string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; + string result = "{\"keycode\":\"" + code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; SubmitLogs(result, "IDCardRead"); return result; } } /// - /// 打印排队票据(已国产化) + /// aks100102 打印排队票据(已国产化) /// /// 排号 /// 等待人数 /// 二维码 /// 办理业务名称 /// - [JSFunction] - public string SendByPrint(string ph, string ddrs, string qrcode, string ywmc) + public static string SendByPrint(string content) { + var param = content.ConvertToAnonymousType(new + { + code = default(string), + ph = default(string), + ddrs = default(string), + qrcode = default(string), + ywmc = default(string) + }); try { + + string ph = param.ph; + string ddrs = param.ddrs; + string qrcode = param.qrcode; + string ywmc = param.ywmc; + if (!isFuncisFuncObject("SendByPrint")) { Utils.MessagesBox("打印排队票据设备未授权使用"); - return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "打印排队票据设备未授权使用" + "\"}"; + return "{\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "打印排队票据设备未授权使用" + "\"}"; } else { @@ -88,13 +214,13 @@ namespace AKS.EnterpriseLibrary.WebBrowser var data = print.SendPrint(ph, ddrs, qrcode, ywmc); if (data == 0) { - string result = "{\"message\":\"seccse\",\"code\":\"200\",\"status\":true,\"data\":\"" + "打印成功" + "\"}"; + string result = "{\"keycode\":\"" + param.code + "\",\"message\":\"seccse\",\"code\":\"200\",\"status\":true,\"data\":\"" + "打印成功" + "\"}"; SubmitLogs(result, "SendByPrint"); return result; } else { - string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + (data == 1 ? "打印失败" : (data == 2 ? "打印机未连接" : "打印机初始化失败")) + "\"}"; + string result = "{\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + (data == 1 ? "打印失败" : (data == 2 ? "打印机未连接" : "打印机初始化失败")) + "\"}"; SubmitLogs(result, "SendByPrint"); return result; } @@ -103,7 +229,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser catch (Exception ex) { Log.Error("打印排队票据异常: " + ex.Message + ""); - string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; + string result = "{\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; SubmitLogs(result, "SendByPrint"); return result; } @@ -117,17 +243,29 @@ namespace AKS.EnterpriseLibrary.WebBrowser /// /// /// - public WaveOutEvent playerTxt = null; public static string tempWav = string.Empty; - [JSFunction] - public string payleText(string text, bool ispaye) + /// + /// aks100103文字语音播报 + /// + /// + /// + public static string payleText(string content) { + var param = content.ConvertToAnonymousType(new + { + code = default(string), + text = default(string), + ispaye = default(bool), + }); + try { + string text = param.text; + bool ispaye = param.ispaye; if (!isFuncisFuncObject("payleText")) { Utils.MessagesBox("文字语音播报设备未授权使用"); - return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "文字语音播报设备未授权使用" + "\"}"; + return "{\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "文字语音播报设备未授权使用" + "\"}"; } else { @@ -147,7 +285,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser } } }); - string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":" + "停止播放成功" + "}"; + string result = "{\"keycode\":\"" + param.code + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":" + "停止播放成功" + "}"; SubmitLogs(result, "payleText"); return result; } @@ -161,7 +299,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser string command = $"sox {tempWav} -d"; ShllCommad(command); }); - string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":" + "开始播放" + "}"; + string result = "{\"keycode\":\"" + param.code + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":" + "开始播放" + "}"; SubmitLogs(result, "payleText"); return result; } @@ -170,26 +308,25 @@ namespace AKS.EnterpriseLibrary.WebBrowser catch (Exception ex) { Log.Error("文字语音播报异常2: " + ex.Message + ""); - string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; + string result = "{\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; SubmitLogs(result, "payleText"); return result; } } /// - /// 打开高拍仪并且进行快速扫描文件 (已国产化) + /// aks100104打开高拍仪并且进行快速扫描文件 (已国产化) /// /// /// - [JSFunction] - public string openCamera(string url) + public static string openCamera(string code) { try { string devIndex = GetSnIndex(); if (string.IsNullOrEmpty(devIndex)) { - string result = "{\"callback\":\"" + callback + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"suffix\":\"jpg\",\"data\":\"" + "扫描仪打开失败" + "\"}"; + string result = "{\"keycode\":\"" + code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"suffix\":\"jpg\",\"data\":\"" + "扫描仪打开失败" + "\"}"; SubmitLogs(result, "openCamera"); return result; } @@ -199,7 +336,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser string param = OpenSn(devIndex); if (string.IsNullOrEmpty(param)) { - string result = "{\"callback\":\"" + callback + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"suffix\":\"jpg\",\"data\":\"" + "扫描仪打开失败" + "\"}"; + string result = "{\"keycode\":\"" + code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"suffix\":\"jpg\",\"data\":\"" + "扫描仪打开失败" + "\"}"; SubmitLogs(result, "openCamera"); return result; } @@ -209,7 +346,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser param = getFrame(); if (string.IsNullOrEmpty(param)) { - string result = "{\"callback\":\"" + callback + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"suffix\":\"jpg\",\"data\":\"" + "获取图片失败" + "\"}"; + string result = "{\"keycode\":\"" + code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"suffix\":\"jpg\",\"data\":\"" + "获取图片失败" + "\"}"; SubmitLogs(result, "openCamera"); return result; } @@ -220,7 +357,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser //关闭 StopSn(devIndex); }); - string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"jpg\",\"data\":\"" + param + "\"}"; + string result = "{\"keycode\":\"" + code + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"jpg\",\"data\":\"" + param + "\"}"; SubmitLogs(result, "openCamera"); return result; } @@ -231,39 +368,42 @@ namespace AKS.EnterpriseLibrary.WebBrowser catch (Exception ex) { Log.Error("打开高拍仪并且进行快速扫描文件异常: " + ex.Message + ""); - string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; + string result = "{\"keycode\":\"" + code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; SubmitLogs(result, "openCamera"); return result; } } /// - /// 打开签字版 sudo apt-get install libgdiplus (已国产化) + /// aks100105打开签字版 sudo apt-get install libgdiplus (已国产化) /// /// /// - [JSFunction] - public string OpenSign(string paramsString, string callback) + public static string OpenSign(string content) { + var param = content.ConvertToAnonymousType(new + { + code = default(string) + }); try { if (!isFuncisFuncObject("OpenSign")) { Utils.MessagesBox("签字版设备未授权使用"); - return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "签字版设备未授权使用" + "\"}"; + return "{\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "签字版设备未授权使用" + "\"}"; } else { - Task.Run(() => HttpPostResponseBySign("open", 1, callback)); - string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"jpg\",\"data\":\"" + "签字版已打开" + "\"}"; - SubmitLogs(result, "openCamera"); + Task.Run(() => { HttpPostResponseBySign("open", 1, param.code); event2.WaitOne(); }); + string result = sginStr; + SubmitLogs(result, "OpenSign"); return result; } } catch (Exception ex) { Log.Error("打开签字版异常: " + ex.Message + ""); - string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; + string result = "{\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; SubmitLogs(result, "OpenSign"); return result; } @@ -274,20 +414,19 @@ namespace AKS.EnterpriseLibrary.WebBrowser /// /// /// - [JSFunction] - public string CloseSign(string paramsString) + private static string CloseSign(string code) { try { if (!isFuncisFuncObject("OpenSign")) { Utils.MessagesBox("签字版设备未授权使用"); - return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "签字版设备未授权使用" + "\"}"; + return "{\"keycode\":\"" + code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "签字版设备未授权使用" + "\"}"; } else { Task.Run(() => HttpPostResponseBySign("close", 2, "")); - string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"jpg\",\"data\":\"" + "签字版已关闭" + "\"}"; + string result = "{\"keycode\":\"" + code + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"jpg\",\"data\":\"" + "签字版已关闭" + "\"}"; SubmitLogs(result, "openCamera"); return result; } @@ -295,31 +434,30 @@ namespace AKS.EnterpriseLibrary.WebBrowser catch (Exception ex) { Log.Error("关闭签字版异常: " + ex.Message + ""); - string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; + string result = "{\"keycode\":\"" + code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; SubmitLogs(result, "OpenSign"); return result; } } /// - /// 指纹 (已国产化,未完成测试) + /// aks100106指纹 (已国产化,未完成测试) /// /// /// - [JSFunction] - public string ReadFingerData(string callback) + public static string ReadFingerData(string code) { try { if (false)//!isFuncisFuncObject("Finger") { Utils.MessagesBox("指纹设备未授权使用"); - return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "指纹设备未授权使用" + "\"}"; + return "{\"keycode\":\"" + code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "指纹设备未授权使用" + "\"}"; } else { - string result = Fingerprint.LIVESCANFinger(callback); + string result = Fingerprint.LIVESCANFinger(code); SubmitLogs(result, "Finger"); return result; } @@ -327,29 +465,38 @@ namespace AKS.EnterpriseLibrary.WebBrowser catch (Exception ex) { Log.Error("指纹异常: " + ex.Message + ""); - string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; + string result = "{\"keycode\":\"" + code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; SubmitLogs(result, "Finger"); return result; } } /// - /// 开始录音、取消录音、结束录音 (已国产化) + /// aks100107开始录音、取消录音、结束录音 (已国产化) /// sudo apt-get update /// sudo apt-get install alsa-utils /// /// /// /// - [JSFunction] - public string SoundRecording(bool isopen, string url) + public static string SoundRecording(string content) { + var param = content.ConvertToAnonymousType(new + { + code = default(string), + isopen = default(bool), + url = default(string) + }); + try { + + bool isopen = param.isopen; + string url = param.url; if (!isFuncisFuncObject("SoundRecording")) { Utils.MessagesBox("录音设备未授权使用"); - return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "录音设备未授权使用" + "\"}"; + return "{\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "录音设备未授权使用" + "\"}"; } else { @@ -366,13 +513,13 @@ namespace AKS.EnterpriseLibrary.WebBrowser Regex re = new Regex(@"(((?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(:[0-9]+)?|(?:ww‌​w.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?‌​(?:[\w]*))?)"); MatchCollection mc = re.Matches(url);//获取的是一个数组 string reurl = mc[0].ToString() + "://" + mc[1].ToString() + urlpath; - string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"wav\",\"data\":\"" + reurl + "\"}"; + string result = "{\"keycode\":\"" + param.code + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"wav\",\"data\":\"" + reurl + "\"}"; SubmitLogs(result, "SoundRecording"); return result; } else { - string result = "{\"callback\":\"" + callback + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"suffix\":\"wav\",\"data\":\"" + "结束录音失败" + "\"}"; + string result = "{\"keycode\":\"" + param.code + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"suffix\":\"wav\",\"data\":\"" + "结束录音失败" + "\"}"; SubmitLogs(result, "SoundRecording"); return result; } @@ -381,13 +528,13 @@ namespace AKS.EnterpriseLibrary.WebBrowser { if (StartRecording()) { - string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"wav\",\"data\":\"" + "开始录音" + "\"}"; + string result = "{\"keycode\":\"" + param.code + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"wav\",\"data\":\"" + "开始录音" + "\"}"; SubmitLogs(result, "SoundRecording"); return result; } else { - string result = "{\"callback\":\"" + callback + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"suffix\":\"wav\",\"data\":\"" + "录音失败" + "\"}"; + string result = "{\"keycode\":\"" + param.code + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"suffix\":\"wav\",\"data\":\"" + "录音失败" + "\"}"; SubmitLogs(result, "SoundRecording"); return result; } @@ -397,14 +544,14 @@ namespace AKS.EnterpriseLibrary.WebBrowser if (StopRecording()) { srpath = string.Empty; - string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"wav\",\"data\":\"" + "取消录音" + "\"}"; + string result = "{\"keycode\":\"" + param.code + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"wav\",\"data\":\"" + "取消录音" + "\"}"; SubmitLogs(result, "SoundRecording"); return result; } else { srpath = string.Empty; - string result = "{\"callback\":\"" + callback + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"suffix\":\"wav\",\"data\":\"" + "取消录音失败" + "\"}"; + string result = "{\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"suffix\":\"wav\",\"data\":\"" + "取消录音失败" + "\"}"; SubmitLogs(result, "SoundRecording"); return result; } @@ -415,26 +562,34 @@ namespace AKS.EnterpriseLibrary.WebBrowser catch (Exception ex) { Log.Error("开始录音、取消录音、结束录音异常: " + ex.Message + ""); - string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; + string result = "{\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; SubmitLogs(result, "SoundRecording"); return result; } } /// - /// 根据文件地址在线打印 (已国产化) + /// aks100108根据文件地址在线打印 (已国产化) /// /// /// - [JSFunction] - public string PrintFile(string url, string ext) + public static string PrintFile(string content) { + var param = content.ConvertToAnonymousType(new + { + code = default(string), + url = default(string), + ext = default(string) + }); try { + + string url = param.url; + string ext = param.ext; if (!isFuncisFuncObject("PrintFile")) { Utils.MessagesBox("打印机设备未授权使用"); - return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "打印机设备未授权使用" + "\"}"; + return "{\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "打印机设备未授权使用" + "\"}"; } else { @@ -465,7 +620,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser string command = $"lp -d {PrinterName} {path}"; ShllCommad(command); }); - string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + "打印成功" + "\"}"; + string result = "{\"keycode\":\"" + param.code + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + "打印成功" + "\"}"; SubmitLogs(result, "PrintFile"); return result; } @@ -473,7 +628,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser catch (Exception ex) { Log.Error("根据文件地址在线打印异常: " + ex.Message + ""); - string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; + string result = "{\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; SubmitLogs(result, "PrintFile"); return result; } @@ -481,20 +636,28 @@ namespace AKS.EnterpriseLibrary.WebBrowser } /// - /// 根据文件base64打印 (已国产化) + /// aks100109根据文件base64打印 (已国产化)PrintBase64 /// /// /// /// - [JSFunction] - public string PrintBase64(string url, string base64, string ext) + public static string PrintBase64(string content) { + var param = content.ConvertToAnonymousType(new + { + code = default(string), + ext = default(string), + base64 = default(string) + }); try { + string base64 = param.base64; + string ext = param.ext; + if (!isFuncisFuncObject("PrintBase64")) { Utils.MessagesBox("打印机设备未授权使用"); - return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "打印机设备未授权使用" + "\"}"; + return "{\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "打印机设备未授权使用" + "\"}"; } else { @@ -520,40 +683,41 @@ namespace AKS.EnterpriseLibrary.WebBrowser string command = $"lp -d {PrinterName} {path}"; ShllCommad(command); }); - string result = "{\"callback\":\"" + callback + "\",\"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 = "{\"message\":\"fali\",\"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; } } - /// - /// 播放音频文件 (已国产化) + /// + /// aks100110播放音频文件 (已国产化) /// - /// + /// + /// /// - public static WaveOutEvent player = null; - public static AudioFileReader audioFileReader = null; - public static string WaveOutPath = string.Empty; - [JSFunction] - public string PalyFile(string url, bool ispaly) + public static string PalyFile(string content) { + var param = content.ConvertToAnonymousType(new + { + code = default(string), + url = default(string), + ispaly = default(bool) + }); try { + string url = param.url; + bool ispaly = param.ispaly; if (!isFuncisFuncObject("PalyFile")) { Utils.MessagesBox("音频设备未授权使用"); - return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "音频设备未授权使用" + "\"}"; - } - else if (Parame.tcpClient == null) - { - return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "硬件服务未启动" + "\"}"; + return "{\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "音频设备未授权使用" + "\"}"; } else { @@ -591,7 +755,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser string command = $"sox {path} -d"; ShllCommad(command); }); - string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":" + "开始播放" + "}"; + string result = "{\"keycode\":\"" + param.code + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":" + "开始播放" + "}"; SubmitLogs(result, "PalyFile"); return result; } @@ -611,7 +775,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser } } }); - string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":" + "停止播放成功" + "}"; + string result = "{\"keycode\":\"" + param.code + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":" + "停止播放成功" + "}"; SubmitLogs(result, "PalyFile"); return result; } @@ -619,42 +783,18 @@ namespace AKS.EnterpriseLibrary.WebBrowser } catch (Exception ex) { - string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; + string result = "{\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; SubmitLogs(result, "PalyFile"); return result; } } /// - /// 播放完成 - /// - /// - /// - private void waveOut_PlaybackStopped(object sender, StoppedEventArgs e) - { - try - { - player.Stop(); - // 释放资源 - player.Dispose(); - audioFileReader.Dispose(); - player = null; - File.Delete(WaveOutPath); - //Log.Info("播放完成"); - } - catch (Exception ex) - { - //Log.Info("播放完成,清除本地文件异常" + ex.Message); - } - } - - /// - /// 唤醒键盘 (已国产化) + /// aks100111唤醒键盘 (已国产化) /// /// /// - [JSFunction] - public string openKey(string paramsString) + public static string openKey(string code) { try { @@ -662,12 +802,12 @@ namespace AKS.EnterpriseLibrary.WebBrowser { Bash("/usr/bin/python3 /usr/bin/onboard"); }); - return "{\"message\":\"seccse\",\"code\":\"200\",\"status\":true,\"data\":\"" + "唤醒键盘成功" + "\"}"; + return "{\"keycode\":\"" + code + "\",\"message\":\"seccse\",\"code\":\"200\",\"status\":true,\"data\":\"" + "唤醒键盘成功" + "\"}"; } catch (Exception ex) { Log.Error("唤醒键盘异常: " + ex.Message + ""); - return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; + return "{\"keycode\":\"" + code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; } } @@ -701,7 +841,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser /// 获取设备index /// /// - public string GetSnIndex() + public static string GetSnIndex() { //获取设备信息 string param = "/GetAllDisplayInfo"; @@ -742,7 +882,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser /// 打开高拍仪 /// /// - public string OpenSn(string dev_idx) + public static string OpenSn(string dev_idx) { //获取设备信息 string param = "/StartPreview?dev_idx=" + dev_idx + "&res_id=0"; @@ -775,7 +915,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser /// 关闭高拍仪 /// /// - public string StopSn(string dev_idx) + public static string StopSn(string dev_idx) { //获取设备信息 string param = "/StopPreview?dev_idx=" + dev_idx; @@ -804,7 +944,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser /// 拍照 /// /// - public string getFrame() + public static string getFrame() { //获取设备信息 string param = "/getFrame"; @@ -835,7 +975,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser /// 右转 /// /// - public string RotateRight() + public static string RotateRight() { //获取设备信息 string param = "/rotate/right"; @@ -864,7 +1004,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser /// 左转 /// /// - public string RotateLeft() + public static string RotateLeft() { //获取设备信息 string param = "/rotate/left"; @@ -892,9 +1032,9 @@ namespace AKS.EnterpriseLibrary.WebBrowser /// /// 高拍仪 /// - private string gpyStr = string.Empty; - private AutoResetEvent @event6 = new AutoResetEvent(false); - private async void HttpResponse(string param) + private static string gpyStr = string.Empty; + private static AutoResetEvent @event6 = new AutoResetEvent(false); + private static async void HttpResponse(string param) { var httpClient = new HttpClient(); var uploader = new ChunkedUpload(httpClient); @@ -902,22 +1042,24 @@ namespace AKS.EnterpriseLibrary.WebBrowser @event6.Set(); } + private static string sginStr = string.Empty; /// /// 签字版 /// - private async void HttpPostResponseBySign(string type, int typeCode, string callback) + private static async void HttpPostResponseBySign(string type, int typeCode, string code) { var httpClient = new HttpClient(); var uploader = new ChunkedUpload(httpClient); - await uploader.PostSign(type, typeCode, callback); + sginStr = await uploader.PostSign(type, typeCode, code); + @event2.Set(); } /// /// 初始文件上传 /// - private string urlpath = string.Empty; - private AutoResetEvent @event2 = new AutoResetEvent(false); - private async void UploadInfo(string url, string srpath) + private static string urlpath = string.Empty; + private static AutoResetEvent @event2 = new AutoResetEvent(false); + private static async void UploadInfo(string url, string srpath) { var httpClient = new HttpClient(); var uploader = new ChunkedUpload(httpClient); @@ -926,9 +1068,9 @@ namespace AKS.EnterpriseLibrary.WebBrowser } //上传本地文件中转 - private string urlP = string.Empty; - private AutoResetEvent @event5 = new AutoResetEvent(false); - private async void UploadInfoByFile(string url, string strpath) + private static string urlP = string.Empty; + private static AutoResetEvent @event5 = new AutoResetEvent(false); + private static async void UploadInfoByFile(string url, string strpath) { var httpClient = new HttpClient(); var uploader = new ChunkedUpload(httpClient); @@ -980,7 +1122,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser /// 开始录音 /// /// - public bool StartRecording() + public static bool StartRecording() { try { @@ -1032,7 +1174,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser /// /// 结束录音 /// - public bool StopRecording() + public static bool StopRecording() { try { @@ -1115,7 +1257,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser /// /// /// - public bool isFuncisFuncObject(string funcName) + public static bool isFuncisFuncObject(string funcName) { bool isFunc = false; if (Parame.FuncObject.Count > 0)