Browse Source

提交对接线硬件对接代码

master
胡超1 1 year ago
parent
commit
1986a7da66
  1. 10
      CPF_Cef/Common/Log.cs
  2. 215
      CPF_Cef/Common/TcpClients.cs
  3. 21
      CPF_Cef/Common/Utils.cs
  4. 17
      CPF_Cef/FrmMain.cs
  5. 174
      CPF_Cef/MainModel.cs
  6. 2
      CPF_Cef/Parame.cs
  7. 6
      CPF_Cef/Program.cs

10
CPF_Cef/Common/Log.cs

@ -34,16 +34,20 @@ namespace AKSWebBrowser.Commen
streamWriter.WriteLine("异常信息:\r\n" + message); streamWriter.WriteLine("异常信息:\r\n" + message);
} }
} }
catch { }
finally finally
{ {
if (streamWriter != null) if (streamWriter != null)
{ {
streamWriter.Flush(); streamWriter.Flush();
if (streamWriter != null)
{
streamWriter.Dispose(); streamWriter.Dispose();
streamWriter = null; streamWriter = null;
} }
} }
} }
}
public static void Info(string message) public static void Info(string message)
{ {
@ -58,7 +62,7 @@ namespace AKSWebBrowser.Commen
directPath += string.Format(@"/{0}.log", DateTime.Now.ToString("yyyy-MM-dd")); directPath += string.Format(@"/{0}.log", DateTime.Now.ToString("yyyy-MM-dd"));
if (streamWriter == null) 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("***********************************************************************");
streamWriter.WriteLine(DateTime.Now.ToString("HH:mm:ss")); streamWriter.WriteLine(DateTime.Now.ToString("HH:mm:ss"));
@ -68,11 +72,14 @@ namespace AKSWebBrowser.Commen
streamWriter.WriteLine("信息:\r\n" + message); streamWriter.WriteLine("信息:\r\n" + message);
} }
} }
catch { }
finally finally
{ {
if (streamWriter != null) if (streamWriter != null)
{ {
streamWriter.Flush(); streamWriter.Flush();
if (streamWriter != null)
{
streamWriter.Dispose(); streamWriter.Dispose();
streamWriter = null; streamWriter = null;
} }
@ -80,3 +87,4 @@ namespace AKSWebBrowser.Commen
} }
} }
} }
}

215
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;
/// <summary>
/// 打开连接
/// </summary>
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 { }
}
/// <summary>
/// 读取服务端信息
/// </summary>
/// <param name="stream"></param>
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 { }
}
}
/// <summary>
/// 发送信息给服务端
/// </summary>
/// <param name="stream"></param>
/// <param name="message"></param>
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;
}
/// <summary>
/// 发送心跳
/// </summary>
/// <param name="state"></param>
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 { }
}
/// <summary>
/// 解析包头中有多少字节
/// </summary>
/// <param name="stream"></param>
/// <returns></returns>
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;
}
}
/// <summary>
/// 等待流全部获取到,然后丢出去
/// </summary>
/// <param name="stream"></param>
/// <param name="buffer"></param>
/// <param name="offset"></param>
/// <param name="count"></param>
/// <returns></returns>
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;
}
}
}
}

21
CPF_Cef/Common/Utils.cs

@ -1,6 +1,9 @@
using CPF.Controls; using CPF.Controls;
using CPF.Windows;
using NAudio.Wave;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -15,7 +18,25 @@ namespace AksWebBrowser.Common
/// <param name="mes"></param> /// <param name="mes"></param>
public static void MessagesBox(string mes) { public static void MessagesBox(string mes) {
MessageBox.ShowSync(mes); MessageBox.ShowSync(mes);
}
/// <summary>
/// base64转文件
/// </summary>
/// <param name="base64String"></param>
/// <param name="filePath"></param>
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();
}
} }
} }
} }

17
CPF_Cef/FrmMain.cs

@ -19,6 +19,9 @@ namespace AKS.EnterpriseLibrary.WebBrowser
{ {
public class FrmMain : Window public class FrmMain : Window
{ {
public int w = 1920;
public int h = 1080;
protected override void InitializeComponent() protected override void InitializeComponent()
{ {
@ -65,18 +68,18 @@ namespace AKS.EnterpriseLibrary.WebBrowser
protected override async void OnInitialized() protected override async void OnInitialized()
{ {
//窗体大小 //窗体大小
this.Width = 1080; this.Width = w;
this.Height = 1920; this.Height = h;
//SetTaskStatus.Hidetask(); //SetTaskStatus.Hidetask();
base.OnInitialized(); base.OnInitialized();
Parame.webBrowser = FindPresenterByName<CusWebBrowser>(nameof(Parame.webBrowser)); Parame.webBrowser = FindPresenterByName<CusWebBrowser>(nameof(Parame.webBrowser));
textBox = FindPresenterByName<TextBox>(nameof(textBox)); textBox = FindPresenterByName<TextBox>(nameof(textBox));
Parame.webBrowser.CusRequest.CusResquestEvent += CusRequest_CusResquestEvent; Parame.webBrowser.CusRequest.CusResquestEvent += CusRequest_CusResquestEvent;
//浏览器大小 //浏览器大小
Parame.webBrowser.Width = 1080; Parame.webBrowser.Width = w;
Parame.webBrowser.Height = 1920; Parame.webBrowser.Height = h;
Parame.webBrowser.Url = "http://192.168.0.34:8078/#/main-out"; //Parame.webBrowser.Url = "http://192.168.0.34:8078/#/main-out";
//Parame.webBrowser.Url = Application.StartupPath + @"\html\index.html"; Parame.webBrowser.Url = Application.StartupPath + @"\html\index.html";
//开发者工具暂时只能支持Windows //开发者工具暂时只能支持Windows
//webBrowser.ShowDev(); //webBrowser.ShowDev();
//SetTaskStatus.Showtask(); //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 request = new HttpRequestMessage(HttpMethod.Get, $"{Parame.apiUrl}/api/Interface/Getlist?Ytjbm={Parame.key}");
var response = await client.SendAsync(request); var response = await client.SendAsync(request);
List<Func> list = new List<Func>(); List<Func> list = new List<Func>();
if (response.StatusCode.ToString() == "200") if (response.StatusCode.ToString() == "OK")
{ {
response.EnsureSuccessStatusCode(); response.EnsureSuccessStatusCode();
var body = await response.Content.ReadAsStringAsync(); var body = await response.Content.ReadAsStringAsync();

174
CPF_Cef/MainModel.cs

@ -8,6 +8,7 @@ using NAudio.Wave;
using NAudio.Wave.SampleProviders; using NAudio.Wave.SampleProviders;
using SkiaSharp; using SkiaSharp;
using System; using System;
using System.Buffers.Text;
using System.Diagnostics; using System.Diagnostics;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
@ -15,22 +16,24 @@ using System.Linq;
using System.Net; using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Net.Http.Headers; using System.Net.Http.Headers;
using System.Net.Sockets;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Web; using System.Web;
using System.Xml.Linq; using System.Xml.Linq;
using static System.Net.Mime.MediaTypeNames;
namespace AKS.EnterpriseLibrary.WebBrowser namespace AKS.EnterpriseLibrary.WebBrowser
{ {
public class MainModel : CPF.CpfObject public class MainModel : CPF.CpfObject
{ {
public COMUtils com = new COMUtils(); public COMUtils com;
public string callback = string.Empty; public string callback = string.Empty;
public string PrinterName = "Lexmark-MS430-Series"; public string PrinterName = "Lexmark-MS430-Series";
public static Process recordingProcess; public static Process recordingProcess;
public static Process Typrocess; public static Process Typrocess;
public TcpClients tcpClients = new TcpClients();
/// <summary> /// <summary>
/// 读取身份证卡号 /// 读取身份证卡号
/// </summary> /// </summary>
@ -51,7 +54,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser
paramsString = "{\"callback\":\"" + callback + "\",\"type\":\"1\",\"param\":{\"data\":\"" + "" + "\"}}"; paramsString = "{\"callback\":\"" + callback + "\",\"type\":\"1\",\"param\":{\"data\":\"" + "" + "\"}}";
Log.Info("读取身份证卡号: " + paramsString + ""); Log.Info("读取身份证卡号: " + paramsString + "");
string base64 = str2Base64(paramsString); string base64 = str2Base64(paramsString);
string str = com.SendData(base64, callback); string str = tcpClients.SendDataWithHeader(Parame.tcpClient.GetStream(), base64);
string result = Base64str2(str); string result = Base64str2(str);
SubmitLogs(result, "IDCardRead"); SubmitLogs(result, "IDCardRead");
return result; 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 + "\"}}"; string paramsString = "{\"callback\":\"" + callback + "\",\"type\":\"2\",\"param\":{\"ph\":\"" + ph + "\",\"ddrs\":\"" + ddrs + "\",\"qrcode\":\"" + qrcode + "\",\"ywmc\":\"" + ywmc + "\"}}";
Log.Info("打印排队票据: " + paramsString + ""); Log.Info("打印排队票据: " + paramsString + "");
string base64 = str2Base64(paramsString); string base64 = str2Base64(paramsString);
string str = com.SendData(base64, callback); string str = tcpClients.SendDataWithHeader(Parame.tcpClient.GetStream(), base64);
string result = Base64str2(str); string result = Base64str2(str);
SubmitLogs(result, "SendByPrint"); SubmitLogs(result, "SendByPrint");
return result; return result;
@ -128,7 +131,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser
{ {
string paramsString = "{\"callback\":\"" + callback + "\",\"type\":\"3\",\"param\":{\"text\":\"" + text + "\",\"ispaye\":\"" + ispaye + "\"}}"; string paramsString = "{\"callback\":\"" + callback + "\",\"type\":\"3\",\"param\":{\"text\":\"" + text + "\",\"ispaye\":\"" + ispaye + "\"}}";
Log.Info("文字语音播报: " + paramsString + ""); Log.Info("文字语音播报: " + paramsString + "");
//string base64 = str2Base64(paramsString); string base64 = str2Base64(paramsString);
//if (base64.Length > 1024) //if (base64.Length > 1024)
//{ //{
// //形成临时文件 // //形成临时文件
@ -162,42 +165,42 @@ namespace AKS.EnterpriseLibrary.WebBrowser
// Log.Info("文字语音播报: " + paramsString + ""); // Log.Info("文字语音播报: " + paramsString + "");
// base64 = str2Base64(paramsString); // base64 = str2Base64(paramsString);
//} //}
//string str = com.SendData(base64, callback); string str = tcpClients.SendDataWithHeader(Parame.tcpClient.GetStream(), base64);
//return Base64str2(str); return Base64str2(str);
if (ispaye) //if (ispaye)
{ //{
Task.Run(() => // Task.Run(() =>
{ // {
if (Typrocess != null) // if (Typrocess != null)
{ // {
// 如果进程还在运行 // // 如果进程还在运行
if (!Typrocess.HasExited) // if (!Typrocess.HasExited)
{ // {
// 发送SIGTERM信号来停止进程 // // 发送SIGTERM信号来停止进程
Typrocess.Kill(); // Typrocess.Kill();
// 等待进程真正停止 // // 等待进程真正停止
Typrocess.WaitForExit(); // Typrocess.WaitForExit();
} // }
} // }
}); // });
string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":" + "停止播放成功" + "}"; // string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":" + "停止播放成功" + "}";
SubmitLogs(result, "payleText"); // SubmitLogs(result, "payleText");
return result; // return result;
} //}
else //else
{ //{
Task.Run(() => // Task.Run(() =>
{ // {
//形成语音 // //形成语音
tempWav = GenerateWavFromText(text); // tempWav = GenerateWavFromText(text);
//开始播放 // //开始播放
string command = $"sox {tempWav} -d"; // string command = $"sox {tempWav} -d";
ShllCommad(command); // ShllCommad(command);
}); // });
string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":" + "开始播放" + "}"; // string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":" + "开始播放" + "}";
SubmitLogs(result, "payleText"); // SubmitLogs(result, "payleText");
return result; // return result;
} //}
} }
} }
catch (Exception ex) catch (Exception ex)
@ -230,7 +233,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser
string paramsString = "{\"callback\":\"" + callback + "\",\"type\":\"4\",\"param\":{\"content\":\"" + content + "\",\"phone\":\"" + phone + "\"}}"; string paramsString = "{\"callback\":\"" + callback + "\",\"type\":\"4\",\"param\":{\"content\":\"" + content + "\",\"phone\":\"" + phone + "\"}}";
Log.Info("发送短信: " + paramsString + ""); Log.Info("发送短信: " + paramsString + "");
string base64 = str2Base64(paramsString); string base64 = str2Base64(paramsString);
string str = com.SendData(base64, callback); string str = tcpClients.SendDataWithHeader(Parame.tcpClient.GetStream(), base64);
string result = Base64str2(str); string result = Base64str2(str);
SubmitLogs(result, "SendSSM"); SubmitLogs(result, "SendSSM");
return result; return result;
@ -265,11 +268,11 @@ namespace AKS.EnterpriseLibrary.WebBrowser
string paramsString = "{\"callback\":\"" + callback + "\",\"type\":\"5\",\"param\":{\"url\":\"" + url + "\"}}"; string paramsString = "{\"callback\":\"" + callback + "\",\"type\":\"5\",\"param\":{\"url\":\"" + url + "\"}}";
Log.Info("打开高拍仪并且进行快速扫描文件: " + paramsString + ""); Log.Info("打开高拍仪并且进行快速扫描文件: " + paramsString + "");
string base64 = str2Base64(paramsString); string base64 = str2Base64(paramsString);
string str = com.SendData(base64, callback); string str = tcpClients.SendDataWithHeader(Parame.tcpClient.GetStream(), base64);
string data = Base64str2(str); string data = Base64str2(str);
if (data == "400") if (data == "400")
{ {
string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "获取签字失败" + "\"}"; string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "扫描文件失败" + "\"}";
SubmitLogs(result, "openCamera"); SubmitLogs(result, "openCamera");
return result; return result;
} }
@ -310,7 +313,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser
paramsString = "{\"callback\":\"" + callback + "\",\"type\":\"6\",\"param\":{\"data\":\"" + "" + "\"}}"; paramsString = "{\"callback\":\"" + callback + "\",\"type\":\"6\",\"param\":{\"data\":\"" + "" + "\"}}";
Log.Info("打开签字版: " + paramsString + ""); Log.Info("打开签字版: " + paramsString + "");
string base64 = str2Base64(paramsString); string base64 = str2Base64(paramsString);
string str = com.SendData(base64, callback); string str = tcpClients.SendDataWithHeader(Parame.tcpClient.GetStream(), base64);
string result = Base64str2(str); string result = Base64str2(str);
SubmitLogs(result, "OpenSign"); SubmitLogs(result, "OpenSign");
return result; return result;
@ -345,7 +348,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser
paramsString = "{\"callback\":\"" + callback + "\",\"type\":\"7\",\"param\":{\"data\":\"" + "" + "\"}}"; paramsString = "{\"callback\":\"" + callback + "\",\"type\":\"7\",\"param\":{\"data\":\"" + "" + "\"}}";
Log.Info("关闭签字版: " + paramsString + ""); Log.Info("关闭签字版: " + paramsString + "");
string base64 = str2Base64(paramsString); string base64 = str2Base64(paramsString);
string str = com.SendData(base64, callback); string str = tcpClients.SendDataWithHeader(Parame.tcpClient.GetStream(), base64);
string result = Base64str2(str); string result = Base64str2(str);
SubmitLogs(result, "OpenSign"); SubmitLogs(result, "OpenSign");
return result; return result;
@ -380,7 +383,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser
string paramsString = "{\"callback\":\"" + callback + "\",\"type\":\"8\",\"param\":{\"url\":\"" + url + "\"}}"; string paramsString = "{\"callback\":\"" + callback + "\",\"type\":\"8\",\"param\":{\"url\":\"" + url + "\"}}";
Log.Info("获取签字版数据: " + paramsString + ""); Log.Info("获取签字版数据: " + paramsString + "");
string base64 = str2Base64(paramsString); string base64 = str2Base64(paramsString);
string str = com.SendData(base64, callback); string str = tcpClients.SendDataWithHeader(Parame.tcpClient.GetStream(), base64);
string data = Base64str2(str); string data = Base64str2(str);
if (data == "400") if (data == "400")
{ {
@ -425,63 +428,53 @@ namespace AKS.EnterpriseLibrary.WebBrowser
} }
else 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 (!string.IsNullOrEmpty(url) && !isopen)
{ {
if (StopRecording()) string tt = Base64str2(str);
{ Log.Info(tt);
Task.Run(async () => //下载文件
{ DateTime dateTime = DateTime.Now;
UploadInfo(url, srpath); string time = DateTime.Now.ToString(
}); "yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo);
@event2.WaitOne(); var dirpath = System.IO.Path.Combine(Environment.CurrentDirectory, "wwwroot", "RecordFile");
Regex re = new Regex(@"(((?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(:[0-9]+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)"); if (!Directory.Exists(dirpath))
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\":\"" + "结束录音失败" + "\"}"; Directory.CreateDirectory(dirpath);
SubmitLogs(result, "SoundRecording");
return result;
}
} }
else if (isopen)//开始录音 var filepath = System.IO.Path.Combine(dirpath, time);
{ string path = dirpath + @"/" + time + ".wav" ;
if (StartRecording()) WebRequest request = WebRequest.Create(tt);
WebResponse response = request.GetResponse();
using (Stream stream = response.GetResponseStream())
{ {
string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"wav\",\"data\":\"" + "开始录音" + "\"}"; using (FileStream fileStream = new FileStream(path, FileMode.Create))
SubmitLogs(result, "SoundRecording");
return result;
}
else
{ {
string result = "{\"callback\":\"" + callback + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"suffix\":\"wav\",\"data\":\"" + "录音失败" + "\"}"; stream.CopyTo(fileStream);
SubmitLogs(result, "SoundRecording");
return result;
} }
} }
else //取消录音 response.Close();
{ //上传文件
if (StopRecording()) Task.Run(async () =>{UploadInfo(url, path);});
{ @event2.WaitOne();
srpath = string.Empty; Regex re = new Regex(@"(((?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(:[0-9]+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)");
string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"wav\",\"data\":\"" + "取消录音" + "\"}"; 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"); SubmitLogs(result, "SoundRecording");
return result; return result;
} }
else else
{ {
srpath = string.Empty; string result = Base64str2(str);
string result = "{\"callback\":\"" + callback + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"suffix\":\"wav\",\"data\":\"" + "取消录音失败" + "\"}";
SubmitLogs(result, "SoundRecording"); SubmitLogs(result, "SoundRecording");
return result; return result;
} }
}
} }
} }
catch (Exception ex) catch (Exception ex)
@ -652,6 +645,8 @@ namespace AKS.EnterpriseLibrary.WebBrowser
} }
else else
{ {
Log.Info("播放音频文件: " + url + "");
Log.Info("是否播放: " + ispaly + "");
if (ispaly) if (ispaly)
{ {
Task.Run(() => Task.Run(() =>
@ -674,7 +669,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser
WebResponse response = request.GetResponse(); WebResponse response = request.GetResponse();
using (Stream stream = response.GetResponseStream()) using (Stream stream = response.GetResponseStream())
{ {
using (FileStream fileStream = new FileStream(WaveOutPath, FileMode.Create)) using (FileStream fileStream = new FileStream(path, FileMode.Create))
{ {
stream.CopyTo(fileStream); stream.CopyTo(fileStream);
} }
@ -1170,6 +1165,8 @@ namespace AKS.EnterpriseLibrary.WebBrowser
string Name = string.Empty; string Name = string.Empty;
string Interfaceaddress = string.Empty; string Interfaceaddress = string.Empty;
bool isFunc = false; bool isFunc = false;
if (Parame.FuncObject != null)
{
if (Parame.FuncObject.Count > 0) if (Parame.FuncObject.Count > 0)
{ {
foreach (Func func in Parame.FuncObject) foreach (Func func in Parame.FuncObject)
@ -1184,6 +1181,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser
} }
} }
} }
}
if (isFunc) if (isFunc)
{ {
var client = new HttpClient(); var client = new HttpClient();

2
CPF_Cef/Parame.cs

@ -2,6 +2,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net.Sockets;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -9,6 +10,7 @@ namespace AksWebBrowser
{ {
public class Parame public class Parame
{ {
public static TcpClient tcpClient { get; set; }
public static CusWebBrowser webBrowser { get; set; } public static CusWebBrowser webBrowser { get; set; }
public static List<Func> FuncObject { get; set; } public static List<Func> FuncObject { get; set; }
//接口地址 //接口地址

6
CPF_Cef/Program.cs

@ -5,6 +5,9 @@ using CPF.Platform;
using CPF.Skia; using CPF.Skia;
using CPF.Windows; using CPF.Windows;
using System; using System;
using System.Net.Sockets;
using System.Threading.Tasks;
using System.Threading;
namespace AKS.EnterpriseLibrary.WebBrowser namespace AKS.EnterpriseLibrary.WebBrowser
{ {
@ -18,7 +21,6 @@ namespace AKS.EnterpriseLibrary.WebBrowser
, (OperatingSystemType.OSX, new MacPlatform(), new SkiaDrawingFactory())//如果需要支持Mac才需要 , (OperatingSystemType.OSX, new MacPlatform(), new SkiaDrawingFactory())//如果需要支持Mac才需要
, (OperatingSystemType.Linux, new LinuxPlatform(), new SkiaDrawingFactory())//如果需要支持Linux才需要 , (OperatingSystemType.Linux, new LinuxPlatform(), new SkiaDrawingFactory())//如果需要支持Linux才需要
); );
CefRuntime.Load(); CefRuntime.Load();
var mainArgs = new CpfCefMainArgs(args); var mainArgs = new CpfCefMainArgs(args);
var app = new CpfCefApp(); var app = new CpfCefApp();
@ -28,10 +30,8 @@ namespace AKS.EnterpriseLibrary.WebBrowser
return; return;
} }
CefRuntime.Initialize(mainArgs, new CefSettings { }, app, IntPtr.Zero); CefRuntime.Initialize(mainArgs, new CefSettings { }, app, IntPtr.Zero);
var model = new MainModel(); var model = new MainModel();
Application.Run(new FrmMain { DataContext = model, CommandContext = model }); Application.Run(new FrmMain { DataContext = model, CommandContext = model });
CefRuntime.Shutdown(); CefRuntime.Shutdown();
} }
} }

Loading…
Cancel
Save