采用网络对联方式交互数据
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

2067 lines
90 KiB

using AksWebBrowser;
using AksWebBrowser.Common;
using AksWebBrowser.Devices;
using AKSWebBrowser.Commen;
using CPF;
using CPF.Linux;
using CPF.Windows;
using Fleck;
using LibVLCSharp.Shared;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using SkiaSharp;
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.Net.WebSockets;
using System.Reflection.Metadata;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using static System.Net.Mime.MediaTypeNames;
namespace AKS.EnterpriseLibrary.WebBrowser
{
public class MainModel : CPF.CpfObject
{
private static List<IWebSocketConnection> allSockets;
//初始化网络连接
public static void DeviceControllerInit()
{
try
{
allSockets = new List<IWebSocketConnection>();
var server = new WebSocketServer("ws://0.0.0.0:19983");
server.Start(socket =>
{
Parame.socket = socket;
socket.OnOpen = () =>
{
allSockets.Add(socket);
string result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + "" + "\",\"message\":\"seccse\",\"code\":\"200\",\"status\":true,\"data\":\"连接成功\"}";
socket.Send(result);
};
socket.OnClose = () =>
{
allSockets.Remove(socket);
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))
{
//检测服务是否启动
//StartShll();
//返回内容
string result = string.Empty;
content = Base64str2(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","timeout":30}
case "aks100101":
result = IDCardRead(content);
break;
//aks100102
//打印排队票据 {"code":"aks100102","ph":"100101","ddrs":"中国检察","qrcode":"90087100100124433002","ywmc":"信访"}
case "aks100102":
result = SendByPrint(content);
break;
//aks100103
//文字语音播报
//播放:{ "code":"aks100103","text":"你好!","ispaye":false,"ywid":"1234567890"},
//停止播放:{ "code":"aks100104","text":"","ispaye":true,"ywid":"1234567890"}
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;
//aks100114
//文字语音播报
//播放:{ "code":"aks100114","text":"你好!","ispaye":false,"ywid":"1234567890"},
case "aks100114":
result = payleTextByWav(content);
break;
//播放:{ "code":"aks100115","title":"測試","url":"http://127.0.0.1/test.mp4"},
case "aks100115":
result = playVideo(content);
break;
//刻录文件:{ "code":"aks100116","name":"测试文件","obj":"http://127.0.0.1/test.doc","ext":"doc"}, obj:可以是url地址或者base64
case "aks100116":
result = BurnFile(content);
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
{
if (!string.IsNullOrEmpty(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 content)
{
try
{
var param = content.ConvertToAnonymousType(new
{
code = default(string),
timeout = default(int)
});
Task.Run(() => { HttpPostResponseByIdcard("open", 1, param.timeout); });
@event7.WaitOne();
string result = IdcardStr;
if (string.IsNullOrEmpty(IdcardStr))
{
result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + param.code + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "读取身份证失败" + "\"}";
}
else
{
if (IdcardStr.Contains("HttpClient.Timeout"))
{
result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + param.code + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "身份证读取失败" + "\"}";
}
else
{
if (Parame.isSM)
{
Task.Run(async () =>
{
string results = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + param.code + "\",\"message\":\"seccse\",\"code\":\"200\",\"status\":true,\"data\":" + IdcardStr + "}";
StartFace(results);
});
result = "";
}
else
{
result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + param.code + "\",\"message\":\"seccse\",\"code\":\"200\",\"status\":true,\"data\":" + IdcardStr + "}";
}
return result;
}
}
SubmitLogs(result, "IDCardRead");
return result;
}
catch (Exception ex)
{
//Log.Error("读取身份证卡号异常: " + ex.Message + "");
string result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + "" + "\",\"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)
{
try
{
var param = content.ConvertToAnonymousType(new
{
code = default(string),
ph = default(string),
ddrs = default(string),
qrcode = default(string),
ywmc = default(string)
});
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\":\"" + "" + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
SubmitLogs(result, "SendByPrint");
return result;
}
}
/// <summary>
/// aks100103文字语音播报
/// </summary>
/// <param name="content"></param>
/// <returns></returns>
public static string payleText(string content)
{
try
{
var param = content.ConvertToAnonymousType(new
{
code = default(string),
text = default(string),
ywid = default(string),
ispaye = default(bool),
});
if (param == null)
{
return "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + "" + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "参数解析错误" + "\"}";
}
string text = param.text;
string ywid = param.ywid;
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(() =>
{
Task.Run(() => { string command = $"pkill sox"; ShllCommad(command); });
});
string result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + param.code + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + "停止播放成功" + "\"}";
SubmitLogs(result, "payleText");
return result;
}
else
{
string dirpath = Utils.getSystemPaht() + @"/wwwroot/SignFile";
if (!Directory.Exists(dirpath))
{
Directory.CreateDirectory(dirpath);
}
var tempFile = dirpath + $"/{ywid}.wav";
string result = string.Empty;
if (!File.Exists(tempFile))
{
Task.Run(() => { HttpPostResponseByTTS("text_to_wav", 1, text); });
event2.WaitOne();
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); });
if (!string.IsNullOrEmpty(ywid))
{
string filename = Path.GetFileName(ttsStr);
Log.Info(filename);
string source_file = dirpath + $"/{filename}";
Log.Info(source_file);
string command = $"cp {ttsStr} -t {dirpath} && mv {source_file} {tempFile}";
ShllCommad(command);
}
result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + param.code + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + "开始播放" + "\"}";
}
}
else
{
Task.Run(() => { string command = $"sox {tempFile} -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\":\"" + "" + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
SubmitLogs(result, "payleText");
return result;
}
}
/// <summary>
/// aks100103文字语音播报
/// </summary>
/// <param name="content"></param>
/// <returns></returns>
public static string payleTextByWav(string content)
{
try
{
var param = content.ConvertToAnonymousType(new
{
code = default(string),
text = default(string),
ywid = default(string),
ispaye = default(bool),
});
if (param == null)
{
return "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + "" + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "参数解析错误" + "\"}";
}
string text = param.text;
string ywid = param.ywid;
bool ispaye = param.ispaye;
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\":\"" + "生成失败" + "\"}";
}
else
{
string dirpath = Utils.getSystemPaht() + @"/wwwroot/SignFile";
if (!Directory.Exists(dirpath))
{
Directory.CreateDirectory(dirpath);
}
var tempFile = dirpath + $"/{ywid}.wav";
string filename = Path.GetFileName(ttsStr);
string source_file = dirpath + $"/{filename}";
string command = $"cp {ttsStr} -t {dirpath} && mv {source_file} {tempFile}";
ShllCommad(command);
result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + param.code + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + "生成成功" + "\"}";
}
return result;
}
catch (Exception ex)
{
//Log.Error("文字语音播报异常2: " + ex.Message + "");
string result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + "" + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
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() + "\",\"keycode\":\"" + code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"suffix\":\"jpg\",\"data\":\"" + "获取图片失败" + "\"}";
SubmitLogs(result, "openCamera");
return result;
}
else
{
param = Utils.ImagesByRotate(param, 90);
//关闭
//StopSn("0");
string result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + code + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"jpg\",\"data\":\"" + param + "\"}";
SubmitLogs(result, "openCamera");
return result;
}
}
else
{
//打开高拍仪
string param = OpenSn(Parame.gpydevIndex);
if (string.IsNullOrEmpty(param))
{
string result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + code + "\",\"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() + "\",\"keycode\":\"" + code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"suffix\":\"jpg\",\"data\":\"" + "获取图片失败" + "\"}";
SubmitLogs(result, "openCamera");
return result;
}
else
{
string base64 = Utils.ImagesByRotate(param, 90);
//关闭
//StopSn("0");
string result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + code + "\",\"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() + "\",\"keycode\":\"" + "" + "\",\"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)
{
try
{
var param = content.ConvertToAnonymousType(new
{
code = default(string),
timeout = default(int)
});
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, param.timeout); });
@event3.WaitOne();
string result = sginStr;
SubmitLogs(result, "OpenSign");
return result;
}
}
catch (Exception ex)
{
//Log.Error("打开签字版异常: " + ex.Message + "");
string result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + "" + "\",\"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, "", 5));
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)
{
try
{
var param = content.ConvertToAnonymousType(new
{
code = default(string),
isclose = default(bool),
timeout = default(int)
});
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, param.timeout); });
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, param.timeout); });
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,\"suffix\":\"jpg\",\"data\":\"" + fingerStr + "\"}";
}
SubmitLogs(result, "ReadFingerData");
return result;
}
}
}
catch (Exception ex)
{
//Log.Error("指纹异常: " + ex.Message + "");
string result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + "" + "\",\"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)
{
try
{
var param = content.ConvertToAnonymousType(new
{
code = default(string),
isopen = default(bool),
url = default(string)
});
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\":\"" + "" + "\",\"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)
{
try
{
var param = content.ConvertToAnonymousType(new
{
code = default(string),
url = default(string),
ext = default(string)
});
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\":\"" + "" + "\",\"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)
{
try
{
var param = content.ConvertToAnonymousType(new
{
code = default(string),
base64 = default(string),
ext = default(string)
});
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\":\"" + "" + "\",\"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)
{
try
{
var param = content.ConvertToAnonymousType(new
{
code = default(string),
url = default(string),
ispaye = default(bool)
});
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(() =>
{
Task.Run(() => { string command = $"pkill sox"; ShllCommad(command); });
});
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(() =>
{
Task.Run(() => { string command = $"pkill sox"; ShllCommad(command); });
});
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\":\"" + "" + "\",\"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() + "\",\"keycode\":\"" + code + "\",\"message\":\"seccse\",\"code\":\"200\",\"status\":true,\"data\":\"" + "唤醒键盘成功" + "\"}";
}
catch (Exception ex)
{
//Log.Error("唤醒键盘异常: " + ex.Message + "");
return "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
}
}
/// <summary>
/// aks100115 播放视频 (已国产化)
/// </summary>
/// <param name="paramsString"></param>
/// <returns></returns>
private static string playVideo(string content)
{
try
{
var param = content.ConvertToAnonymousType(new
{
code = default(string),
title = default(string),
url = default(string)
});
if (!isFuncisFuncObject("playVideo"))
{
return "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "视频播放设备未授权使用" + "\"}";
}
else
{
Parame.frm.Invoke(() =>
{
new AksVideoPlayer(Parame.frm, param.title, param.url);
});
string result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"jpg\",\"data\":\"" + "播放成功" + "\"}";
SubmitLogs(result, "playVideo");
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, "playVideo");
return result;
}
}
/// <summary>
/// aks100116 刻录文件 (已国产化)
/// </summary>
/// <param name="filename"></param>
/// <returns></returns>
public static string BurnFile(string content)
{
try
{
var param = content.ConvertToAnonymousType(new
{
code = default(string),
name = default(string),
obj = default(string),
ext = default(string)
});
if (param == null)
{
return "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + "" + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "参数解析错误" + "\"}";
}
if (!isFuncisFuncObject("PrintBase64"))
{
return "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "刻录机设备未授权使用" + "\"}";
}
else
{
DateTime dateTime = DateTime.Now;
string time = DateTime.Now.ToString(
"yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo);
string dirpath = Utils.getSystemPaht() + @"/wwwroot/tmpFile";
if (!Directory.Exists(dirpath))
{
Directory.CreateDirectory(dirpath);
}
var filepath = System.IO.Path.Combine(dirpath, time);
string path = dirpath + @"/" + time + "." + param.ext;
if (param.obj.Contains("http:"))
{
//url地址
WebRequest request = WebRequest.Create(param.obj);
WebResponse response = request.GetResponse();
using (Stream stream = response.GetResponseStream())
{
using (FileStream fileStream = new FileStream(path, FileMode.Create))
{
stream.CopyTo(fileStream);
}
}
response.Close();
}
else
{
//base64文件
byte[] bytes = Convert.FromBase64String(param.obj);
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);
//弹出光驱 eject /dev/cdrom
//刻录文件 wodim -v dev=/dev/cdrom blank=fast -data file1.txt file2.txt
//growisofs -Z /dev/cdrom -R -V "label" -iso-level 2 /path/to/files
//growisofs -Z /dev/cdrom -R -V "VOLUME_LABEL" -iso-level 2 /path/to/files
}
return "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + param.code + "\",\"message\":\"seccse\",\"code\":\"200\",\"status\":true,\"data\":\"" + "刻录成功" + "\"}";
}
catch (Exception ex)
{
//Log.Error("唤醒键盘异常: " + ex.Message + "");
return "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + "" + "\",\"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)
{
name = jo2["name"].ToString();
if (name.Contains(Parame.gpyVersion))
{
devidx = jo2["dev_idx"].ToString();
Parame.gpydevIndex = devidx;
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 EnableDeskImage(int idx)
{
//获取设备信息
string param = "/EnableDeskImage?enable=" + 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, int timeout)
{
try
{
var httpClient = new HttpClient();
var uploader = new ChunkedUpload(httpClient);
sginStr = await uploader.PostSign(type, typeCode, code, timeout);
@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, int timeout)
{
try
{
var httpClient = new HttpClient();
var uploader = new ChunkedUpload(httpClient);
fingerStr = await uploader.PostFinger(type, typeCode, timeout);
@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, int timeout)
{
try
{
var httpClient = new HttpClient();
var uploader = new ChunkedUpload(httpClient);
IdcardStr = await uploader.OpenGetIdcard(type, typeCode, timeout);
@event7.Set();
}
catch (Exception ex)
{
//Log.Error("签字版异常:" + ex.Message);
}
}
/// <summary>
/// 关闭硬件
/// </summary>
private static AutoResetEvent @event8 = new AutoResetEvent(false);
private static async void HttpResponseClose()
{
try
{
var httpClient = new HttpClient();
var uploader = new ChunkedUpload(httpClient);
await uploader.PublicSign("close", 2, 5);
await uploader.PublicFinger("close", 2, 5);
await uploader.PublicIdcard("close", 2, 5);
@event8.Set();
}
catch (Exception ex)
{
//Log.Error("高拍仪异常:" + ex.Message);
}
}
/// <summary>
/// 人证合一
/// </summary>
private static string smresults = string.Empty;
private static AutoResetEvent @event9 = new AutoResetEvent(false);
private static async void StartFace(string ImageBase64)
{
try
{
Parame.ImgBase64 = ImageBase64;
WebSocketClientWithHeartbeat webSocket = new WebSocketClientWithHeartbeat();
Task.Delay(800).Wait();
var mode = new
{
function = "CF_OpenCamera",
show = 1,
fx = 100,
fy = 800,
fw = 800,
fh = 600
};
//打开摄像头
webSocket.Send(JsonConvert.SerializeObject(mode), "CF_OpenCamera");
//开始活检
webSocket.Send("{\"function\":\"CF_StartLiveDetect\"}", "CF_StartLiveDetect");
}
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>
/// 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 "";
}
/// <summary>
/// 启动服务
/// </summary>
public static void StartShll()
{
try
{
if (true)
{
//启动身份证、签字版、指纹服务
string commod = "lsof -i:9399";
string zxjg = Bash(commod);
if (string.IsNullOrEmpty(zxjg))
{
commod = "cd /opt/apps/yfzy/bin && ./FiveInchServer-yfzy.sh";
Bash(commod);
}
}
if (true)
{
//启动高拍仪服务
string commod = "netstat -tuln | grep 6543";
string zxjg = Bash(commod);
if (string.IsNullOrEmpty(zxjg))
{
commod = "cd /opt/hCamera && ./start.sh";
Bash(commod);
//获取设备
GetSnIndex();
//打开高拍仪
if (OpenSn(Parame.gpydevIndex) == "200") { Parame.isGPY = true; }
//开启/关闭纠偏显示
EnableDeskImage(1);
}
}
}
catch { }
finally { }
}
}
}