From 1986a7da66ca2861ab803b07400e1348246f7076 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=BD=87=E9=98=B3?= Date: Tue, 21 May 2024 10:33:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E5=AF=B9=E6=8E=A5=E7=BA=BF?= =?UTF-8?q?=E7=A1=AC=E4=BB=B6=E5=AF=B9=E6=8E=A5=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CPF_Cef/Common/Log.cs | 22 ++-- CPF_Cef/Common/TcpClients.cs | 215 +++++++++++++++++++++++++++++++++++ CPF_Cef/Common/Utils.cs | 21 ++++ CPF_Cef/FrmMain.cs | 19 ++-- CPF_Cef/MainModel.cs | 204 ++++++++++++++++----------------- CPF_Cef/Parame.cs | 2 + CPF_Cef/Program.cs | 16 +-- 7 files changed, 373 insertions(+), 126 deletions(-) create mode 100644 CPF_Cef/Common/TcpClients.cs diff --git a/CPF_Cef/Common/Log.cs b/CPF_Cef/Common/Log.cs index adc6668..4d6f69f 100644 --- a/CPF_Cef/Common/Log.cs +++ b/CPF_Cef/Common/Log.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace AKSWebBrowser.Commen { - public class Log + public class Log { private static StreamWriter streamWriter; //写文件 @@ -24,7 +24,7 @@ namespace AKSWebBrowser.Commen directPath += string.Format(@"/{0}.log", DateTime.Now.ToString("yyyy-MM-dd")); if (streamWriter == null) { - streamWriter = !File.Exists(directPath) ? File.CreateText(directPath) : File.AppendText(directPath); + streamWriter = !File.Exists(directPath) ? File.CreateText(directPath) : File.AppendText(directPath); } streamWriter.WriteLine("***********************************************************************"); streamWriter.WriteLine(DateTime.Now.ToString("HH:mm:ss")); @@ -34,13 +34,17 @@ namespace AKSWebBrowser.Commen streamWriter.WriteLine("异常信息:\r\n" + message); } } + catch { } finally { if (streamWriter != null) { streamWriter.Flush(); - streamWriter.Dispose(); - streamWriter = null; + if (streamWriter != null) + { + streamWriter.Dispose(); + streamWriter = null; + } } } } @@ -58,7 +62,7 @@ namespace AKSWebBrowser.Commen directPath += string.Format(@"/{0}.log", DateTime.Now.ToString("yyyy-MM-dd")); if (streamWriter == null) { - streamWriter = !File.Exists(directPath) ? File.CreateText(directPath) : File.AppendText(directPath); + try { streamWriter = !File.Exists(directPath) ? File.CreateText(directPath) : File.AppendText(directPath); } catch { } finally { } } streamWriter.WriteLine("***********************************************************************"); streamWriter.WriteLine(DateTime.Now.ToString("HH:mm:ss")); @@ -68,13 +72,17 @@ namespace AKSWebBrowser.Commen streamWriter.WriteLine("信息:\r\n" + message); } } + catch { } finally { if (streamWriter != null) { streamWriter.Flush(); - streamWriter.Dispose(); - streamWriter = null; + if (streamWriter != null) + { + streamWriter.Dispose(); + streamWriter = null; + } } } } diff --git a/CPF_Cef/Common/TcpClients.cs b/CPF_Cef/Common/TcpClients.cs new file mode 100644 index 0000000..d64dbc0 --- /dev/null +++ b/CPF_Cef/Common/TcpClients.cs @@ -0,0 +1,215 @@ +using AKSWebBrowser.Commen; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Sockets; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Net; +using System.Net.Http; +using System.IO.Ports; +using System.Timers; + +namespace AksWebBrowser.Common +{ + public class TcpClients + { + public string jsonstr = string.Empty; + /// + /// 打开连接 + /// + public TcpClients() + { + try + { + //初始化连接 192.168.1.166 + Parame.tcpClient = new TcpClient("127.0.0.1", 1234); + NetworkStream stream = Parame.tcpClient.GetStream(); + Task.Factory.StartNew(() => { Write(stream); }); + ThreadPool.QueueUserWorkItem(SendInstruction, Parame.tcpClient); + } + catch (Exception ex) { Console.WriteLine(ex.Message); } + finally { + //开启定时 + System.Timers.Timer timer = new System.Timers.Timer(3000);//3秒钟的时间间隔 + timer.Elapsed += OnTimedEvent; + timer.AutoReset = true;//重复执行 + timer.Enabled = true;//启动定时器 + } + } + + + //打开串口 + private void OnTimedEvent(Object source, ElapsedEventArgs e) + { + try + { + if (Parame.tcpClient == null) + { + Parame.tcpClient = new TcpClient("127.0.0.1", 1234); + NetworkStream stream = Parame.tcpClient.GetStream(); + Task.Factory.StartNew(() => { Write(stream); }); + ThreadPool.QueueUserWorkItem(SendInstruction, Parame.tcpClient); + } + } + catch (Exception ex) { Console.WriteLine(ex.Message); Parame.tcpClient = null; } + finally { } + } + + /// + /// 读取服务端信息 + /// + /// + public void Write(NetworkStream stream) + { + while (true) + { + try + { + // 读取包头,获取消息的大小 + int messageSize = ReadHeader(stream); + if (messageSize == -1) + { + Parame.tcpClient = null; + Console.WriteLine("与服务端连接断开"); + break; + } + // 读取消息内容 + byte[] buffer = new byte[messageSize]; + + int bytesRead = ReadExactly(stream, buffer, 0, messageSize); + + if (bytesRead < messageSize) + { + Parame.tcpClient = null; + Console.WriteLine("无法读取消息,可能是连接断开"); + break; + } + string message = Encoding.UTF8.GetString(buffer, 0, bytesRead); + if (!message.Contains("heartbeatService")) + { + //接收到服务端口返回数据 + Console.WriteLine("接收到服务端口返回数据:{0}", message); + jsonstr = message; + } + else + { + //收到服务器心跳反馈 + Console.WriteLine("收到服务器心跳反馈:{0}", message); + SendDataWithHeader(stream, "heartbeatClient"); + } + } + catch (Exception ex) { Console.WriteLine(ex.Message); jsonstr = string.Empty; Parame.tcpClient = null; } + finally { } + } + } + + /// + /// 发送信息给服务端 + /// + /// + /// + public string SendDataWithHeader(NetworkStream stream, string message) + { + try + { + byte[] messageBytes = Encoding.UTF8.GetBytes(message); + byte[] header = BitConverter.GetBytes(messageBytes.Length); + byte[] data = new byte[header.Length + messageBytes.Length]; + Array.Copy(header, 0, data, 0, header.Length); + Array.Copy(messageBytes, 0, data, header.Length, messageBytes.Length); + stream.Write(data, 0, data.Length); + jsonstr = string.Empty; + while (string.IsNullOrEmpty(jsonstr)){ Task.Delay(10).Wait(); } + } + catch (Exception ex) {Console.WriteLine(ex.Message); Parame.tcpClient = null; } + finally { } + return jsonstr; + } + + /// + /// 发送心跳 + /// + /// + public void SendInstruction(object state) + { + try + { + TcpClient client = (TcpClient)state; + NetworkStream stream = client.GetStream(); + while (true) + { + // 每隔2分钟向服务端发送一条指令 + Thread.Sleep(122000); + SendDataWithHeader(stream, "keepAlive"); + Console.WriteLine("发送心跳指令关闭连接"); + + } + } + catch (Exception ex) { Console.WriteLine(ex.Message); Parame.tcpClient = null; } + finally { } + } + + /// + /// 解析包头中有多少字节 + /// + /// + /// + public int ReadHeader(NetworkStream stream) + { + try + { + byte[] header = new byte[4]; + int headerBytesRead = stream.Read(header, 0, 4); + + if (headerBytesRead < 4) + { + Parame.tcpClient = null; + Console.WriteLine("无法读取包头,可能是连接断开"); + return -1; + } + return BitConverter.ToInt32(header, 0); + } + catch (Exception ex) + { + Parame.tcpClient = null; + Console.WriteLine(ex.Message); + return -1; + } + } + + /// + /// 等待流全部获取到,然后丢出去 + /// + /// + /// + /// + /// + /// + public int ReadExactly(NetworkStream stream, byte[] buffer, int offset, int count) + { + try + { + int bytesRead = 0; + while (bytesRead < count) + { + int result = stream.Read(buffer, offset + bytesRead, count - bytesRead); + if (result == 0) + { + // 连接断开或遇到流的末尾 + return bytesRead; + } + bytesRead += result; + } + return bytesRead; + } + catch (Exception ex) + { + Parame.tcpClient = null; + Console.WriteLine(ex.Message); + return -1; + } + } + } +} diff --git a/CPF_Cef/Common/Utils.cs b/CPF_Cef/Common/Utils.cs index 5616b15..434f5a7 100644 --- a/CPF_Cef/Common/Utils.cs +++ b/CPF_Cef/Common/Utils.cs @@ -1,6 +1,9 @@ using CPF.Controls; +using CPF.Windows; +using NAudio.Wave; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -15,7 +18,25 @@ namespace AksWebBrowser.Common /// public static void MessagesBox(string mes) { MessageBox.ShowSync(mes); + } + + /// + /// base64转文件 + /// + /// + /// + public static void Base64StringToFile(string base64String, string filePath) + { + // 将base64字符串转换为字节数组 + byte[] wavBytes = Convert.FromBase64String(base64String); + // 将字节数组写入到wav文件 + using (FileStream fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write)) + { + fileStream.Write(wavBytes, 0, wavBytes.Length); + fileStream.Flush(); + fileStream.Close(); + } } } } diff --git a/CPF_Cef/FrmMain.cs b/CPF_Cef/FrmMain.cs index cae73a7..f25f441 100644 --- a/CPF_Cef/FrmMain.cs +++ b/CPF_Cef/FrmMain.cs @@ -19,7 +19,10 @@ namespace AKS.EnterpriseLibrary.WebBrowser { public class FrmMain : Window { - + public int w = 1920; + public int h = 1080; + + protected override void InitializeComponent() { LoadStyleFile("res://AksWebBrowser/StyleSheet.css"); @@ -65,18 +68,18 @@ namespace AKS.EnterpriseLibrary.WebBrowser protected override async void OnInitialized() { //窗体大小 - this.Width = 1080; - this.Height = 1920; + this.Width = w; + this.Height = h; //SetTaskStatus.Hidetask(); base.OnInitialized(); Parame.webBrowser = FindPresenterByName(nameof(Parame.webBrowser)); textBox = FindPresenterByName(nameof(textBox)); Parame.webBrowser.CusRequest.CusResquestEvent += CusRequest_CusResquestEvent; //浏览器大小 - Parame.webBrowser.Width = 1080; - Parame.webBrowser.Height = 1920; - Parame.webBrowser.Url = "http://192.168.0.34:8078/#/main-out"; - //Parame.webBrowser.Url = Application.StartupPath + @"\html\index.html"; + Parame.webBrowser.Width = w; + Parame.webBrowser.Height = h; + //Parame.webBrowser.Url = "http://192.168.0.34:8078/#/main-out"; + Parame.webBrowser.Url = Application.StartupPath + @"\html\index.html"; //开发者工具暂时只能支持Windows //webBrowser.ShowDev(); //SetTaskStatus.Showtask(); @@ -161,7 +164,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser var request = new HttpRequestMessage(HttpMethod.Get, $"{Parame.apiUrl}/api/Interface/Getlist?Ytjbm={Parame.key}"); var response = await client.SendAsync(request); List list = new List(); - if (response.StatusCode.ToString() == "200") + if (response.StatusCode.ToString() == "OK") { response.EnsureSuccessStatusCode(); var body = await response.Content.ReadAsStringAsync(); diff --git a/CPF_Cef/MainModel.cs b/CPF_Cef/MainModel.cs index 0dcd33e..3e37310 100644 --- a/CPF_Cef/MainModel.cs +++ b/CPF_Cef/MainModel.cs @@ -8,6 +8,7 @@ using NAudio.Wave; using NAudio.Wave.SampleProviders; using SkiaSharp; using System; +using System.Buffers.Text; using System.Diagnostics; using System.Globalization; using System.IO; @@ -15,22 +16,24 @@ 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; namespace AKS.EnterpriseLibrary.WebBrowser { public class MainModel : CPF.CpfObject { - public COMUtils com = new COMUtils(); + public COMUtils com; public string callback = string.Empty; public string PrinterName = "Lexmark-MS430-Series"; public static Process recordingProcess; public static Process Typrocess; - + public TcpClients tcpClients = new TcpClients(); /// /// 读取身份证卡号 /// @@ -51,7 +54,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser paramsString = "{\"callback\":\"" + callback + "\",\"type\":\"1\",\"param\":{\"data\":\"" + "" + "\"}}"; Log.Info("读取身份证卡号: " + paramsString + ""); string base64 = str2Base64(paramsString); - string str = com.SendData(base64, callback); + string str = tcpClients.SendDataWithHeader(Parame.tcpClient.GetStream(), base64); string result = Base64str2(str); SubmitLogs(result, "IDCardRead"); return result; @@ -89,7 +92,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser string paramsString = "{\"callback\":\"" + callback + "\",\"type\":\"2\",\"param\":{\"ph\":\"" + ph + "\",\"ddrs\":\"" + ddrs + "\",\"qrcode\":\"" + qrcode + "\",\"ywmc\":\"" + ywmc + "\"}}"; Log.Info("打印排队票据: " + paramsString + ""); string base64 = str2Base64(paramsString); - string str = com.SendData(base64, callback); + string str = tcpClients.SendDataWithHeader(Parame.tcpClient.GetStream(), base64); string result = Base64str2(str); SubmitLogs(result, "SendByPrint"); return result; @@ -128,7 +131,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser { string paramsString = "{\"callback\":\"" + callback + "\",\"type\":\"3\",\"param\":{\"text\":\"" + text + "\",\"ispaye\":\"" + ispaye + "\"}}"; Log.Info("文字语音播报: " + paramsString + ""); - //string base64 = str2Base64(paramsString); + string base64 = str2Base64(paramsString); //if (base64.Length > 1024) //{ // //形成临时文件 @@ -162,42 +165,42 @@ namespace AKS.EnterpriseLibrary.WebBrowser // Log.Info("文字语音播报: " + paramsString + ""); // base64 = str2Base64(paramsString); //} - //string str = com.SendData(base64, callback); - //return Base64str2(str); - 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; - } + string str = tcpClients.SendDataWithHeader(Parame.tcpClient.GetStream(), base64); + return Base64str2(str); + //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) @@ -230,7 +233,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser string paramsString = "{\"callback\":\"" + callback + "\",\"type\":\"4\",\"param\":{\"content\":\"" + content + "\",\"phone\":\"" + phone + "\"}}"; Log.Info("发送短信: " + paramsString + ""); string base64 = str2Base64(paramsString); - string str = com.SendData(base64, callback); + string str = tcpClients.SendDataWithHeader(Parame.tcpClient.GetStream(), base64); string result = Base64str2(str); SubmitLogs(result, "SendSSM"); return result; @@ -265,11 +268,11 @@ namespace AKS.EnterpriseLibrary.WebBrowser string paramsString = "{\"callback\":\"" + callback + "\",\"type\":\"5\",\"param\":{\"url\":\"" + url + "\"}}"; Log.Info("打开高拍仪并且进行快速扫描文件: " + paramsString + ""); string base64 = str2Base64(paramsString); - string str = com.SendData(base64, callback); + string str = tcpClients.SendDataWithHeader(Parame.tcpClient.GetStream(), base64); string data = Base64str2(str); if (data == "400") { - string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "获取签字失败" + "\"}"; + string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "扫描文件失败" + "\"}"; SubmitLogs(result, "openCamera"); return result; } @@ -310,7 +313,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser paramsString = "{\"callback\":\"" + callback + "\",\"type\":\"6\",\"param\":{\"data\":\"" + "" + "\"}}"; Log.Info("打开签字版: " + paramsString + ""); string base64 = str2Base64(paramsString); - string str = com.SendData(base64, callback); + string str = tcpClients.SendDataWithHeader(Parame.tcpClient.GetStream(), base64); string result = Base64str2(str); SubmitLogs(result, "OpenSign"); return result; @@ -345,7 +348,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser paramsString = "{\"callback\":\"" + callback + "\",\"type\":\"7\",\"param\":{\"data\":\"" + "" + "\"}}"; Log.Info("关闭签字版: " + paramsString + ""); string base64 = str2Base64(paramsString); - string str = com.SendData(base64, callback); + string str = tcpClients.SendDataWithHeader(Parame.tcpClient.GetStream(), base64); string result = Base64str2(str); SubmitLogs(result, "OpenSign"); return result; @@ -380,7 +383,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser string paramsString = "{\"callback\":\"" + callback + "\",\"type\":\"8\",\"param\":{\"url\":\"" + url + "\"}}"; Log.Info("获取签字版数据: " + paramsString + ""); string base64 = str2Base64(paramsString); - string str = com.SendData(base64, callback); + string str = tcpClients.SendDataWithHeader(Parame.tcpClient.GetStream(), base64); string data = Base64str2(str); if (data == "400") { @@ -425,62 +428,52 @@ namespace AKS.EnterpriseLibrary.WebBrowser } else { + string paramsString = "{\"callback\":\"" + callback + "\",\"type\":\"11\",\"param\":{\"isopen\":\"" + isopen + "\",\"url\":\"" + url + "\"}}"; + Log.Info("开始录音、取消录音、结束录音: " + paramsString + ""); + string base64 = str2Base64(paramsString); + string str = tcpClients.SendDataWithHeader(Parame.tcpClient.GetStream(), base64); //结束录音上传文件 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 tt = Base64str2(str); + Log.Info(tt); + //下载文件 + DateTime dateTime = DateTime.Now; + string time = DateTime.Now.ToString( + "yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo); + var dirpath = System.IO.Path.Combine(Environment.CurrentDirectory, "wwwroot", "RecordFile"); + if (!Directory.Exists(dirpath)) { - string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"wav\",\"data\":\"" + "开始录音" + "\"}"; - SubmitLogs(result, "SoundRecording"); - return result; + Directory.CreateDirectory(dirpath); } - else + var filepath = System.IO.Path.Combine(dirpath, time); + string path = dirpath + @"/" + time + ".wav" ; + WebRequest request = WebRequest.Create(tt); + WebResponse response = request.GetResponse(); + using (Stream stream = response.GetResponseStream()) { - string result = "{\"callback\":\"" + callback + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"suffix\":\"wav\",\"data\":\"" + "录音失败" + "\"}"; - SubmitLogs(result, "SoundRecording"); - return result; + using (FileStream fileStream = new FileStream(path, FileMode.Create)) + { + stream.CopyTo(fileStream); + } } + response.Close(); + //上传文件 + Task.Run(async () =>{UploadInfo(url, path);}); + @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 wavurl = mc[0].ToString() + "://" + mc[1].ToString() + urlpath; + string result = "{\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"wav\",\"data\":\"" + wavurl + "\"}"; + Log.Info(result); + SubmitLogs(result, "SoundRecording"); + return result; } - else //取消录音 + 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; - } - + string result = Base64str2(str); + SubmitLogs(result, "SoundRecording"); + return result; } } } @@ -652,6 +645,8 @@ namespace AKS.EnterpriseLibrary.WebBrowser } else { + Log.Info("播放音频文件: " + url + ""); + Log.Info("是否播放: " + ispaly + ""); if (ispaly) { Task.Run(() => @@ -674,7 +669,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser WebResponse response = request.GetResponse(); using (Stream stream = response.GetResponseStream()) { - using (FileStream fileStream = new FileStream(WaveOutPath, FileMode.Create)) + using (FileStream fileStream = new FileStream(path, FileMode.Create)) { stream.CopyTo(fileStream); } @@ -1170,17 +1165,20 @@ namespace AKS.EnterpriseLibrary.WebBrowser string Name = string.Empty; string Interfaceaddress = string.Empty; bool isFunc = false; - if (Parame.FuncObject.Count > 0) + if (Parame.FuncObject != null) { - foreach (Func func in Parame.FuncObject) + if (Parame.FuncObject.Count > 0) { - if (func.Interfaceaddress.Contains(funcName)) + foreach (Func func in Parame.FuncObject) { - isFunc = true; - ApiId = func.Id; - Name = func.Platform; - Interfaceaddress = func.Interfaceaddress; - break; + if (func.Interfaceaddress.Contains(funcName)) + { + isFunc = true; + ApiId = func.Id; + Name = func.Platform; + Interfaceaddress = func.Interfaceaddress; + break; + } } } } diff --git a/CPF_Cef/Parame.cs b/CPF_Cef/Parame.cs index 834aeb6..b04e306 100644 --- a/CPF_Cef/Parame.cs +++ b/CPF_Cef/Parame.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net.Sockets; using System.Text; using System.Threading.Tasks; @@ -9,6 +10,7 @@ namespace AksWebBrowser { public class Parame { + public static TcpClient tcpClient { get; set; } public static CusWebBrowser webBrowser { get; set; } public static List FuncObject { get; set; } //接口地址 diff --git a/CPF_Cef/Program.cs b/CPF_Cef/Program.cs index 9f15228..0cdf955 100644 --- a/CPF_Cef/Program.cs +++ b/CPF_Cef/Program.cs @@ -5,6 +5,9 @@ using CPF.Platform; using CPF.Skia; using CPF.Windows; using System; +using System.Net.Sockets; +using System.Threading.Tasks; +using System.Threading; namespace AKS.EnterpriseLibrary.WebBrowser { @@ -14,11 +17,10 @@ namespace AKS.EnterpriseLibrary.WebBrowser static void Main(string[] args) { Application.Initialize( - (OperatingSystemType.Windows, new WindowsPlatform(), new SkiaDrawingFactory()) - , (OperatingSystemType.OSX, new MacPlatform(), new SkiaDrawingFactory())//如果需要支持Mac才需要 - , (OperatingSystemType.Linux, new LinuxPlatform(), new SkiaDrawingFactory())//如果需要支持Linux才需要 - ); - + (OperatingSystemType.Windows, new WindowsPlatform(), new SkiaDrawingFactory()) + , (OperatingSystemType.OSX, new MacPlatform(), new SkiaDrawingFactory())//如果需要支持Mac才需要 + , (OperatingSystemType.Linux, new LinuxPlatform(), new SkiaDrawingFactory())//如果需要支持Linux才需要 + ); CefRuntime.Load(); var mainArgs = new CpfCefMainArgs(args); var app = new CpfCefApp(); @@ -27,11 +29,9 @@ namespace AKS.EnterpriseLibrary.WebBrowser { return; } - CefRuntime.Initialize(mainArgs, new CefSettings{ }, app, IntPtr.Zero); - + CefRuntime.Initialize(mainArgs, new CefSettings { }, app, IntPtr.Zero); var model = new MainModel(); Application.Run(new FrmMain { DataContext = model, CommandContext = model }); - CefRuntime.Shutdown(); } }