Browse Source

优化完成 超时设置,语音文字播报预设、高拍仪不同电脑序号自动获取

master
胡超1 1 year ago
parent
commit
020116f0ac
  1. 31
      CPF_Cef/Common/ChunkedUpload.cs
  2. 68
      CPF_Cef/Common/Utils.cs
  3. 52
      CPF_Cef/FrmMain.cs
  4. 90
      CPF_Cef/MainModel.cs
  5. 7
      CPF_Cef/Parame.cs

31
CPF_Cef/Common/ChunkedUpload.cs

@ -148,6 +148,7 @@ namespace AksWebBrowser.Common
{ {
try try
{ {
timeout = timeout == 0 ? Parame.timeout : timeout;
var client = new HttpClient(); var client = new HttpClient();
client.Timeout = TimeSpan.FromSeconds(timeout); client.Timeout = TimeSpan.FromSeconds(timeout);
var request = new HttpRequestMessage(HttpMethod.Post, Parame.signUrl); var request = new HttpRequestMessage(HttpMethod.Post, Parame.signUrl);
@ -271,6 +272,7 @@ namespace AksWebBrowser.Common
{ {
try try
{ {
timeout = timeout == 0 ? Parame.timeout : timeout;
var client = new HttpClient(); var client = new HttpClient();
client.Timeout = TimeSpan.FromSeconds(timeout); client.Timeout = TimeSpan.FromSeconds(timeout);
var request = new HttpRequestMessage(HttpMethod.Post, Parame.signUrl); var request = new HttpRequestMessage(HttpMethod.Post, Parame.signUrl);
@ -339,6 +341,7 @@ namespace AksWebBrowser.Common
{ {
try try
{ {
timeout = timeout == 0 ? Parame.timeout : timeout;
var client = new HttpClient(); var client = new HttpClient();
client.Timeout = TimeSpan.FromSeconds(timeout); client.Timeout = TimeSpan.FromSeconds(timeout);
var request = new HttpRequestMessage(HttpMethod.Post, Parame.signUrl); var request = new HttpRequestMessage(HttpMethod.Post, Parame.signUrl);
@ -367,33 +370,7 @@ namespace AksWebBrowser.Common
string base64 = jo4["face_data"].ToString(); string base64 = jo4["face_data"].ToString();
if (Parame.isTMZ) if (Parame.isTMZ)
{ {
//生成文件 var faceA =Utils.Base64ByImages(base64);
string dirpath = Utils.getSystemPaht() + @"/wwwroot/FileTxt";
if (!Directory.Exists(dirpath))
{
Directory.CreateDirectory(dirpath);
}
var tempFile = dirpath + "/faceA.txt";
using (StreamWriter sw = new StreamWriter(tempFile))
{
sw.Write(base64);
sw.Close();
sw.Dispose();
}
//生成图片
string dirpath1 = Utils.getSystemPaht() + @"/wwwroot/Face";
if (!Directory.Exists(dirpath1))
{
Directory.CreateDirectory(dirpath1);
}
var faceA = dirpath1 + "/faceA.jpg";
string command = $"base64 -d {tempFile} > {faceA}";
MainModel.ShllCommad(command);
//删除图片
Task.Run(() =>
{
File.Delete(tempFile);
});
//开启人脸比对 //开启人脸比对
LhtCF lht = new LhtCF(); LhtCF lht = new LhtCF();
string stat = lht.LhtCFFace("", faceA); string stat = lht.LhtCFFace("", faceA);

68
CPF_Cef/Common/Utils.cs

@ -1,9 +1,11 @@
using AKSWebBrowser.Commen; using AKS.EnterpriseLibrary.WebBrowser;
using AKSWebBrowser.Commen;
using CPF.Controls; using CPF.Controls;
using System; using System;
using System.Drawing; using System.Drawing;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
using System.Threading.Tasks;
namespace AksWebBrowser.Common namespace AksWebBrowser.Common
{ {
@ -52,7 +54,10 @@ namespace AksWebBrowser.Common
// 删除所有文件 // 删除所有文件
foreach (string file in files) foreach (string file in files)
{ {
File.Delete(file); if (!file.Contains("SignFile"))
{
File.Delete(file);
}
} }
} }
@ -94,5 +99,64 @@ namespace AksWebBrowser.Common
long timestamp = (long)timeSpan.TotalSeconds; long timestamp = (long)timeSpan.TotalSeconds;
return timestamp.ToString(); return timestamp.ToString();
} }
//图片旋转
public static string ImagesByRotate(string base64, int rotate)
{
string time = DateTime.Now.ToString("yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo);
//生成图片
string dirpath1 = Utils.getSystemPaht() + @"/wwwroot/TmpFile";
if (!Directory.Exists(dirpath1))
{
Directory.CreateDirectory(dirpath1);
}
var outImgpath = dirpath1 + $"/{time}.jpg";
var Imgpath = Base64ByImages(base64);
string command = $"convert {Imgpath} -rotate {rotate} {outImgpath}";
MainModel.ShllCommad(command);
byte[] bytes = File.ReadAllBytes(outImgpath);
string _base64 = Convert.ToBase64String(bytes);
//删除图片
Task.Run(() =>
{
File.Delete(Imgpath);
File.Delete(outImgpath);
});
return _base64;
}
//base64转图片
public static string Base64ByImages(string base64)
{
string time = DateTime.Now.ToString("yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo);
//生成文件
string dirpath = Utils.getSystemPaht() + @"/wwwroot/TmpFile";
if (!Directory.Exists(dirpath))
{
Directory.CreateDirectory(dirpath);
}
var tempFile = dirpath + $"/{time}.txt";
using (StreamWriter sw = new StreamWriter(tempFile))
{
sw.Write(base64);
sw.Close();
sw.Dispose();
}
//生成图片
string dirpath1 = Utils.getSystemPaht() + @"/wwwroot/TmpFile";
if (!Directory.Exists(dirpath1))
{
Directory.CreateDirectory(dirpath1);
}
var Imgpath = dirpath1 + $"/{time}.jpg";
string command = $"base64 -d {tempFile} > {Imgpath}";
MainModel.ShllCommad(command);
//删除图片
Task.Run(() =>
{
File.Delete(tempFile);
});
return Imgpath;
}
} }
} }

52
CPF_Cef/FrmMain.cs

@ -21,7 +21,6 @@ namespace AKS.EnterpriseLibrary.WebBrowser
public int w = 1080; public int w = 1080;
public int h = 1920; public int h = 1920;
protected override void InitializeComponent() protected override void InitializeComponent()
{ {
//注册gb2312 //注册gb2312
@ -118,60 +117,12 @@ namespace AKS.EnterpriseLibrary.WebBrowser
//获取设备 //获取设备
MainModel.GetSnIndex(); MainModel.GetSnIndex();
//打开高拍仪 //打开高拍仪
if (MainModel.OpenSn("0") == "200") if (MainModel.OpenSn(Parame.gpydevIndex) == "200")
{ {
Parame.isGPY = true; Parame.isGPY = true;
} }
////删除临时文件
//Task.Run(() => { DeleteFile(); });
////开启定时清理任务
//Task.Run(() => { Time(); });
}
//凌晨2点执行,清理当天缓存文件
public void Time()
{
try
{
// 获取当前时间
DateTime now = DateTime.Now;
// 计算明天凌晨的时间// 假设凌晨2点执行
DateTime tomorrowMorning = new DateTime(now.Year, now.Month, now.Day) + TimeSpan.FromDays(1) + TimeSpan.FromHours(2);
// 计算时间差(明天凌晨时间减去现在时间)
TimeSpan timeToGo = tomorrowMorning - now;
// 设置定时器
Timer timer = new Timer(ExecuteTask, null, timeToGo, Timeout.InfiniteTimeSpan);
}
catch (Exception ex)
{
//Log.Error("定时任务开启异常: " + ex.Message);
}
}
// 要执行的任务
private static void ExecuteTask(object state)
{
DeleteFile();
}
//删除临时文件
public static void DeleteFile()
{
try
{
// // Log.Info("定时任务执行时间: " + DateTime.Now);
string file = System.IO.Directory.GetCurrentDirectory();
file = file + @"/wwwroot";
// 这里添加你的任务代码
Utils.DeleteAllFiles(file);
}
catch (Exception ex)
{
//Log.Error("定时任务执行异常: " + ex.Message);
}
} }
public void Writelog(string str, string dirName = @"logs") public void Writelog(string str, string dirName = @"logs")
{ {
try try
@ -192,6 +143,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser
} }
catch { } catch { }
} }
private void CusRequest_CusResquestEvent(CefPostData postData, CefRequest request) private void CusRequest_CusResquestEvent(CefPostData postData, CefRequest request)
{ {
string postParams = string.Empty; string postParams = string.Empty;

90
CPF_Cef/MainModel.cs

@ -268,7 +268,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser
catch (Exception ex) catch (Exception ex)
{ {
//Log.Error("读取身份证卡号异常: " + ex.Message + ""); //Log.Error("读取身份证卡号异常: " + ex.Message + "");
string result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" +""+ "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; string result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + "" + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
SubmitLogs(result, "IDCardRead"); SubmitLogs(result, "IDCardRead");
return result; return result;
} }
@ -329,7 +329,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser
catch (Exception ex) catch (Exception ex)
{ {
//Log.Error("打印排队票据异常: " + ex.Message + ""); //Log.Error("打印排队票据异常: " + ex.Message + "");
string result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" +"" + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; string result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + "" + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
SubmitLogs(result, "SendByPrint"); SubmitLogs(result, "SendByPrint");
return result; return result;
} }
@ -369,25 +369,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser
{ {
Task.Run(() => Task.Run(() =>
{ {
try Task.Run(() => { string command = $"pkill sox"; ShllCommad(command); });
{
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\":\"" + "停止播放成功" + "\"}"; string result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + param.code + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + "停止播放成功" + "\"}";
SubmitLogs(result, "payleText"); SubmitLogs(result, "payleText");
@ -414,12 +396,15 @@ namespace AKS.EnterpriseLibrary.WebBrowser
else else
{ {
Task.Run(() => { string command = $"sox {ttsStr} -d"; ShllCommad(command); }); Task.Run(() => { string command = $"sox {ttsStr} -d"; ShllCommad(command); });
string filename = Path.GetFileName(ttsStr); if (!string.IsNullOrEmpty(ywid))
Log.Info(filename); {
string source_file = dirpath + $"/{filename}"; string filename = Path.GetFileName(ttsStr);
Log.Info(source_file); Log.Info(filename);
string command = $"cp {ttsStr} -t {dirpath} && mv {source_file} {tempFile}"; string source_file = dirpath + $"/{filename}";
ShllCommad(command); 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\":\"" + "开始播放" + "\"}"; result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + param.code + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + "开始播放" + "\"}";
} }
} }
@ -437,7 +422,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser
catch (Exception ex) catch (Exception ex)
{ {
//Log.Error("文字语音播报异常2: " + ex.Message + ""); //Log.Error("文字语音播报异常2: " + ex.Message + "");
string result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" +"" + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; string result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + "" + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
SubmitLogs(result, "payleText"); SubmitLogs(result, "payleText");
return result; return result;
} }
@ -492,7 +477,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser
catch (Exception ex) catch (Exception ex)
{ {
//Log.Error("文字语音播报异常2: " + ex.Message + ""); //Log.Error("文字语音播报异常2: " + ex.Message + "");
string result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + ""+ "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; string result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + "" + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
return result; return result;
} }
} }
@ -521,6 +506,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser
} }
else else
{ {
param = Utils.ImagesByRotate(param, 90);
//关闭 //关闭
//StopSn("0"); //StopSn("0");
string result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + code + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"jpg\",\"data\":\"" + param + "\"}"; string result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + code + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"jpg\",\"data\":\"" + param + "\"}";
@ -531,7 +517,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser
else else
{ {
//打开高拍仪 //打开高拍仪
string param = OpenSn("0"); string param = OpenSn(Parame.gpydevIndex);
if (string.IsNullOrEmpty(param)) if (string.IsNullOrEmpty(param))
{ {
string result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"suffix\":\"jpg\",\"data\":\"" + "扫描仪打开失败" + "\"}"; string result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"suffix\":\"jpg\",\"data\":\"" + "扫描仪打开失败" + "\"}";
@ -554,6 +540,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser
} }
else else
{ {
string base64 = Utils.ImagesByRotate(param, 90);
//关闭 //关闭
//StopSn("0"); //StopSn("0");
string result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + code + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"jpg\",\"data\":\"" + param + "\"}"; string result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + code + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"jpg\",\"data\":\"" + param + "\"}";
@ -615,7 +602,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser
catch (Exception ex) catch (Exception ex)
{ {
//Log.Error("打开签字版异常: " + ex.Message + ""); //Log.Error("打开签字版异常: " + ex.Message + "");
string result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + ""+ "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}"; string result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + "" + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
SubmitLogs(result, "OpenSign"); SubmitLogs(result, "OpenSign");
return result; return result;
} }
@ -637,7 +624,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser
} }
else else
{ {
Task.Run(() => HttpPostResponseBySign("close", 2, "",5)); Task.Run(() => HttpPostResponseBySign("close", 2, "", 5));
string result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"jpg\",\"data\":\"" + "签字版已关闭" + "\"}"; string result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"jpg\",\"data\":\"" + "签字版已关闭" + "\"}";
SubmitLogs(result, "openCamera"); SubmitLogs(result, "openCamera");
return result; return result;
@ -991,18 +978,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser
{ {
Task.Run(() => Task.Run(() =>
{ {
if (Typrocess != null) Task.Run(() => { string command = $"pkill sox"; ShllCommad(command); });
{
// 如果进程还在运行
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\":\"" + "停止播放成功" + "\"}"; string result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + param.code + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + "停止播放成功" + "\"}";
SubmitLogs(result, "PalyFile"); SubmitLogs(result, "PalyFile");
@ -1014,18 +990,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser
{ {
Task.Run(() => Task.Run(() =>
{ {
if (Typrocess != null) Task.Run(() => { string command = $"pkill sox"; ShllCommad(command); });
{
// 如果进程还在运行
if (!Typrocess.HasExited)
{
// 发送SIGTERM信号来停止进程
Typrocess.Kill();
// 等待进程真正停止
Typrocess.WaitForExit();
}
}
//AutoAudio(ispaly, "");
}); });
Uri uri = new Uri(url); Uri uri = new Uri(url);
//返回 123.xlsx //返回 123.xlsx
@ -1155,10 +1120,13 @@ namespace AKS.EnterpriseLibrary.WebBrowser
string name = string.Empty; string name = string.Empty;
foreach (JObject jo2 in jo1) foreach (JObject jo2 in jo1)
{ {
devidx = jo2["dev_idx"].ToString();
name = jo2["name"].ToString(); name = jo2["name"].ToString();
// // Log.Info(name); if (name.Contains(Parame.gpyVersion))
break; {
devidx = jo2["dev_idx"].ToString();
Parame.gpydevIndex = devidx;
break;
}
} }
return devidx; return devidx;
} }
@ -1380,7 +1348,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser
/// <summary> /// <summary>
/// 签字版 /// 签字版
/// </summary> /// </summary>
private static async void HttpPostResponseBySign(string type, int typeCode, string code,int timeout) private static async void HttpPostResponseBySign(string type, int typeCode, string code, int timeout)
{ {
try try
{ {
@ -1419,7 +1387,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser
/// <summary> /// <summary>
/// 指紋 /// 指紋
/// </summary> /// </summary>
private static async void HttpPostResponseByFinger(string type, int typeCode,int timeout) private static async void HttpPostResponseByFinger(string type, int typeCode, int timeout)
{ {
try try
{ {

7
CPF_Cef/Parame.cs

@ -25,8 +25,13 @@ namespace AksWebBrowser
public static string Ip = "192.168.1.166"; public static string Ip = "192.168.1.166";
//高拍仪url //高拍仪url
public static string gpyUrl = "http://127.0.0.1:6543"; public static string gpyUrl = "http://127.0.0.1:6543";
//高拍仪
public static string gpyVersion = "S1000A3";
//高拍仪devIndex
public static string gpydevIndex = "0";
//签字版、指纹、身份证 //签字版、指纹、身份证
public static string signUrl = "http://192.168.0.234:9399/device"; public static string signUrl = "http://127.0.0.1:9399/device";
public static int timeout= 60;
//票据打印机 //票据打印机
public static string pritPj = "/dev/ttyS7"; public static string pritPj = "/dev/ttyS7";
//波特率 //波特率

Loading…
Cancel
Save