|
|
using AksWebBrowser; |
|
|
using AksWebBrowser.Common; |
|
|
using AksWebBrowser.Devices; |
|
|
using AKSWebBrowser.Commen; |
|
|
using Fleck; |
|
|
using Newtonsoft.Json; |
|
|
using Newtonsoft.Json.Linq; |
|
|
using System; |
|
|
using System.Collections.Generic; |
|
|
using System.Diagnostics; |
|
|
using System.Globalization; |
|
|
using System.IO; |
|
|
using System.Linq; |
|
|
using System.Net; |
|
|
using System.Net.Http; |
|
|
using System.Text; |
|
|
using System.Text.RegularExpressions; |
|
|
using System.Threading; |
|
|
using System.Threading.Tasks; |
|
|
using System.Web; |
|
|
|
|
|
namespace AKS.EnterpriseLibrary.WebBrowser |
|
|
{ |
|
|
public class MainModel : CPF.CpfObject |
|
|
{ |
|
|
|
|
|
//初始化网络连接 |
|
|
public static void DeviceControllerInit() |
|
|
{ |
|
|
try |
|
|
{ |
|
|
List<string> lit = new List<string>(); |
|
|
var server = new WebSocketServer("ws://0.0.0.0:19983"); |
|
|
server.Start(socket => |
|
|
{ |
|
|
Parame.socket = socket; |
|
|
socket.OnOpen = () => |
|
|
{ |
|
|
string result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + "" + "\",\"message\":\"seccse\",\"code\":\"200\",\"status\":true,\"data\":\"连接成功\"}"; |
|
|
socket.Send(result); |
|
|
}; |
|
|
socket.OnClose = () => |
|
|
{ |
|
|
string result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + "" + "\",\"message\":\"seccse\",\"code\":\"200\",\"status\":true,\"data\":\"连接关闭\"}"; |
|
|
socket.Send(result); |
|
|
}; |
|
|
socket.OnMessage = message => |
|
|
{ |
|
|
string content = message; |
|
|
//读取参数 |
|
|
if (content != "ping" && !string.IsNullOrEmpty(content)) |
|
|
{ |
|
|
//返回内容 |
|
|
string result = string.Empty; |
|
|
content = Base64str2(content); |
|
|
// Log.Info("收到请求:" + socket.ConnectionInfo.ClientIpAddress + " 请求参数:" + content); |
|
|
if (!string.IsNullOrEmpty(content)) |
|
|
{ |
|
|
try |
|
|
{ |
|
|
var json = content.ConvertToAnonymousType(new |
|
|
{ |
|
|
code = default(string) |
|
|
}); |
|
|
if (json != null) |
|
|
{ |
|
|
//接收指令和参数 |
|
|
string keycode = json.code; |
|
|
switch (keycode) |
|
|
{ |
|
|
//aks100101 |
|
|
//读取身份证卡号 {"code":"aks100101"} |
|
|
case "aks100101": |
|
|
result = IDCardRead(keycode); |
|
|
//Log.Info("读取身份证卡号" + result); |
|
|
//result = "{\"keycode\":\"aks100101\",\"message\":\"seccse\",\"code\":\"200\",\"status\":true,\"data\":{\"Data\":{\"Name\":\"谢洪基\",\"Sex\":\"男\",\"Nation_Code\":null,\"Nation\":\"汉\",\"Id\":\"510125199702062315\",\"BirthDay\":\"19970206\",\"Addr\":\"成都市新都区马家镇升庵村11组\",\"Regorg\":\"成都市公安局新都分局\",\"StartDate\":\"20171027\",\"EndDate\":\"20271027\",\"Reserv\":null,\"WltFileName\":null,\"BmpFilePath\":null,\"Status\":null,\"ImageBase64\":\"data:image/jpg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAIBAQEBAQIBAQECAgICAgQDAgICAgUEBAMEBgUGBgYFBgYGBwkIBgcJBwYGCAsICQoKCgoKBggLDAsKDAkKCgr/2wBDAQICAgICAgUDAwUKBwYHCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgr/wAARCAB+AGYDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1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LiPPBGT69q5D/hGzo/hyWNMpNcbvMAH3V5GPxGK+ezviCllGGlFStUa08i44b647T2PwG+CfxZ+Pn/AATU/aoX4gfBnxjPpHiLwlq0tt98+Rexq+HimRSPNifaMjPUKylWVWH9Cv7Cn/B07+xH+0SdO8FftFwXfwv197SFbjVdamjfSp7goTJtnT/Uou0/NKEDbl2jJ2r+EP8AwVq8Fx+Dv2sr5ktzHbaijTWxA+9hsMfz4/CvnS0f7FIJI+CPWv13hzH081yTD4mXxTim/Vn5zm+HeDx86fRPT0P7lPCPxM+HXj5FfwR470jV98AmC6dqMczCPj5iqsSB8wHI4JAor+KXwn8W/F+h6d9k0zxZqNpHx+7tL+SIfiEYZor3fYeZ5ntDzi4u1PQ96qXNzlGG6jt+NUr+VoywU1mZP4z3n/glHaC+/wCCgvgOKQ/KdRuCffFrKR+oFf0DWNlIY0uguSor+ff/AIJUXUtt+3l8PZ4mwz64YyfZ4XQ/o1f0N6eAtoyKMBWwMV/MPjdVdPiDDP8A6dv/ANKP13ghXyqp/i/Ql0q8bQrw6tYwIpc5uot3Ep/vHvkCu78Oa/pOvlZoYjHnojJj+deftEPIFwTkg5H51YsdYvo286KUqw6EGvleH+N6+SxVGsr03r5ryXkejj6ENZHqlwljChQvWZqMllDA0glUn+6WrhbvxxrattknL+5NVDrV7qVxiWQgnPIPSvocZ4p4OM3HCpt+a0POo0Yy3NjWtQa8fETAKpwYh0Y9j9RXMeKLiaOGZ5ZCf3bd/at+C0CJveUud3U1znjVs6bevjlW2j6EGvzbPc6xWY13Wq7y19PJeR9BhKMYR0Pxm/4Lb2n2n44+HNVbqNInUE+gmyP1J/Ovi6G7FzgB+uK+7v8AgurpkGl+O/Alxb9bvw5cyScdxPivgDTZXXGD0xX9ZeG85T4Xwt/5EflnFn/Izkb0T+Uu3rRVP7XLRX6UfLH/2QA=\"}}}"; |
|
|
break; |
|
|
//aks100102 |
|
|
//打印排队票据 {"code":"aks100102","ph":"100101","ddrs":"中国检察","qrcode":"90087100100124433002","ywmc":"信访"} |
|
|
case "aks100102": |
|
|
result = SendByPrint(content); |
|
|
break; |
|
|
//aks100103 |
|
|
//文字语音播报 |
|
|
//播放:{ "code":"aks100103","text":"你好!","ispaye":false}, |
|
|
//停止播放:{ "code":"aks100104","text":"","ispaye":true} |
|
|
case "aks100103": |
|
|
result = payleText(content); |
|
|
//Log.Info("文字语音播报返回:" + result); |
|
|
break; |
|
|
//aks100104 |
|
|
//打开高拍仪并且进行快速扫描文件 {"code":"aks100104"} |
|
|
case "aks100104": |
|
|
result = openCamera(keycode); |
|
|
//Log.Info("打开高拍仪并且进行快速扫描文件返回:" + result); |
|
|
break; |
|
|
//aks100105 |
|
|
//打开签字版 {"code":"aks100105"} |
|
|
case "aks100105": |
|
|
result = OpenSign(content); |
|
|
break; |
|
|
//aks100112 |
|
|
//关闭签字版 {"code":"aks100112"} |
|
|
case "aks100112": |
|
|
result = CloseSign(keycode); |
|
|
break; |
|
|
//aks100106 |
|
|
//读取指纹 {"code":"aks100106","isclose":false} |
|
|
case "aks100106": |
|
|
result = ReadFingerData(content); |
|
|
Log.Info("读取指纹" + result); |
|
|
break; |
|
|
//aks100107 开始录音、取消录音、结束录音 |
|
|
// 开始录音:{ "code":"aks100107","url":"","isopen":true} |
|
|
// 取消录音: { "code":"aks100107","url":"","isopen":false} |
|
|
// 结束录音: { "code":"aks100107","url":"http://127.0.0.1/Upload","isopen":false} |
|
|
case "aks100107": |
|
|
result = SoundRecording(content); |
|
|
//// Log.Info("开始录音、取消录音、结束录音返回:" + result); |
|
|
break; |
|
|
//aks100108 |
|
|
//根据文件地址在线打印 { "code":"aks100108","url":"http://127.0.0.1/test.doc","ext":"doc"} |
|
|
case "aks100108": |
|
|
result = PrintFile(content); |
|
|
break; |
|
|
//aks100109 |
|
|
//根据文件base64打印(PDF) { "code":"aks100109","base64":"ADFJLAKSDJFLKASJF...","ext":"pdf"} |
|
|
case "aks100109": |
|
|
result = PrintBase64(content); |
|
|
//result = "{\"keycode\":\"" + "aks100109" + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"Base64打印保留原方式\"}"; |
|
|
break; |
|
|
//aks100110 |
|
|
//播放音频文件 { "code":"aks100110","url":"http://127.0.0.1/test.wav","ispaye":false} |
|
|
//停止播放音频文件 { "code":"aks100110","url":"","ispaye":true} |
|
|
case "aks100110": |
|
|
result = PalyFile(content); |
|
|
break; |
|
|
//aks100111 唤醒键盘 {"code":"aks100111"} |
|
|
case "aks100111": |
|
|
result = openKey(keycode); |
|
|
break; |
|
|
default: |
|
|
result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + "" + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"无效指令\"}"; |
|
|
break; |
|
|
} |
|
|
} |
|
|
else |
|
|
{ |
|
|
result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + "hert" + "\",\"message\":\"seccse\",\"code\":\"400\",\"status\":true,\"data\":\"参数解析错误\"}"; |
|
|
} |
|
|
} |
|
|
catch { result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + "hert" + "\",\"message\":\"seccse\",\"code\":\"400\",\"status\":true,\"data\":\"参数解析错误\"}"; } |
|
|
finally { } |
|
|
} |
|
|
else |
|
|
{ |
|
|
result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + "" + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"无效指令\"}"; |
|
|
} |
|
|
try |
|
|
{ |
|
|
|
|
|
//Log.Info("答复请求者:" + result); |
|
|
//答复请求者(处理完请求后在些答复) |
|
|
//byte[] bytes = SerializeContent(result); |
|
|
socket.Send(result); |
|
|
} |
|
|
catch { result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + "hert" + "\",\"message\":\"seccse\",\"code\":\"400\",\"status\":true,\"data\":\"返回参数失败\"}"; } |
|
|
finally { } |
|
|
} |
|
|
//监听心跳并且回复客户端“已ping作为关键字” |
|
|
else if (content == "ping") |
|
|
{ |
|
|
string result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + "hert" + "\",\"message\":\"seccse\",\"code\":\"200\",\"status\":true,\"data\":\"收到客户端心跳\"}"; |
|
|
socket.Send(result); |
|
|
} |
|
|
else |
|
|
{ |
|
|
string result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + "hert" + "\",\"message\":\"seccse\",\"code\":\"200\",\"status\":true,\"data\":\"收到客户端心跳\"}"; |
|
|
socket.Send(result); |
|
|
} |
|
|
}; |
|
|
}); |
|
|
} |
|
|
catch (Exception ex) |
|
|
{ |
|
|
Log.Error("socket异常:" + ex.Message); |
|
|
} |
|
|
} |
|
|
|
|
|
//解包 |
|
|
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 = Parame.PrinterName; |
|
|
public static Process recordingProcess; |
|
|
public static Process Typrocess; |
|
|
private static string srpath = string.Empty; |
|
|
|
|
|
/// <summary> |
|
|
/// aks100101 读取身份证卡号(已国产化) |
|
|
/// </summary> |
|
|
/// <param name="paramsString"></param> |
|
|
/// <returns></returns> |
|
|
public static string IDCardRead(string code) |
|
|
{ |
|
|
try |
|
|
{ |
|
|
//IDCard iDCard = new IDCard(); |
|
|
//string result = iDCard.getIdCard(code); |
|
|
Task.Run(() => { HttpPostResponseByIdcard("open", 1); }); |
|
|
@event7.WaitOne(); |
|
|
string result = IdcardStr; |
|
|
if (string.IsNullOrEmpty(IdcardStr)) |
|
|
{ |
|
|
result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "读取身份证失败" + "\"}"; |
|
|
} |
|
|
else |
|
|
{ |
|
|
if (IdcardStr == "500") |
|
|
{ |
|
|
result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "身份证持有者非本人" + "\"}"; |
|
|
} |
|
|
else |
|
|
{ |
|
|
result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"message\":\"seccse\",\"code\":\"200\",\"status\":true,\"data\":" + IdcardStr + "}"; |
|
|
} |
|
|
} |
|
|
SubmitLogs(result, "IDCardRead"); |
|
|
return result; |
|
|
} |
|
|
catch (Exception ex) |
|
|
{ |
|
|
//Log.Error("读取身份证卡号异常: " + ex.Message + ""); |
|
|
string result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; |
|
|
SubmitLogs(result, "IDCardRead"); |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
/// <summary> |
|
|
/// aks100102 打印排队票据(已国产化) |
|
|
/// </summary> |
|
|
/// <param name="ph">排号</param> |
|
|
/// <param name="ddrs">等待人数</param> |
|
|
/// <param name="qrcode">二维码</param> |
|
|
/// <param name="ywmc">办理业务名称</param> |
|
|
/// <returns></returns> |
|
|
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 |
|
|
{ |
|
|
if (param == null) |
|
|
{ |
|
|
return "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + "" + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "参数解析错误" + "\"}"; |
|
|
} |
|
|
string ph = param.ph; |
|
|
string ddrs = param.ddrs; |
|
|
string qrcode = param.qrcode; |
|
|
string ywmc = param.ywmc; |
|
|
|
|
|
if (!isFuncisFuncObject("SendByPrint")) |
|
|
{ |
|
|
//Utils.MessagesBox("打印排队票据设备未授权使用"); |
|
|
return "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"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 = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + param.code + "\",\"message\":\"seccse\",\"code\":\"200\",\"status\":true,\"data\":\"" + "打印成功" + "\"}"; |
|
|
SubmitLogs(result, "SendByPrint"); |
|
|
return result; |
|
|
} |
|
|
else |
|
|
{ |
|
|
string result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + (data == 1 ? "打印失败" : (data == 2 ? "打印机未连接" : "打印机初始化失败")) + "\"}"; |
|
|
SubmitLogs(result, "SendByPrint"); |
|
|
return result; |
|
|
} |
|
|
} |
|
|
} |
|
|
catch (Exception ex) |
|
|
{ |
|
|
//Log.Error("打印排队票据异常: " + ex.Message + ""); |
|
|
string result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; |
|
|
SubmitLogs(result, "SendByPrint"); |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
/// <summary> |
|
|
/// 文字语音播报(已国产化) |
|
|
/// apt install sox |
|
|
/// apt install libsox-fmt-all |
|
|
/// </summary> |
|
|
/// <param name="text"></param> |
|
|
/// <param name="ispaye"></param> |
|
|
/// <returns></returns> |
|
|
public static string tempWav = string.Empty; |
|
|
/// <summary> |
|
|
/// aks100103文字语音播报 |
|
|
/// </summary> |
|
|
/// <param name="content"></param> |
|
|
/// <returns></returns> |
|
|
public static string payleText(string content) |
|
|
{ |
|
|
var param = content.ConvertToAnonymousType(new |
|
|
{ |
|
|
code = default(string), |
|
|
text = default(string), |
|
|
ispaye = default(bool), |
|
|
}); |
|
|
|
|
|
try |
|
|
{ |
|
|
if (param == null) |
|
|
{ |
|
|
return "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + "" + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "参数解析错误" + "\"}"; |
|
|
} |
|
|
string text = param.text; |
|
|
bool ispaye = param.ispaye; |
|
|
if (!isFuncisFuncObject("payleText")) |
|
|
{ |
|
|
//Utils.MessagesBox("文字语音播报设备未授权使用"); |
|
|
return "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "文字语音播报设备未授权使用" + "\"}"; |
|
|
} |
|
|
else |
|
|
{ |
|
|
if (ispaye) |
|
|
{ |
|
|
Task.Run(() => |
|
|
{ |
|
|
try |
|
|
{ |
|
|
if (Typrocess != null) |
|
|
{ |
|
|
// 如果进程还在运行 |
|
|
if (!Typrocess.HasExited) |
|
|
{ |
|
|
// 发送SIGTERM信号来停止进程 |
|
|
Typrocess.Kill(); |
|
|
// 等待进程真正停止 |
|
|
Typrocess.WaitForExit(); |
|
|
} |
|
|
} |
|
|
} |
|
|
catch (Exception ex) |
|
|
{ |
|
|
//Log.Error("停止失败: " + ex.Message + ""); |
|
|
} |
|
|
// AutoAudio(false, ""); |
|
|
}); |
|
|
string result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + param.code + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + "停止播放成功" + "\"}"; |
|
|
SubmitLogs(result, "payleText"); |
|
|
return result; |
|
|
} |
|
|
else |
|
|
{ |
|
|
Task.Run(() => { HttpPostResponseByTTS("text_to_wav", 1, text); }); |
|
|
event2.WaitOne(); |
|
|
string result = string.Empty; |
|
|
if (string.IsNullOrEmpty(ttsStr)) |
|
|
{ |
|
|
result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "播放失败" + "\"}"; |
|
|
SubmitLogs(result, "payleText"); |
|
|
} |
|
|
else |
|
|
{ |
|
|
Task.Run(() => { string command = $"sox {ttsStr} -d"; ShllCommad(command); }); |
|
|
result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + param.code + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + "开始播放" + "\"}"; |
|
|
} |
|
|
SubmitLogs(result, "payleText"); |
|
|
return result; |
|
|
} |
|
|
} |
|
|
} |
|
|
catch (Exception ex) |
|
|
{ |
|
|
//Log.Error("文字语音播报异常2: " + ex.Message + ""); |
|
|
string result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; |
|
|
SubmitLogs(result, "payleText"); |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
/// <summary> |
|
|
/// aks100104打开高拍仪并且进行快速扫描文件 (已国产化) |
|
|
/// </summary> |
|
|
/// <param name="url"></param> |
|
|
/// <returns></returns> |
|
|
public static string openCamera(string code) |
|
|
{ |
|
|
try |
|
|
{ |
|
|
if (Parame.isGPY) |
|
|
{ |
|
|
//拍照 |
|
|
string param = getFrame(); |
|
|
//Log.Info("img2" + (param)); |
|
|
if (string.IsNullOrEmpty(param)) |
|
|
{ |
|
|
//关闭 |
|
|
//StopSn("0"); |
|
|
string result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"suffix\":\"jpg\",\"data\":\"" + "获取图片失败" + "\"}"; |
|
|
SubmitLogs(result, "openCamera"); |
|
|
return result; |
|
|
} |
|
|
else |
|
|
{ |
|
|
//关闭 |
|
|
//StopSn("0"); |
|
|
string result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"jpg\",\"data\":\"" + param + "\"}"; |
|
|
SubmitLogs(result, "openCamera"); |
|
|
return result; |
|
|
} |
|
|
} |
|
|
else |
|
|
{ |
|
|
//打开高拍仪 |
|
|
string param = OpenSn("0"); |
|
|
if (string.IsNullOrEmpty(param)) |
|
|
{ |
|
|
string result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"suffix\":\"jpg\",\"data\":\"" + "扫描仪打开失败" + "\"}"; |
|
|
SubmitLogs(result, "openCamera"); |
|
|
return result; |
|
|
} |
|
|
else |
|
|
{ |
|
|
Task.Delay(1000).Wait(); |
|
|
//拍照 |
|
|
param = getFrame(); |
|
|
//Log.Info("img2" + (param)); |
|
|
if (string.IsNullOrEmpty(param)) |
|
|
{ |
|
|
//关闭 |
|
|
//StopSn("0"); |
|
|
string result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"suffix\":\"jpg\",\"data\":\"" + "获取图片失败" + "\"}"; |
|
|
SubmitLogs(result, "openCamera"); |
|
|
return result; |
|
|
} |
|
|
else |
|
|
{ |
|
|
//关闭 |
|
|
//StopSn("0"); |
|
|
string result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"jpg\",\"data\":\"" + param + "\"}"; |
|
|
SubmitLogs(result, "openCamera"); |
|
|
return result; |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
catch (Exception ex) |
|
|
{ |
|
|
//Log.Error("打开高拍仪并且进行快速扫描文件异常: " + ex.Message + ""); |
|
|
string result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; |
|
|
SubmitLogs(result, "openCamera"); |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
/// <summary> |
|
|
/// aks100105打开签字版 sudo apt-get install libgdiplus (已国产化) |
|
|
/// </summary> |
|
|
/// <param name="paramsString"></param> |
|
|
/// <returns></returns> |
|
|
public static string OpenSign(string content) |
|
|
{ |
|
|
var param = content.ConvertToAnonymousType(new |
|
|
{ |
|
|
code = default(string) |
|
|
}); |
|
|
try |
|
|
{ |
|
|
if (param == null) |
|
|
{ |
|
|
return "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + "" + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "参数解析错误" + "\"}"; |
|
|
} |
|
|
if (!isFuncisFuncObject("OpenSign")) |
|
|
{ |
|
|
//Utils.MessagesBox("签字版设备未授权使用"); |
|
|
return "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "签字版设备未授权使用" + "\"}"; |
|
|
} |
|
|
else |
|
|
{ |
|
|
Task.Run(() => { HttpPostResponseBySign("open", 1, param.code); }); |
|
|
@event3.WaitOne(); |
|
|
string result = sginStr; |
|
|
SubmitLogs(result, "OpenSign"); |
|
|
return result; |
|
|
} |
|
|
} |
|
|
catch (Exception ex) |
|
|
{ |
|
|
//Log.Error("打开签字版异常: " + ex.Message + ""); |
|
|
string result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; |
|
|
SubmitLogs(result, "OpenSign"); |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
/// <summary> |
|
|
/// 关闭签字版 (已国产化) |
|
|
/// </summary> |
|
|
/// <param name="paramsString"></param> |
|
|
/// <returns></returns> |
|
|
private static string CloseSign(string code) |
|
|
{ |
|
|
try |
|
|
{ |
|
|
if (!isFuncisFuncObject("OpenSign")) |
|
|
{ |
|
|
//Utils.MessagesBox("签字版设备未授权使用"); |
|
|
return "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "签字版设备未授权使用" + "\"}"; |
|
|
} |
|
|
else |
|
|
{ |
|
|
Task.Run(() => HttpPostResponseBySign("close", 2, "")); |
|
|
string result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"jpg\",\"data\":\"" + "签字版已关闭" + "\"}"; |
|
|
SubmitLogs(result, "openCamera"); |
|
|
return result; |
|
|
} |
|
|
} |
|
|
catch (Exception ex) |
|
|
{ |
|
|
//Log.Error("关闭签字版异常: " + ex.Message + ""); |
|
|
string result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; |
|
|
SubmitLogs(result, "OpenSign"); |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
/// <summary> |
|
|
/// aks100106指纹 (已国产化,未完成测试) |
|
|
/// </summary> |
|
|
/// <param name="paramsString"></param> |
|
|
/// <returns></returns> |
|
|
public static string ReadFingerData(string content) |
|
|
{ |
|
|
var param = content.ConvertToAnonymousType(new |
|
|
{ |
|
|
code = default(string), |
|
|
isclose = default(bool) |
|
|
}); |
|
|
try |
|
|
{ |
|
|
if (param == null) |
|
|
{ |
|
|
return "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + "" + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "参数解析错误" + "\"}"; |
|
|
} |
|
|
if (!isFuncisFuncObject("ReadFingerData")) |
|
|
{ |
|
|
//Utils.MessagesBox("指纹设备未授权使用"); |
|
|
return "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "指纹设备未授权使用" + "\"}"; |
|
|
} |
|
|
else |
|
|
{ |
|
|
if (param.isclose) |
|
|
{ |
|
|
Task.Run(() => { HttpPostResponseByFinger("close", 2); }); |
|
|
event2.WaitOne(); |
|
|
string result = string.Empty; |
|
|
if (string.IsNullOrEmpty(fingerStr)) |
|
|
{ |
|
|
result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "关闭失败" + "\"}"; |
|
|
SubmitLogs(result, "ReadFingerData"); |
|
|
} |
|
|
else |
|
|
{ |
|
|
result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + param.code + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + "关闭成功" + "\"}"; |
|
|
} |
|
|
SubmitLogs(result, "ReadFingerData"); |
|
|
return result; |
|
|
} |
|
|
else |
|
|
{ |
|
|
Task.Run(() => { HttpPostResponseByFinger("open", 1); }); |
|
|
event2.WaitOne(); |
|
|
string result = string.Empty; |
|
|
Log.Info("指纹数据" + fingerStr); |
|
|
if (string.IsNullOrEmpty(fingerStr)) |
|
|
{ |
|
|
result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "读取失败" + "\"}"; |
|
|
SubmitLogs(result, "ReadFingerData"); |
|
|
} |
|
|
else |
|
|
{ |
|
|
result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + param.code + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"jpg\",\"data\":\"" + fingerStr + "\"}"; |
|
|
} |
|
|
SubmitLogs(result, "ReadFingerData"); |
|
|
return result; |
|
|
} |
|
|
} |
|
|
} |
|
|
catch (Exception ex) |
|
|
{ |
|
|
//Log.Error("指纹异常: " + ex.Message + ""); |
|
|
string result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; |
|
|
SubmitLogs(result, "ReadFingerData"); |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
/// <summary> |
|
|
/// aks100107开始录音、取消录音、结束录音 (已国产化) |
|
|
/// sudo apt-get update |
|
|
/// sudo apt-get install alsa-utils |
|
|
/// </summary> |
|
|
/// <param name="isopen"></param> |
|
|
/// <param name="url"></param> |
|
|
/// <returns></returns> |
|
|
public static string SoundRecording(string content) |
|
|
{ |
|
|
var param = content.ConvertToAnonymousType(new |
|
|
{ |
|
|
code = default(string), |
|
|
isopen = default(bool), |
|
|
url = default(string) |
|
|
}); |
|
|
|
|
|
try |
|
|
{ |
|
|
if (param == null) |
|
|
{ |
|
|
return "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + "" + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "参数解析错误" + "\"}"; |
|
|
} |
|
|
bool isopen = param.isopen; |
|
|
string url = param.url; |
|
|
if (!isFuncisFuncObject("SoundRecording")) |
|
|
{ |
|
|
Utils.MessagesBox("录音设备未授权使用"); |
|
|
return "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"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]+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)"); |
|
|
MatchCollection mc = re.Matches(url);//获取的是一个数组 |
|
|
string reurl = mc[0].ToString() + "://" + mc[1].ToString() + urlpath; |
|
|
|
|
|
string result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + param.code + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"wav\",\"data\":\"" + reurl + "\"}"; |
|
|
SubmitLogs(result, "SoundRecording"); |
|
|
return result; |
|
|
} |
|
|
else |
|
|
{ |
|
|
string result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + param.code + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"suffix\":\"wav\",\"data\":\"" + "结束录音失败" + "\"}"; |
|
|
SubmitLogs(result, "SoundRecording"); |
|
|
return result; |
|
|
} |
|
|
} |
|
|
else if (isopen)//开始录音 |
|
|
{ |
|
|
if (StartRecording()) |
|
|
{ |
|
|
string result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + param.code + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"wav\",\"data\":\"" + "开始录音" + "\"}"; |
|
|
SubmitLogs(result, "SoundRecording"); |
|
|
return result; |
|
|
} |
|
|
else |
|
|
{ |
|
|
string result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + param.code + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"suffix\":\"wav\",\"data\":\"" + "录音失败" + "\"}"; |
|
|
SubmitLogs(result, "SoundRecording"); |
|
|
return result; |
|
|
} |
|
|
} |
|
|
else //取消录音 |
|
|
{ |
|
|
if (StopRecording()) |
|
|
{ |
|
|
srpath = string.Empty; |
|
|
string result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + param.code + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"wav\",\"data\":\"" + "取消录音" + "\"}"; |
|
|
SubmitLogs(result, "SoundRecording"); |
|
|
return result; |
|
|
} |
|
|
else |
|
|
{ |
|
|
srpath = string.Empty; |
|
|
string result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"suffix\":\"wav\",\"data\":\"" + "取消录音失败" + "\"}"; |
|
|
SubmitLogs(result, "SoundRecording"); |
|
|
return result; |
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
catch (Exception ex) |
|
|
{ |
|
|
//Log.Error("开始录音、取消录音、结束录音异常: " + ex.Message + ""); |
|
|
string result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; |
|
|
SubmitLogs(result, "SoundRecording"); |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
/// <summary> |
|
|
/// aks100108根据文件地址在线打印 (已国产化) |
|
|
/// </summary> |
|
|
/// <param name="filename"></param> |
|
|
/// <returns></returns> |
|
|
public static string PrintFile(string content) |
|
|
{ |
|
|
var param = content.ConvertToAnonymousType(new |
|
|
{ |
|
|
code = default(string), |
|
|
url = default(string), |
|
|
ext = default(string) |
|
|
}); |
|
|
try |
|
|
{ |
|
|
if (param == null) |
|
|
{ |
|
|
return "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + "" + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "参数解析错误" + "\"}"; |
|
|
} |
|
|
string url = param.url; |
|
|
string ext = param.ext; |
|
|
if (!isFuncisFuncObject("PrintFile")) |
|
|
{ |
|
|
//Utils.MessagesBox("打印机设备未授权使用"); |
|
|
return "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "打印机设备未授权使用" + "\"}"; |
|
|
} |
|
|
else |
|
|
{ |
|
|
Task.Run(async () => |
|
|
{ |
|
|
DateTime dateTime = DateTime.Now; |
|
|
string time = DateTime.Now.ToString( |
|
|
"yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo); |
|
|
string dirpath = Utils.getSystemPaht() + @"/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 = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + param.code + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + "打印成功" + "\"}"; |
|
|
SubmitLogs(result, "PrintFile"); |
|
|
return result; |
|
|
} |
|
|
} |
|
|
catch (Exception ex) |
|
|
{ |
|
|
//Log.Error("根据文件地址在线打印异常: " + ex.Message + ""); |
|
|
string result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; |
|
|
SubmitLogs(result, "PrintFile"); |
|
|
return result; |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
/// <summary> |
|
|
/// aks100109根据文件base64打印 (已国产化)PrintBase64 |
|
|
/// </summary> |
|
|
/// <param name="base64"></param> |
|
|
/// <param name="ext"></param> |
|
|
/// <returns></returns> |
|
|
//[JSFunction] |
|
|
public static string PrintBase64(string content) |
|
|
{ |
|
|
var param = content.ConvertToAnonymousType(new |
|
|
{ |
|
|
code = default(string), |
|
|
base64 = default(string), |
|
|
ext = default(string) |
|
|
}); |
|
|
try |
|
|
{ |
|
|
if (param == null) |
|
|
{ |
|
|
return "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + "" + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "参数解析错误" + "\"}"; |
|
|
} |
|
|
if (!isFuncisFuncObject("PrintBase64")) |
|
|
{ |
|
|
//Utils.MessagesBox("打印机设备未授权使用"); |
|
|
return "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "打印机设备未授权使用" + "\"}"; |
|
|
} |
|
|
else |
|
|
{ |
|
|
Task.Run(async () => |
|
|
{ |
|
|
DateTime dateTime = DateTime.Now; |
|
|
string time = DateTime.Now.ToString( |
|
|
"yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo); |
|
|
string dirpath = Utils.getSystemPaht() + @"/wwwroot/PrintFile"; |
|
|
if (!Directory.Exists(dirpath)) |
|
|
{ |
|
|
Directory.CreateDirectory(dirpath); |
|
|
} |
|
|
var filepath = System.IO.Path.Combine(dirpath, time); |
|
|
string path = dirpath + @"/" + time + "." + param.ext; |
|
|
byte[] bytes = Convert.FromBase64String(param.base64); |
|
|
System.IO.FileStream stream = new System.IO.FileStream(path, System.IO.FileMode.CreateNew); |
|
|
System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream); |
|
|
writer.Write(bytes, 0, bytes.Length); |
|
|
writer.Close(); |
|
|
//// Log.Info("根据文件base64打印: " + path + ""); |
|
|
string command = $"lp -d {PrinterName} {path}"; |
|
|
ShllCommad(command); |
|
|
}); |
|
|
string result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + param.code + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + "打印成功" + "\"}"; |
|
|
SubmitLogs(result, "PrintBase64"); |
|
|
return result; |
|
|
} |
|
|
} |
|
|
catch (Exception ex) |
|
|
{ |
|
|
string result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; |
|
|
SubmitLogs(result, "PrintBase64"); |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
/// <summary> |
|
|
/// aks100110播放音频文件 (已国产化) |
|
|
/// </summary> |
|
|
/// <param name="url"></param> |
|
|
/// <param name="ispaly"></param> |
|
|
/// <returns></returns> |
|
|
public static string PalyFile(string content) |
|
|
{ |
|
|
var param = content.ConvertToAnonymousType(new |
|
|
{ |
|
|
code = default(string), |
|
|
url = default(string), |
|
|
ispaye = default(bool) |
|
|
}); |
|
|
try |
|
|
{ |
|
|
if (param == null) |
|
|
{ |
|
|
return "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + "" + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "参数解析错误" + "\"}"; |
|
|
} |
|
|
string url = param.url; |
|
|
bool ispaly = param.ispaye; |
|
|
if (!isFuncisFuncObject("PalyFile")) |
|
|
{ |
|
|
//Utils.MessagesBox("音频设备未授权使用"); |
|
|
return "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "音频设备未授权使用" + "\"}"; |
|
|
} |
|
|
else |
|
|
{ |
|
|
if (ispaly) |
|
|
{ |
|
|
Task.Run(() => |
|
|
{ |
|
|
if (Typrocess != null) |
|
|
{ |
|
|
// 如果进程还在运行 |
|
|
if (!Typrocess.HasExited) |
|
|
{ |
|
|
// 发送SIGTERM信号来停止进程 |
|
|
Typrocess.Kill(); |
|
|
// 等待进程真正停止 |
|
|
Typrocess.WaitForExit(); |
|
|
} |
|
|
} |
|
|
//AutoAudio(ispaly, ""); |
|
|
}); |
|
|
string result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + param.code + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + "停止播放成功" + "\"}"; |
|
|
SubmitLogs(result, "PalyFile"); |
|
|
return result; |
|
|
} |
|
|
else |
|
|
{ |
|
|
Task.Run(() => |
|
|
{ |
|
|
Task.Run(() => |
|
|
{ |
|
|
if (Typrocess != null) |
|
|
{ |
|
|
// 如果进程还在运行 |
|
|
if (!Typrocess.HasExited) |
|
|
{ |
|
|
// 发送SIGTERM信号来停止进程 |
|
|
Typrocess.Kill(); |
|
|
// 等待进程真正停止 |
|
|
Typrocess.WaitForExit(); |
|
|
} |
|
|
} |
|
|
//AutoAudio(ispaly, ""); |
|
|
}); |
|
|
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 = Utils.getSystemPaht() + @"/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); |
|
|
//AutoAudio(ispaly, path); |
|
|
}); |
|
|
string result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + param.code + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + "开始播放" + "\"}"; |
|
|
SubmitLogs(result, "PalyFile"); |
|
|
return result; |
|
|
} |
|
|
} |
|
|
} |
|
|
catch (Exception ex) |
|
|
{ |
|
|
string result = "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; |
|
|
SubmitLogs(result, "PalyFile"); |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
/// <summary> |
|
|
/// aks100111唤醒键盘 (已国产化) |
|
|
/// </summary> |
|
|
/// <param name="filename"></param> |
|
|
/// <returns></returns> |
|
|
public static string openKey(string code) |
|
|
{ |
|
|
try |
|
|
{ |
|
|
Task.Run(() => |
|
|
{ |
|
|
Bash("/usr/bin/python3 /usr/bin/onboard"); |
|
|
}); |
|
|
return "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"message\":\"seccse\",\"code\":\"200\",\"status\":true,\"data\":\"" + "唤醒键盘成功" + "\"}"; |
|
|
} |
|
|
catch (Exception ex) |
|
|
{ |
|
|
//Log.Error("唤醒键盘异常: " + ex.Message + ""); |
|
|
return "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; |
|
|
} |
|
|
} |
|
|
|
|
|
/// <summary> |
|
|
/// 执行文件 |
|
|
/// </summary> |
|
|
/// <param name="command"></param> |
|
|
/// <returns></returns> |
|
|
public static string Bash(string command) |
|
|
{ |
|
|
try |
|
|
{ |
|
|
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; |
|
|
} |
|
|
catch (Exception ex) |
|
|
{ |
|
|
//Log.Error("执行文件异常:" + ex.Message); |
|
|
} |
|
|
return ""; |
|
|
} |
|
|
|
|
|
/// <summary> |
|
|
/// 获取设备index |
|
|
/// </summary> |
|
|
/// <returns></returns> |
|
|
public static string GetSnIndex() |
|
|
{ |
|
|
try |
|
|
{ |
|
|
//获取设备信息 |
|
|
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 ""; |
|
|
} |
|
|
} |
|
|
} |
|
|
catch (Exception ex) |
|
|
{ |
|
|
//Log.Error("获取设备index异常:" + ex.Message); |
|
|
} |
|
|
return ""; |
|
|
} |
|
|
|
|
|
/// <summary> |
|
|
/// 打开高拍仪 |
|
|
/// </summary> |
|
|
/// <returns></returns> |
|
|
public static string OpenSn(string dev_idx) |
|
|
{ |
|
|
try |
|
|
{ |
|
|
//获取设备信息 |
|
|
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" || jo["returnCode"].ToString() == "2") |
|
|
{ |
|
|
return "200"; |
|
|
} |
|
|
else |
|
|
{ |
|
|
return ""; |
|
|
} |
|
|
} |
|
|
} |
|
|
catch (Exception ex) |
|
|
{ |
|
|
//Log.Error("打开高拍仪异常:" + ex.Message); |
|
|
} |
|
|
return ""; |
|
|
} |
|
|
|
|
|
/// <summary> |
|
|
/// 关闭高拍仪 |
|
|
/// </summary> |
|
|
/// <returns></returns> |
|
|
public static 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() == "2" || jo["returnCode"].ToString() == "0") |
|
|
{ |
|
|
return "200"; |
|
|
} |
|
|
else |
|
|
{ |
|
|
// // Log.Info(jo["returnMsg"].ToString()); |
|
|
return ""; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
/// <summary> |
|
|
/// 拍照 |
|
|
/// </summary> |
|
|
/// <returns></returns> |
|
|
public static string getFrame() |
|
|
{ |
|
|
string result = string.Empty; |
|
|
try |
|
|
{ |
|
|
//获取设备信息 |
|
|
string param = "/getFrame"; |
|
|
Task.Run(() => HttpResponse(param)); |
|
|
@event6.WaitOne(); |
|
|
Log.Info(gpyStr); |
|
|
if (string.IsNullOrEmpty(gpyStr)) |
|
|
{ |
|
|
result = ""; |
|
|
} |
|
|
else |
|
|
{ |
|
|
JObject jo = (JObject)JsonConvert.DeserializeObject(gpyStr); |
|
|
if (jo["returnCode"].ToString() == "0") |
|
|
{ |
|
|
string data = jo["data"].ToString(); |
|
|
JObject jo1 = (JObject)JsonConvert.DeserializeObject(data); |
|
|
result = jo1["img"].ToString(); |
|
|
} |
|
|
else |
|
|
{ |
|
|
result = ""; |
|
|
} |
|
|
} |
|
|
} |
|
|
catch (Exception ex) |
|
|
{ |
|
|
//Log.Error("拍照异常:" + ex.Message); |
|
|
} |
|
|
return result; |
|
|
} |
|
|
|
|
|
/// <summary> |
|
|
/// 右转 |
|
|
/// </summary> |
|
|
/// <returns></returns> |
|
|
public static string RotateRight() |
|
|
{ |
|
|
try |
|
|
{ |
|
|
//获取设备信息 |
|
|
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 ""; |
|
|
} |
|
|
} |
|
|
} |
|
|
catch (Exception ex) |
|
|
{ |
|
|
//Log.Error("右转异常:" + ex.Message); |
|
|
} |
|
|
return ""; |
|
|
} |
|
|
|
|
|
/// <summary> |
|
|
/// 左转 |
|
|
/// </summary> |
|
|
/// <returns></returns> |
|
|
public static string RotateLeft() |
|
|
{ |
|
|
try |
|
|
{ |
|
|
//获取设备信息 |
|
|
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 ""; |
|
|
} |
|
|
} |
|
|
} |
|
|
catch (Exception ex) |
|
|
{ |
|
|
//Log.Error("左转异常:" + ex.Message); |
|
|
} |
|
|
return ""; |
|
|
} |
|
|
|
|
|
/// <summary> |
|
|
/// 高拍仪 |
|
|
/// </summary> |
|
|
private static string gpyStr = string.Empty; |
|
|
private static AutoResetEvent @event6 = new AutoResetEvent(false); |
|
|
private static async void HttpResponse(string param) |
|
|
{ |
|
|
try |
|
|
{ |
|
|
var httpClient = new HttpClient(); |
|
|
var uploader = new ChunkedUpload(httpClient); |
|
|
gpyStr = await uploader.getReq(param); |
|
|
@event6.Set(); |
|
|
} |
|
|
catch (Exception ex) |
|
|
{ |
|
|
//Log.Error("高拍仪异常:" + ex.Message); |
|
|
} |
|
|
} |
|
|
|
|
|
private static string sginStr = string.Empty; |
|
|
private static AutoResetEvent @event3 = new AutoResetEvent(false); |
|
|
/// <summary> |
|
|
/// 签字版 |
|
|
/// </summary> |
|
|
private static async void HttpPostResponseBySign(string type, int typeCode, string code) |
|
|
{ |
|
|
try |
|
|
{ |
|
|
var httpClient = new HttpClient(); |
|
|
var uploader = new ChunkedUpload(httpClient); |
|
|
sginStr = await uploader.PostSign(type, typeCode, code); |
|
|
@event3.Set(); |
|
|
} |
|
|
catch (Exception ex) |
|
|
{ |
|
|
//Log.Error("签字版异常:" + ex.Message); |
|
|
} |
|
|
} |
|
|
|
|
|
private static string ttsStr = string.Empty; |
|
|
/// <summary> |
|
|
/// 文字转语音 |
|
|
/// </summary> |
|
|
private static async void HttpPostResponseByTTS(string type, int typeCode, string tts_text) |
|
|
{ |
|
|
try |
|
|
{ |
|
|
var httpClient = new HttpClient(); |
|
|
var uploader = new ChunkedUpload(httpClient); |
|
|
ttsStr = await uploader.PostTTS(type, typeCode, tts_text); |
|
|
@event2.Set(); |
|
|
} |
|
|
catch (Exception ex) |
|
|
{ |
|
|
//Log.Error("签字版异常:" + ex.Message); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private static string fingerStr = string.Empty; |
|
|
/// <summary> |
|
|
/// 指紋 |
|
|
/// </summary> |
|
|
private static async void HttpPostResponseByFinger(string type, int typeCode) |
|
|
{ |
|
|
try |
|
|
{ |
|
|
var httpClient = new HttpClient(); |
|
|
var uploader = new ChunkedUpload(httpClient); |
|
|
fingerStr = await uploader.PostFinger(type, typeCode); |
|
|
@event2.Set(); |
|
|
} |
|
|
catch (Exception ex) |
|
|
{ |
|
|
//Log.Error("签字版异常:" + ex.Message); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private static string IdcardStr = string.Empty; |
|
|
private static AutoResetEvent @event7 = new AutoResetEvent(false); |
|
|
/// <summary> |
|
|
/// 读取身份证 |
|
|
/// </summary> |
|
|
private static async void HttpPostResponseByIdcard(string type, int typeCode) |
|
|
{ |
|
|
try |
|
|
{ |
|
|
var httpClient = new HttpClient(); |
|
|
var uploader = new ChunkedUpload(httpClient); |
|
|
IdcardStr = await uploader.OpenGetIdcard(type, typeCode); |
|
|
@event7.Set(); |
|
|
} |
|
|
catch (Exception ex) |
|
|
{ |
|
|
//Log.Error("签字版异常:" + ex.Message); |
|
|
} |
|
|
} |
|
|
|
|
|
/// <summary> |
|
|
/// 初始文件上传 |
|
|
/// </summary> |
|
|
private static string urlpath = string.Empty; |
|
|
private static AutoResetEvent @event2 = new AutoResetEvent(false); |
|
|
private static async void UploadInfo(string url, string srpath) |
|
|
{ |
|
|
try |
|
|
{ |
|
|
var httpClient = new HttpClient(); |
|
|
var uploader = new ChunkedUpload(httpClient); |
|
|
urlpath = await uploader.UploadFileAsync(url, srpath); |
|
|
@event2.Set(); |
|
|
} |
|
|
catch (Exception ex) |
|
|
{ |
|
|
//Log.Error("初始文件上传异常:" + ex.Message); |
|
|
} |
|
|
} |
|
|
|
|
|
//上传本地文件中转 |
|
|
private static string urlP = string.Empty; |
|
|
private static AutoResetEvent @event5 = new AutoResetEvent(false); |
|
|
private static async void UploadInfoByFile(string url, string strpath) |
|
|
{ |
|
|
try |
|
|
{ |
|
|
var httpClient = new HttpClient(); |
|
|
var uploader = new ChunkedUpload(httpClient); |
|
|
urlP = await uploader.UploadFileAsync(url, strpath); |
|
|
File.Delete(strpath); |
|
|
@event5.Set(); |
|
|
} |
|
|
catch (Exception ex) |
|
|
{ |
|
|
//Log.Error("上传本地文件中转异常:" + ex.Message); |
|
|
} |
|
|
} |
|
|
|
|
|
//根据程序名称杀死进程 |
|
|
public static void KillProcessByName(string processName) |
|
|
{ |
|
|
try |
|
|
{ |
|
|
Process[] processes = Process.GetProcessesByName(processName); |
|
|
|
|
|
foreach (Process process in processes) |
|
|
{ |
|
|
try |
|
|
{ |
|
|
process.Kill(); |
|
|
process.WaitForExit(); // 等待进程退出 |
|
|
} |
|
|
catch (Exception ex) { } |
|
|
} |
|
|
} |
|
|
catch (Exception ex) |
|
|
{ |
|
|
//Log.Error("根据程序名称杀死进程异常:" + ex.Message); |
|
|
} |
|
|
} |
|
|
|
|
|
/// <summary> |
|
|
/// 开始录音 |
|
|
/// </summary> |
|
|
/// <returns></returns> |
|
|
public static 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 = Utils.getSystemPaht() + @"/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 --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; |
|
|
} |
|
|
} |
|
|
|
|
|
/// <summary> |
|
|
/// 结束录音 |
|
|
/// </summary> |
|
|
public static bool StopRecording() |
|
|
{ |
|
|
try |
|
|
{ |
|
|
if (recordingProcess != null) |
|
|
{ |
|
|
// 如果进程还在运行 |
|
|
if (!recordingProcess.HasExited) |
|
|
{ |
|
|
// 发送SIGTERM信号来停止arecord进程 |
|
|
recordingProcess.Kill(); |
|
|
recordingProcess.WaitForExit(); // 等待进程真正停止 |
|
|
} |
|
|
} |
|
|
return true; |
|
|
} |
|
|
catch (Exception ex) |
|
|
{ |
|
|
//Log.Error("结束录音异常:" + ex.Message); |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
/// <summary> |
|
|
/// 执行命令 |
|
|
/// </summary> |
|
|
public static void ShllCommad(string command) |
|
|
{ |
|
|
try |
|
|
{ |
|
|
//// 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(); |
|
|
} |
|
|
catch (Exception ex) |
|
|
{ |
|
|
//Log.Error("执行命令异常:" + ex.Message); |
|
|
} |
|
|
} |
|
|
|
|
|
/// <summary> |
|
|
/// 开源文字转语音 |
|
|
/// sudo apt-get install espeak |
|
|
/// </summary> |
|
|
/// <param name="text"></param> |
|
|
/// <returns></returns> |
|
|
static string GenerateWavFromText(string text) |
|
|
{ |
|
|
string time = DateTime.Now.ToString( |
|
|
"yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo); |
|
|
string dirpath = Utils.getSystemPaht() + @"/wwwroot/WavFile"; |
|
|
// // Log.Info(dirpath); |
|
|
if (!Directory.Exists(dirpath)) |
|
|
{ |
|
|
Directory.CreateDirectory(dirpath); |
|
|
} |
|
|
var tempFile = dirpath + "/" + time + ".wav"; |
|
|
try |
|
|
{ |
|
|
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(); |
|
|
} |
|
|
} |
|
|
catch (Exception ex) |
|
|
{ |
|
|
//Log.Error("文字转语音失败:" + ex.Message); |
|
|
} |
|
|
return tempFile; |
|
|
} |
|
|
|
|
|
/// <summary> |
|
|
/// 开源文字转语音 |
|
|
/// sudo apt-get install espeak |
|
|
/// </summary> |
|
|
/// <param name="text"></param> |
|
|
/// <returns></returns> |
|
|
static string GenerateWavFromText2(string text) |
|
|
{ |
|
|
string time = DateTime.Now.ToString( |
|
|
"yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo); |
|
|
string dirpath = Utils.getSystemPaht() + @"/wwwroot/WavFile"; |
|
|
// // Log.Info(dirpath); |
|
|
if (!Directory.Exists(dirpath)) |
|
|
{ |
|
|
Directory.CreateDirectory(dirpath); |
|
|
} |
|
|
var tempFile = dirpath + "/" + time + ".wav"; |
|
|
try |
|
|
{ |
|
|
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(); |
|
|
} |
|
|
} |
|
|
catch (Exception ex) |
|
|
{ |
|
|
//Log.Error("文字转语音失败:" + ex.Message); |
|
|
} |
|
|
return tempFile; |
|
|
} |
|
|
/// <summary> |
|
|
/// 是否已获取收取 |
|
|
/// </summary> |
|
|
/// <param name="funcName"></param> |
|
|
/// <returns></returns> |
|
|
public static bool isFuncisFuncObject(string funcName) |
|
|
{ |
|
|
bool isFunc = false; |
|
|
try |
|
|
{ |
|
|
if (Parame.FuncObject != null) |
|
|
{ |
|
|
if (Parame.FuncObject.Count > 0) |
|
|
{ |
|
|
foreach (Func func in Parame.FuncObject) |
|
|
{ |
|
|
if (func.Interfaceaddress.Contains(funcName)) |
|
|
{ |
|
|
isFunc = true; |
|
|
break; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
catch (Exception ex) |
|
|
{ |
|
|
//Log.Error("是否已获取收取异常:" + ex.Message); |
|
|
} |
|
|
return isFunc; |
|
|
} |
|
|
|
|
|
/// <summary> |
|
|
/// 提交设备操作日志 |
|
|
/// </summary> |
|
|
/// <param name="Describer"></param> |
|
|
/// <param name="funcName"></param> |
|
|
public static void SubmitLogs(string Describer, string funcName) |
|
|
{ |
|
|
try |
|
|
{ |
|
|
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); |
|
|
} |
|
|
} |
|
|
}); |
|
|
} |
|
|
catch (Exception ex) |
|
|
{ |
|
|
//Log.Error("提交设备操作日志异常:" + ex.Message); |
|
|
} |
|
|
} |
|
|
|
|
|
/// <summary> |
|
|
/// 播放语音文件 |
|
|
/// </summary> |
|
|
/// <param name="ispaly"></param> |
|
|
public static void AutoAudio(bool ispaly, string path) |
|
|
{ |
|
|
try |
|
|
{ |
|
|
if (ispaly) |
|
|
{ |
|
|
Parame.videoV.Play(new Uri(path));//播放 |
|
|
} |
|
|
else |
|
|
{ |
|
|
Parame.videoV.Pause();//停止 |
|
|
} |
|
|
} |
|
|
catch (Exception ex) |
|
|
{ |
|
|
//Log.Error("播放语音文件异常:" + ex.Message); |
|
|
} |
|
|
} |
|
|
|
|
|
/// <summary> |
|
|
/// string 转换为 base64 |
|
|
/// </summary> |
|
|
/// <returns></returns> |
|
|
public static string str2Base64(string str) |
|
|
{ |
|
|
try |
|
|
{ |
|
|
byte[] b = System.Text.Encoding.UTF8.GetBytes(str); |
|
|
string result = Convert.ToBase64String(b); |
|
|
return result; |
|
|
} |
|
|
catch (Exception ex) |
|
|
{ |
|
|
//Log.Error("string 转换为 base64异常:" + ex.Message); |
|
|
} |
|
|
return ""; |
|
|
} |
|
|
|
|
|
/// <summary> |
|
|
/// base64 转换为 string |
|
|
/// </summary> |
|
|
/// <param name="data"></param> |
|
|
public static string Base64str2(string data) |
|
|
{ |
|
|
try |
|
|
{ |
|
|
byte[] c = Convert.FromBase64String(data); |
|
|
string result = System.Text.Encoding.UTF8.GetString(c); |
|
|
//// Log.Info("接收返回数据:" + result); |
|
|
return result; |
|
|
} |
|
|
catch (Exception ex) |
|
|
{ |
|
|
//Log.Error("base64 转换为 string异常:" + ex.Message); |
|
|
} |
|
|
return ""; |
|
|
} |
|
|
} |
|
|
}
|
|
|
|