|
|
|
|
using AksWebBrowser;
|
|
|
|
|
using AksWebBrowser.Common;
|
|
|
|
|
using AKSWebBrowser.Commen;
|
|
|
|
|
using AKSWebBrowser.Common;
|
|
|
|
|
using CPF.Cef;
|
|
|
|
|
using CPF.Mac.AppKit;
|
|
|
|
|
using DevicesService.Devices;
|
|
|
|
|
using NAudio.Wave;
|
|
|
|
|
using NAudio.Wave.SampleProviders;
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using SkiaSharp;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Buffers.Text;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Net.Http.Headers;
|
|
|
|
|
using System.Net.Sockets;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Web;
|
|
|
|
|
using System.Xml.Linq;
|
|
|
|
|
using static System.Net.Mime.MediaTypeNames;
|
|
|
|
|
using AksWebBrowser.Devices;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
|
|
|
|
|
namespace AKS.EnterpriseLibrary.WebBrowser
|
|
|
|
|
{
|
|
|
|
|
public class MainModel : CPF.CpfObject
|
|
|
|
|
{
|
|
|
|
|
public string callback = string.Empty;
|
|
|
|
|
public string PrinterName = "Lexmark-MS430-Series";
|
|
|
|
|
public static Process recordingProcess;
|
|
|
|
|
public static Process Typrocess;
|
|
|
|
|
private string srpath = string.Empty;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 读取身份证卡号(已国产化)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="paramsString"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[JSFunction]
|
|
|
|
|
public string IDCardRead(string paramsString)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//Finger("","");
|
|
|
|
|
IDCard iDCard = new IDCard();
|
|
|
|
|
string result = iDCard.getIdCard();
|
|
|
|
|
SubmitLogs(result, "IDCardRead");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Log.Error("读取身份证卡号异常: " + ex.Message + "");
|
|
|
|
|
string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
|
|
|
|
|
SubmitLogs(result, "IDCardRead");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 打印排队票据(已国产化)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ph">排号</param>
|
|
|
|
|
/// <param name="ddrs">等待人数</param>
|
|
|
|
|
/// <param name="qrcode">二维码</param>
|
|
|
|
|
/// <param name="ywmc">办理业务名称</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[JSFunction]
|
|
|
|
|
public string SendByPrint(string ph, string ddrs, string qrcode, string ywmc)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (!isFuncisFuncObject("SendByPrint"))
|
|
|
|
|
{
|
|
|
|
|
Utils.MessagesBox("打印排队票据设备未授权使用");
|
|
|
|
|
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "打印排队票据设备未授权使用" + "\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
PrintPJ print = new PrintPJ(Parame.pritPj, Parame.pritPjPort);
|
|
|
|
|
var data = print.SendPrint(ph, ddrs, qrcode, ywmc);
|
|
|
|
|
if (data == 0)
|
|
|
|
|
{
|
|
|
|
|
string result = "{\"message\":\"seccse\",\"code\":\"200\",\"status\":true,\"data\":\"" + "打印成功" + "\"}";
|
|
|
|
|
SubmitLogs(result, "SendByPrint");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + (data == 1 ? "打印失败" : (data == 2 ? "打印机未连接" : "打印机初始化失败")) + "\"}";
|
|
|
|
|
SubmitLogs(result, "SendByPrint");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Log.Error("打印排队票据异常: " + ex.Message + "");
|
|
|
|
|
string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
|
|
|
|
|
SubmitLogs(result, "SendByPrint");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 文字语音播报(已国产化)
|
|
|
|
|
/// apt install sox
|
|
|
|
|
/// apt install libsox-fmt-all
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="text"></param>
|
|
|
|
|
/// <param name="ispaye"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public WaveOutEvent playerTxt = null;
|
|
|
|
|
public static string tempWav = string.Empty;
|
|
|
|
|
[JSFunction]
|
|
|
|
|
public string payleText(string text, bool ispaye)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (!isFuncisFuncObject("payleText"))
|
|
|
|
|
{
|
|
|
|
|
Utils.MessagesBox("文字语音播报设备未授权使用");
|
|
|
|
|
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "文字语音播报设备未授权使用" + "\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (ispaye)
|
|
|
|
|
{
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
if (Typrocess != null)
|
|
|
|
|
{
|
|
|
|
|
// 如果进程还在运行
|
|
|
|
|
if (!Typrocess.HasExited)
|
|
|
|
|
{
|
|
|
|
|
// 发送SIGTERM信号来停止进程
|
|
|
|
|
Typrocess.Kill();
|
|
|
|
|
// 等待进程真正停止
|
|
|
|
|
Typrocess.WaitForExit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":" + "停止播放成功" + "}";
|
|
|
|
|
SubmitLogs(result, "payleText");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
//形成语音
|
|
|
|
|
tempWav = GenerateWavFromText(text);
|
|
|
|
|
//开始播放
|
|
|
|
|
string command = $"sox {tempWav} -d";
|
|
|
|
|
ShllCommad(command);
|
|
|
|
|
});
|
|
|
|
|
string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":" + "开始播放" + "}";
|
|
|
|
|
SubmitLogs(result, "payleText");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Log.Error("文字语音播报异常2: " + ex.Message + "");
|
|
|
|
|
string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
|
|
|
|
|
SubmitLogs(result, "payleText");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 打开高拍仪并且进行快速扫描文件 (已国产化)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="url"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[JSFunction]
|
|
|
|
|
public string openCamera(string url)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string devIndex = GetSnIndex();
|
|
|
|
|
if (string.IsNullOrEmpty(devIndex))
|
|
|
|
|
{
|
|
|
|
|
string result = "{\"callback\":\"" + callback + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"suffix\":\"jpg\",\"data\":\"" + "扫描仪打开失败" + "\"}";
|
|
|
|
|
SubmitLogs(result, "openCamera");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//打开高拍仪
|
|
|
|
|
string param = OpenSn(devIndex);
|
|
|
|
|
if (string.IsNullOrEmpty(param))
|
|
|
|
|
{
|
|
|
|
|
string result = "{\"callback\":\"" + callback + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"suffix\":\"jpg\",\"data\":\"" + "扫描仪打开失败" + "\"}";
|
|
|
|
|
SubmitLogs(result, "openCamera");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//拍照
|
|
|
|
|
param = getFrame();
|
|
|
|
|
if (string.IsNullOrEmpty(param))
|
|
|
|
|
{
|
|
|
|
|
string result = "{\"callback\":\"" + callback + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"suffix\":\"jpg\",\"data\":\"" + "获取图片失败" + "\"}";
|
|
|
|
|
SubmitLogs(result, "openCamera");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
//关闭
|
|
|
|
|
StopSn(devIndex);
|
|
|
|
|
});
|
|
|
|
|
string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"jpg\",\"data\":\"" + param + "\"}";
|
|
|
|
|
SubmitLogs(result, "openCamera");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Log.Error("打开高拍仪并且进行快速扫描文件异常: " + ex.Message + "");
|
|
|
|
|
string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
|
|
|
|
|
SubmitLogs(result, "openCamera");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 打开签字版 sudo apt-get install libgdiplus (已国产化)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="paramsString"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[JSFunction]
|
|
|
|
|
public string OpenSign(string paramsString, string callback)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (!isFuncisFuncObject("OpenSign"))
|
|
|
|
|
{
|
|
|
|
|
Utils.MessagesBox("签字版设备未授权使用");
|
|
|
|
|
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "签字版设备未授权使用" + "\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Task.Run(() => HttpPostResponseBySign("open", callback));
|
|
|
|
|
string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"jpg\",\"data\":\"" + "签字版已打开" + "\"}";
|
|
|
|
|
SubmitLogs(result, "openCamera");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Log.Error("打开签字版异常: " + ex.Message + "");
|
|
|
|
|
string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
|
|
|
|
|
SubmitLogs(result, "OpenSign");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 关闭签字版 (已国产化)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="paramsString"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[JSFunction]
|
|
|
|
|
public string CloseSign(string paramsString)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (!isFuncisFuncObject("OpenSign"))
|
|
|
|
|
{
|
|
|
|
|
Utils.MessagesBox("签字版设备未授权使用");
|
|
|
|
|
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "签字版设备未授权使用" + "\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"png\",\"data\":\"" + "成功" + "\"}";
|
|
|
|
|
SubmitLogs(result, "OpenSign");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Log.Error("关闭签字版异常: " + ex.Message + "");
|
|
|
|
|
string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
|
|
|
|
|
SubmitLogs(result, "OpenSign");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 指纹 (已国产化,未完成测试)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="paramsString"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[JSFunction]
|
|
|
|
|
public string ReadFingerData(string callback)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (false)//!isFuncisFuncObject("Finger")
|
|
|
|
|
{
|
|
|
|
|
Utils.MessagesBox("指纹设备未授权使用");
|
|
|
|
|
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "指纹设备未授权使用" + "\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
string result = Fingerprint.LIVESCANFinger(callback);
|
|
|
|
|
SubmitLogs(result, "Finger");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Log.Error("指纹异常: " + ex.Message + "");
|
|
|
|
|
string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
|
|
|
|
|
SubmitLogs(result, "Finger");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 开始录音、取消录音、结束录音 (已国产化)
|
|
|
|
|
/// sudo apt-get update
|
|
|
|
|
/// sudo apt-get install alsa-utils
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="isopen"></param>
|
|
|
|
|
/// <param name="url"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[JSFunction]
|
|
|
|
|
public string SoundRecording(bool isopen, string url)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (!isFuncisFuncObject("SoundRecording"))
|
|
|
|
|
{
|
|
|
|
|
Utils.MessagesBox("录音设备未授权使用");
|
|
|
|
|
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "录音设备未授权使用" + "\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//结束录音上传文件
|
|
|
|
|
if (!string.IsNullOrEmpty(url) && !isopen)
|
|
|
|
|
{
|
|
|
|
|
if (StopRecording())
|
|
|
|
|
{
|
|
|
|
|
Task.Run(async () =>
|
|
|
|
|
{
|
|
|
|
|
UploadInfo(url, srpath);
|
|
|
|
|
});
|
|
|
|
|
@event2.WaitOne();
|
|
|
|
|
Regex re = new Regex(@"(((?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(:[0-9]+)?|(?: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 = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"wav\",\"data\":\"" + reurl + "\"}";
|
|
|
|
|
SubmitLogs(result, "SoundRecording");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
string result = "{\"callback\":\"" + callback + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"suffix\":\"wav\",\"data\":\"" + "结束录音失败" + "\"}";
|
|
|
|
|
SubmitLogs(result, "SoundRecording");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (isopen)//开始录音
|
|
|
|
|
{
|
|
|
|
|
if (StartRecording())
|
|
|
|
|
{
|
|
|
|
|
string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"wav\",\"data\":\"" + "开始录音" + "\"}";
|
|
|
|
|
SubmitLogs(result, "SoundRecording");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
string result = "{\"callback\":\"" + callback + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"suffix\":\"wav\",\"data\":\"" + "录音失败" + "\"}";
|
|
|
|
|
SubmitLogs(result, "SoundRecording");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else //取消录音
|
|
|
|
|
{
|
|
|
|
|
if (StopRecording())
|
|
|
|
|
{
|
|
|
|
|
srpath = string.Empty;
|
|
|
|
|
string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"wav\",\"data\":\"" + "取消录音" + "\"}";
|
|
|
|
|
SubmitLogs(result, "SoundRecording");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
srpath = string.Empty;
|
|
|
|
|
string result = "{\"callback\":\"" + callback + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"suffix\":\"wav\",\"data\":\"" + "取消录音失败" + "\"}";
|
|
|
|
|
SubmitLogs(result, "SoundRecording");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Log.Error("开始录音、取消录音、结束录音异常: " + ex.Message + "");
|
|
|
|
|
string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
|
|
|
|
|
SubmitLogs(result, "SoundRecording");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据文件地址在线打印 (已国产化)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="filename"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[JSFunction]
|
|
|
|
|
public string PrintFile(string url, string ext)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (!isFuncisFuncObject("PrintFile"))
|
|
|
|
|
{
|
|
|
|
|
Utils.MessagesBox("打印机设备未授权使用");
|
|
|
|
|
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "打印机设备未授权使用" + "\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Task.Run(async () =>
|
|
|
|
|
{
|
|
|
|
|
DateTime dateTime = DateTime.Now;
|
|
|
|
|
string time = DateTime.Now.ToString(
|
|
|
|
|
"yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo);
|
|
|
|
|
var dirpath = System.IO.Path.Combine(Environment.CurrentDirectory, "wwwroot", "PrintFile");
|
|
|
|
|
if (!Directory.Exists(dirpath))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(dirpath);
|
|
|
|
|
}
|
|
|
|
|
var filepath = System.IO.Path.Combine(dirpath, time);
|
|
|
|
|
string path = dirpath + @"/" + time + "." + ext;
|
|
|
|
|
WebRequest request = WebRequest.Create(url);
|
|
|
|
|
WebResponse response = request.GetResponse();
|
|
|
|
|
using (Stream stream = response.GetResponseStream())
|
|
|
|
|
{
|
|
|
|
|
using (FileStream fileStream = new FileStream(path, FileMode.Create))
|
|
|
|
|
{
|
|
|
|
|
stream.CopyTo(fileStream);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
response.Close();
|
|
|
|
|
//Log.Info("根据文件base64打印: " + path + "");
|
|
|
|
|
string command = $"lp -d {PrinterName} {path}";
|
|
|
|
|
ShllCommad(command);
|
|
|
|
|
});
|
|
|
|
|
string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + "打印成功" + "\"}";
|
|
|
|
|
SubmitLogs(result, "PrintFile");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Log.Error("根据文件地址在线打印异常: " + ex.Message + "");
|
|
|
|
|
string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
|
|
|
|
|
SubmitLogs(result, "PrintFile");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据文件base64打印 (已国产化)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="base64"></param>
|
|
|
|
|
/// <param name="ext"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[JSFunction]
|
|
|
|
|
public string PrintBase64(string url, string base64, string ext)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (!isFuncisFuncObject("PrintBase64"))
|
|
|
|
|
{
|
|
|
|
|
Utils.MessagesBox("打印机设备未授权使用");
|
|
|
|
|
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "打印机设备未授权使用" + "\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Task.Run(async () =>
|
|
|
|
|
{
|
|
|
|
|
DateTime dateTime = DateTime.Now;
|
|
|
|
|
string time = DateTime.Now.ToString(
|
|
|
|
|
"yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo);
|
|
|
|
|
var dirpath = System.IO.Path.Combine(Environment.CurrentDirectory, "wwwroot", "PrintFile");
|
|
|
|
|
if (!Directory.Exists(dirpath))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(dirpath);
|
|
|
|
|
}
|
|
|
|
|
var filepath = System.IO.Path.Combine(dirpath, time);
|
|
|
|
|
string path = dirpath + @"/" + time + "." + ext;
|
|
|
|
|
byte[] bytes = Convert.FromBase64String(base64);
|
|
|
|
|
System.IO.FileStream stream = new System.IO.FileStream(path, System.IO.FileMode.CreateNew);
|
|
|
|
|
System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream);
|
|
|
|
|
writer.Write(bytes, 0, bytes.Length);
|
|
|
|
|
writer.Close();
|
|
|
|
|
//Log.Info("根据文件base64打印: " + path + "");
|
|
|
|
|
string command = $"lp -d {PrinterName} {path}";
|
|
|
|
|
ShllCommad(command);
|
|
|
|
|
});
|
|
|
|
|
string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + "打印成功" + "\"}";
|
|
|
|
|
SubmitLogs(result, "PrintBase64");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
|
|
|
|
|
SubmitLogs(result, "PrintBase64");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 播放音频文件 (已国产化)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="filename"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static WaveOutEvent player = null;
|
|
|
|
|
public static AudioFileReader audioFileReader = null;
|
|
|
|
|
public static string WaveOutPath = string.Empty;
|
|
|
|
|
[JSFunction]
|
|
|
|
|
public string PalyFile(string url, bool ispaly)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (!isFuncisFuncObject("PalyFile"))
|
|
|
|
|
{
|
|
|
|
|
Utils.MessagesBox("音频设备未授权使用");
|
|
|
|
|
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "音频设备未授权使用" + "\"}";
|
|
|
|
|
}
|
|
|
|
|
else if (Parame.tcpClient == null)
|
|
|
|
|
{
|
|
|
|
|
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "硬件服务未启动" + "\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (ispaly)
|
|
|
|
|
{
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
Uri uri = new Uri(url);
|
|
|
|
|
//返回 123.xlsx
|
|
|
|
|
var filename = HttpUtility.UrlDecode(uri.Segments.Last());
|
|
|
|
|
//获取文件后缀
|
|
|
|
|
string ext = System.IO.Path.GetExtension(filename);
|
|
|
|
|
DateTime dateTime = DateTime.Now;
|
|
|
|
|
string time = DateTime.Now.ToString(
|
|
|
|
|
"yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo);
|
|
|
|
|
var dirpath = System.IO.Path.Combine(Environment.CurrentDirectory, "wwwroot", "WaveOutFile");
|
|
|
|
|
if (!Directory.Exists(dirpath))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(dirpath);
|
|
|
|
|
}
|
|
|
|
|
string path = dirpath + @"/" + time + "." + ext;
|
|
|
|
|
WebRequest request = WebRequest.Create(url);
|
|
|
|
|
WebResponse response = request.GetResponse();
|
|
|
|
|
using (Stream stream = response.GetResponseStream())
|
|
|
|
|
{
|
|
|
|
|
using (FileStream fileStream = new FileStream(path, FileMode.Create))
|
|
|
|
|
{
|
|
|
|
|
stream.CopyTo(fileStream);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
response.Close();
|
|
|
|
|
|
|
|
|
|
//开始播放
|
|
|
|
|
string command = $"sox {path} -d";
|
|
|
|
|
ShllCommad(command);
|
|
|
|
|
});
|
|
|
|
|
string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":" + "开始播放" + "}";
|
|
|
|
|
SubmitLogs(result, "PalyFile");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
if (Typrocess != null)
|
|
|
|
|
{
|
|
|
|
|
// 如果进程还在运行
|
|
|
|
|
if (!Typrocess.HasExited)
|
|
|
|
|
{
|
|
|
|
|
// 发送SIGTERM信号来停止进程
|
|
|
|
|
Typrocess.Kill();
|
|
|
|
|
// 等待进程真正停止
|
|
|
|
|
Typrocess.WaitForExit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":" + "停止播放成功" + "}";
|
|
|
|
|
SubmitLogs(result, "PalyFile");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
|
|
|
|
|
SubmitLogs(result, "PalyFile");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 播放完成
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void waveOut_PlaybackStopped(object sender, StoppedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
player.Stop();
|
|
|
|
|
// 释放资源
|
|
|
|
|
player.Dispose();
|
|
|
|
|
audioFileReader.Dispose();
|
|
|
|
|
player = null;
|
|
|
|
|
File.Delete(WaveOutPath);
|
|
|
|
|
//Log.Info("播放完成");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
//Log.Info("播放完成,清除本地文件异常" + ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 唤醒键盘 (已国产化)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="filename"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[JSFunction]
|
|
|
|
|
public string openKey(string paramsString)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
Bash("/usr/bin/python3 /usr/bin/onboard");
|
|
|
|
|
});
|
|
|
|
|
return "{\"message\":\"seccse\",\"code\":\"200\",\"status\":true,\"data\":\"" + "唤醒键盘成功" + "\"}";
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Log.Error("唤醒键盘异常: " + ex.Message + "");
|
|
|
|
|
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 执行文件
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="command"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static string Bash(string command)
|
|
|
|
|
{
|
|
|
|
|
var escapedArgs = command.Replace("\"", "\\\"");
|
|
|
|
|
var process = new Process()
|
|
|
|
|
{
|
|
|
|
|
StartInfo = new ProcessStartInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = "/bin/bash",
|
|
|
|
|
Arguments = $"-c \"{escapedArgs}\"",
|
|
|
|
|
RedirectStandardOutput = true,
|
|
|
|
|
UseShellExecute = false,
|
|
|
|
|
CreateNoWindow = true,
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
process.Start();
|
|
|
|
|
string result = process.StandardOutput.ReadToEnd();
|
|
|
|
|
process.WaitForExit();
|
|
|
|
|
process.Dispose();
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取设备index
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public string GetSnIndex()
|
|
|
|
|
{
|
|
|
|
|
//获取设备信息
|
|
|
|
|
string param = "/GetAllDisplayInfo";
|
|
|
|
|
Task.Run(() => HttpResponse(param));
|
|
|
|
|
@event6.WaitOne();
|
|
|
|
|
if (string.IsNullOrEmpty(gpyStr))
|
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
JObject jo = (JObject)JsonConvert.DeserializeObject(gpyStr);
|
|
|
|
|
if (jo["returnCode"].ToString() == "0")
|
|
|
|
|
{
|
|
|
|
|
string result = jo["data"].ToString();
|
|
|
|
|
Log.Info(result);
|
|
|
|
|
JArray jo1 = (JArray)JsonConvert.DeserializeObject(result);
|
|
|
|
|
string devidx = string.Empty;
|
|
|
|
|
string name = string.Empty;
|
|
|
|
|
foreach (JObject jo2 in jo1)
|
|
|
|
|
{
|
|
|
|
|
devidx = jo2["dev_idx"].ToString();
|
|
|
|
|
name = jo2["name"].ToString();
|
|
|
|
|
Log.Info(name);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return devidx;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Log.Info(jo["returnMsg"].ToString());
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 打开高拍仪
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public string OpenSn(string dev_idx)
|
|
|
|
|
{
|
|
|
|
|
//获取设备信息
|
|
|
|
|
string param = "/StartPreview?dev_idx=" + dev_idx + "&res_id=0";
|
|
|
|
|
Task.Run(() => HttpResponse(param));
|
|
|
|
|
@event6.WaitOne();
|
|
|
|
|
if (string.IsNullOrEmpty(gpyStr))
|
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
JObject jo = (JObject)JsonConvert.DeserializeObject(gpyStr);
|
|
|
|
|
if (jo["returnCode"].ToString() == "0")
|
|
|
|
|
{
|
|
|
|
|
return "200";
|
|
|
|
|
}
|
|
|
|
|
if (jo["returnCode"].ToString() == "2")
|
|
|
|
|
{
|
|
|
|
|
return "200";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Log.Info(jo["returnMsg"].ToString());
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 关闭高拍仪
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public string StopSn(string dev_idx)
|
|
|
|
|
{
|
|
|
|
|
//获取设备信息
|
|
|
|
|
string param = "/StopPreview?dev_idx=" + dev_idx;
|
|
|
|
|
Task.Run(() => HttpResponse(param));
|
|
|
|
|
@event6.WaitOne();
|
|
|
|
|
if (string.IsNullOrEmpty(gpyStr))
|
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
JObject jo = (JObject)JsonConvert.DeserializeObject(gpyStr);
|
|
|
|
|
if (jo["returnCode"].ToString() == "0")
|
|
|
|
|
{
|
|
|
|
|
return "200";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Log.Info(jo["returnMsg"].ToString());
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 拍照
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public string getFrame()
|
|
|
|
|
{
|
|
|
|
|
//获取设备信息
|
|
|
|
|
string param = "/getFrame";
|
|
|
|
|
Task.Run(() => HttpResponse(param));
|
|
|
|
|
@event6.WaitOne();
|
|
|
|
|
if (string.IsNullOrEmpty(gpyStr))
|
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
JObject jo = (JObject)JsonConvert.DeserializeObject(gpyStr);
|
|
|
|
|
if (jo["returnCode"].ToString() == "0")
|
|
|
|
|
{
|
|
|
|
|
string result = jo["data"].ToString();
|
|
|
|
|
JObject jo1 = (JObject)JsonConvert.DeserializeObject(result);
|
|
|
|
|
return jo1["img"].ToString();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Log.Info(jo["returnMsg"].ToString());
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 右转
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public string RotateRight()
|
|
|
|
|
{
|
|
|
|
|
//获取设备信息
|
|
|
|
|
string param = "/rotate/right";
|
|
|
|
|
Task.Run(() => HttpResponse(param));
|
|
|
|
|
@event6.WaitOne();
|
|
|
|
|
if (string.IsNullOrEmpty(gpyStr))
|
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
JObject jo = (JObject)JsonConvert.DeserializeObject(gpyStr);
|
|
|
|
|
if (jo["returnCode"].ToString() == "0")
|
|
|
|
|
{
|
|
|
|
|
return "200";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Log.Info(jo["returnMsg"].ToString());
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 左转
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public string RotateLeft()
|
|
|
|
|
{
|
|
|
|
|
//获取设备信息
|
|
|
|
|
string param = "/rotate/left";
|
|
|
|
|
Task.Run(() => HttpResponse(param));
|
|
|
|
|
@event6.WaitOne();
|
|
|
|
|
if (string.IsNullOrEmpty(gpyStr))
|
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
JObject jo = (JObject)JsonConvert.DeserializeObject(gpyStr);
|
|
|
|
|
if (jo["returnCode"].ToString() == "0")
|
|
|
|
|
{
|
|
|
|
|
return "200";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Log.Info(jo["returnMsg"].ToString());
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 高拍仪
|
|
|
|
|
/// </summary>
|
|
|
|
|
private string gpyStr = string.Empty;
|
|
|
|
|
private AutoResetEvent @event6 = new AutoResetEvent(false);
|
|
|
|
|
private async void HttpResponse(string param)
|
|
|
|
|
{
|
|
|
|
|
var httpClient = new HttpClient();
|
|
|
|
|
var uploader = new ChunkedUpload(httpClient);
|
|
|
|
|
gpyStr = await uploader.getReq(param);
|
|
|
|
|
@event6.Set();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 签字版
|
|
|
|
|
/// </summary>
|
|
|
|
|
private async void HttpPostResponseBySign(string type,string callback)
|
|
|
|
|
{
|
|
|
|
|
var httpClient = new HttpClient();
|
|
|
|
|
var uploader = new ChunkedUpload(httpClient);
|
|
|
|
|
await uploader.PostSign(type, callback);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 初始文件上传
|
|
|
|
|
/// </summary>
|
|
|
|
|
private string urlpath = string.Empty;
|
|
|
|
|
private AutoResetEvent @event2 = new AutoResetEvent(false);
|
|
|
|
|
private async void UploadInfo(string url, string srpath)
|
|
|
|
|
{
|
|
|
|
|
var httpClient = new HttpClient();
|
|
|
|
|
var uploader = new ChunkedUpload(httpClient);
|
|
|
|
|
urlpath = await uploader.UploadFileAsync(url, srpath);
|
|
|
|
|
@event2.Set();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//上传本地文件中转
|
|
|
|
|
private string urlP = string.Empty;
|
|
|
|
|
private AutoResetEvent @event5 = new AutoResetEvent(false);
|
|
|
|
|
private async void UploadInfoByFile(string url, string strpath)
|
|
|
|
|
{
|
|
|
|
|
var httpClient = new HttpClient();
|
|
|
|
|
var uploader = new ChunkedUpload(httpClient);
|
|
|
|
|
urlP = await uploader.UploadFileAsync(url, strpath);
|
|
|
|
|
File.Delete(strpath);
|
|
|
|
|
@event5.Set();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// string 转换为 base64
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static string str2Base64(string str)
|
|
|
|
|
{
|
|
|
|
|
byte[] b = System.Text.Encoding.UTF8.GetBytes(str);
|
|
|
|
|
string result = Convert.ToBase64String(b);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// base64 转换为 string
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="data"></param>
|
|
|
|
|
public static string Base64str2(string data)
|
|
|
|
|
{
|
|
|
|
|
byte[] c = Convert.FromBase64String(data);
|
|
|
|
|
string result = System.Text.Encoding.UTF8.GetString(c);
|
|
|
|
|
//Log.Info("接收返回数据:" + result);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//根据程序名称杀死进程
|
|
|
|
|
public static void KillProcessByName(string processName)
|
|
|
|
|
{
|
|
|
|
|
Process[] processes = Process.GetProcessesByName(processName);
|
|
|
|
|
|
|
|
|
|
foreach (Process process in processes)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
process.Kill();
|
|
|
|
|
process.WaitForExit(); // 等待进程退出
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex) { }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 开始录音
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public bool StartRecording()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (recordingProcess != null)
|
|
|
|
|
{
|
|
|
|
|
// 如果进程还在运行
|
|
|
|
|
if (!recordingProcess.HasExited)
|
|
|
|
|
{
|
|
|
|
|
// 发送SIGTERM信号来停止arecord进程
|
|
|
|
|
recordingProcess.Kill();
|
|
|
|
|
recordingProcess.WaitForExit(); // 等待进程真正停止
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
string time = DateTime.Now.ToString(
|
|
|
|
|
"yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo);
|
|
|
|
|
var dirpath = System.IO.Path.Combine(Environment.CurrentDirectory, "wwwroot", "Record");
|
|
|
|
|
if (!Directory.Exists(dirpath))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(dirpath);
|
|
|
|
|
}
|
|
|
|
|
srpath = dirpath + "/" + time + ".wav";
|
|
|
|
|
string outputFile = srpath; // 输出文件名
|
|
|
|
|
string device = "default"; // 音频设备,可以通过arecord -l来列出所有设备
|
|
|
|
|
// 构建arecord命令
|
|
|
|
|
string command = $"arecord --device={device} --file-type=wav --duration=10 --quiet {outputFile}";
|
|
|
|
|
// 启动进程
|
|
|
|
|
recordingProcess = new Process
|
|
|
|
|
{
|
|
|
|
|
StartInfo = new ProcessStartInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = "/bin/bash",
|
|
|
|
|
Arguments = $"-c \"{command}\"",
|
|
|
|
|
UseShellExecute = false,
|
|
|
|
|
RedirectStandardOutput = true,
|
|
|
|
|
RedirectStandardError = true
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
recordingProcess.Start();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Log.Error("开始录音异常:" + ex.Message);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 结束录音
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool StopRecording()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// 如果进程还在运行
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
//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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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);
|
|
|
|
|
var dirpath = System.IO.Path.Combine(Environment.CurrentDirectory, "wwwroot", "WavFile");
|
|
|
|
|
if (!Directory.Exists(dirpath))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(dirpath);
|
|
|
|
|
}
|
|
|
|
|
var tempFile = dirpath + "/" + time + ".wav";
|
|
|
|
|
text = text.Replace("(", "").Replace(")", "、");
|
|
|
|
|
ProcessStartInfo startInfo = new ProcessStartInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = "espeak",
|
|
|
|
|
Arguments = $" -vzh -s 150 \"{text}\" -w {tempFile}", // 设置语速为150,输出为WAV文件
|
|
|
|
|
UseShellExecute = false,
|
|
|
|
|
RedirectStandardOutput = true,
|
|
|
|
|
CreateNoWindow = true
|
|
|
|
|
};
|
|
|
|
|
using (Process process = Process.Start(startInfo))
|
|
|
|
|
{
|
|
|
|
|
process.WaitForExit(); // 等待进程结束
|
|
|
|
|
process.Close();
|
|
|
|
|
process.Dispose();
|
|
|
|
|
}
|
|
|
|
|
return tempFile;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 是否已获取收取
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="funcName"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public bool isFuncisFuncObject(string funcName)
|
|
|
|
|
{
|
|
|
|
|
bool isFunc = false;
|
|
|
|
|
if (Parame.FuncObject.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
foreach (Func func in Parame.FuncObject)
|
|
|
|
|
{
|
|
|
|
|
if (func.Interfaceaddress.Contains(funcName))
|
|
|
|
|
{
|
|
|
|
|
isFunc = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return isFunc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//提交设备操作日志
|
|
|
|
|
public static void SubmitLogs(string Describer, string funcName)
|
|
|
|
|
{
|
|
|
|
|
Task.Run(async () =>
|
|
|
|
|
{
|
|
|
|
|
string ApiId = string.Empty;
|
|
|
|
|
string Name = string.Empty;
|
|
|
|
|
string Interfaceaddress = string.Empty;
|
|
|
|
|
bool isFunc = false;
|
|
|
|
|
if (Parame.FuncObject != null)
|
|
|
|
|
{
|
|
|
|
|
if (Parame.FuncObject.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
foreach (Func func in Parame.FuncObject)
|
|
|
|
|
{
|
|
|
|
|
if (func.Interfaceaddress.Contains(funcName))
|
|
|
|
|
{
|
|
|
|
|
isFunc = true;
|
|
|
|
|
ApiId = func.Id;
|
|
|
|
|
Name = func.Platform;
|
|
|
|
|
Interfaceaddress = func.Interfaceaddress;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (isFunc)
|
|
|
|
|
{
|
|
|
|
|
var client = new HttpClient();
|
|
|
|
|
var request = new HttpRequestMessage(HttpMethod.Post, $"{Parame.apiUrl}/api/Interface/JournalAdd");
|
|
|
|
|
var content = new StringContent("{\"Name\": \"" + Name + "\",\"Describer\": \"" + str2Base64(Describer) + "\", \"Interfaceaddress\": \"" + Interfaceaddress + "\", \"ApiId\": \"" + ApiId + "\"}", null, "application/json");
|
|
|
|
|
request.Content = content;
|
|
|
|
|
var response = await client.SendAsync(request);
|
|
|
|
|
if (response.StatusCode.ToString() == "200")
|
|
|
|
|
{
|
|
|
|
|
response.EnsureSuccessStatusCode();
|
|
|
|
|
var body = await response.Content.ReadAsStringAsync();
|
|
|
|
|
//Log.Info(body);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|