Browse Source

修改签字版

master
胡超1 1 year ago
parent
commit
eb4f3d7fe7
  1. 36
      CPF_Cef/Common/TcpClients.cs
  2. 8
      CPF_Cef/FrmMain.cs
  3. 71
      CPF_Cef/MainModel.cs
  4. 2
      CPF_Cef/Parame.cs

36
CPF_Cef/Common/TcpClients.cs

@ -10,6 +10,7 @@ using System.Net;
using System.Net.Http;
using System.IO.Ports;
using System.Timers;
using AKS.EnterpriseLibrary.WebBrowser;
namespace AksWebBrowser.Common
{
@ -24,15 +25,16 @@ namespace AksWebBrowser.Common
try
{
//初始化连接 192.168.1.166
Parame.tcpClient = new TcpClient("127.0.0.1", 1234);
Parame.tcpClient = new TcpClient(Parame.Ip, 1234);
NetworkStream stream = Parame.tcpClient.GetStream();
Task.Factory.StartNew(() => { Write(stream); });
ThreadPool.QueueUserWorkItem(SendInstruction, Parame.tcpClient);
}
catch (Exception ex) { Console.WriteLine(ex.Message); }
finally {
catch { Parame.tcpClient = null; }
finally
{
//开启定时
System.Timers.Timer timer = new System.Timers.Timer(3000);//3秒钟的时间间隔
System.Timers.Timer timer = new System.Timers.Timer(1000);//3秒钟的时间间隔
timer.Elapsed += OnTimedEvent;
timer.AutoReset = true;//重复执行
timer.Enabled = true;//启动定时器
@ -47,13 +49,13 @@ namespace AksWebBrowser.Common
{
if (Parame.tcpClient == null)
{
Parame.tcpClient = new TcpClient("127.0.0.1", 1234);
Parame.tcpClient = new TcpClient(Parame.Ip, 1234);
NetworkStream stream = Parame.tcpClient.GetStream();
Task.Factory.StartNew(() => { Write(stream); });
ThreadPool.QueueUserWorkItem(SendInstruction, Parame.tcpClient);
}
}
catch (Exception ex) { Console.WriteLine(ex.Message); Parame.tcpClient = null; }
catch { Parame.tcpClient = null; }
finally { }
}
@ -100,7 +102,7 @@ namespace AksWebBrowser.Common
SendDataWithHeader(stream, "heartbeatClient");
}
}
catch (Exception ex) { Console.WriteLine(ex.Message); jsonstr = string.Empty; Parame.tcpClient = null; }
catch { jsonstr = string.Empty; Parame.tcpClient = null; }
finally { }
}
}
@ -121,9 +123,16 @@ namespace AksWebBrowser.Common
Array.Copy(messageBytes, 0, data, header.Length, messageBytes.Length);
stream.Write(data, 0, data.Length);
jsonstr = string.Empty;
while (string.IsNullOrEmpty(jsonstr)){ Task.Delay(10).Wait(); }
while (string.IsNullOrEmpty(jsonstr) && Parame.tcpClient != null)
{
Task.Delay(10).Wait();
}
if (string.IsNullOrEmpty(jsonstr))
{
jsonstr = MainModel.str2Base64("{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "硬件服务器未启动" + "\"}");
}
}
catch (Exception ex) {Console.WriteLine(ex.Message); Parame.tcpClient = null; }
catch { Parame.tcpClient = null; }
finally { }
return jsonstr;
}
@ -144,10 +153,9 @@ namespace AksWebBrowser.Common
Thread.Sleep(122000);
SendDataWithHeader(stream, "keepAlive");
Console.WriteLine("发送心跳指令关闭连接");
}
}
catch (Exception ex) { Console.WriteLine(ex.Message); Parame.tcpClient = null; }
catch { Parame.tcpClient = null; }
finally { }
}
@ -171,10 +179,9 @@ namespace AksWebBrowser.Common
}
return BitConverter.ToInt32(header, 0);
}
catch (Exception ex)
catch
{
Parame.tcpClient = null;
Console.WriteLine(ex.Message);
return -1;
}
}
@ -204,10 +211,9 @@ namespace AksWebBrowser.Common
}
return bytesRead;
}
catch (Exception ex)
catch
{
Parame.tcpClient = null;
Console.WriteLine(ex.Message);
return -1;
}
}

8
CPF_Cef/FrmMain.cs

@ -19,8 +19,8 @@ namespace AKS.EnterpriseLibrary.WebBrowser
{
public class FrmMain : Window
{
public int w = 1920;
public int h = 1080;
public int w = 1080;
public int h = 1920;
protected override void InitializeComponent()
@ -78,8 +78,8 @@ namespace AKS.EnterpriseLibrary.WebBrowser
//浏览器大小
Parame.webBrowser.Width = w;
Parame.webBrowser.Height = h;
//Parame.webBrowser.Url = "http://192.168.0.34:8078/#/main-out";
Parame.webBrowser.Url = Application.StartupPath + @"\html\index.html";
Parame.webBrowser.Url = "http://192.168.0.34:8078/#/main-out";
//Parame.webBrowser.Url = Application.StartupPath + @"\html\index.html";
//开发者工具暂时只能支持Windows
//webBrowser.ShowDev();
//SetTaskStatus.Showtask();

71
CPF_Cef/MainModel.cs

@ -49,6 +49,10 @@ namespace AKS.EnterpriseLibrary.WebBrowser
Utils.MessagesBox("读取身份证设备未授权使用");
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "读取身份证设备未授权使用" + "\"}";
}
else if (Parame.tcpClient == null)
{
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "硬件服务未启动" + "\"}";
}
else
{
paramsString = "{\"callback\":\"" + callback + "\",\"type\":\"1\",\"param\":{\"data\":\"" + "" + "\"}}";
@ -87,6 +91,10 @@ namespace AKS.EnterpriseLibrary.WebBrowser
Utils.MessagesBox("打印排队票据设备未授权使用");
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "打印排队票据设备未授权使用" + "\"}";
}
else if (Parame.tcpClient == null)
{
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "硬件服务未启动" + "\"}";
}
else
{
string paramsString = "{\"callback\":\"" + callback + "\",\"type\":\"2\",\"param\":{\"ph\":\"" + ph + "\",\"ddrs\":\"" + ddrs + "\",\"qrcode\":\"" + qrcode + "\",\"ywmc\":\"" + ywmc + "\"}}";
@ -127,6 +135,10 @@ namespace AKS.EnterpriseLibrary.WebBrowser
Utils.MessagesBox("文字语音播报设备未授权使用");
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "文字语音播报设备未授权使用" + "\"}";
}
else if (Parame.tcpClient == null)
{
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "硬件服务未启动" + "\"}";
}
else
{
string paramsString = "{\"callback\":\"" + callback + "\",\"type\":\"3\",\"param\":{\"text\":\"" + text + "\",\"ispaye\":\"" + ispaye + "\"}}";
@ -228,6 +240,10 @@ namespace AKS.EnterpriseLibrary.WebBrowser
Utils.MessagesBox("发送短信设备未授权使用");
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "发送短信设备未授权使用" + "\"}";
}
else if (Parame.tcpClient == null)
{
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "硬件服务未启动" + "\"}";
}
else
{
string paramsString = "{\"callback\":\"" + callback + "\",\"type\":\"4\",\"param\":{\"content\":\"" + content + "\",\"phone\":\"" + phone + "\"}}";
@ -263,6 +279,10 @@ namespace AKS.EnterpriseLibrary.WebBrowser
Utils.MessagesBox("高拍仪设备未授权使用");
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "高拍仪设备未授权使用" + "\"}";
}
else if (Parame.tcpClient == null)
{
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "硬件服务未启动" + "\"}";
}
else
{
string paramsString = "{\"callback\":\"" + callback + "\",\"type\":\"5\",\"param\":{\"url\":\"" + url + "\"}}";
@ -270,9 +290,9 @@ namespace AKS.EnterpriseLibrary.WebBrowser
string base64 = str2Base64(paramsString);
string str = tcpClients.SendDataWithHeader(Parame.tcpClient.GetStream(), base64);
string data = Base64str2(str);
if (data == "400")
if (data == "400" || data.Contains("fali"))
{
string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "扫描文件失败" + "\"}";
string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "扫描文件失败,请重新扫描!" + "\"}";
SubmitLogs(result, "openCamera");
return result;
}
@ -308,6 +328,10 @@ namespace AKS.EnterpriseLibrary.WebBrowser
Utils.MessagesBox("签字版设备未授权使用");
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "签字版设备未授权使用" + "\"}";
}
else if (Parame.tcpClient == null)
{
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "硬件服务未启动" + "\"}";
}
else
{
paramsString = "{\"callback\":\"" + callback + "\",\"type\":\"6\",\"param\":{\"data\":\"" + "" + "\"}}";
@ -343,6 +367,10 @@ namespace AKS.EnterpriseLibrary.WebBrowser
Utils.MessagesBox("签字版设备未授权使用");
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "签字版设备未授权使用" + "\"}";
}
else if (Parame.tcpClient == null)
{
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "硬件服务未启动" + "\"}";
}
else
{
paramsString = "{\"callback\":\"" + callback + "\",\"type\":\"7\",\"param\":{\"data\":\"" + "" + "\"}}";
@ -378,6 +406,10 @@ namespace AKS.EnterpriseLibrary.WebBrowser
Utils.MessagesBox("签字版设备未授权使用");
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "签字版设备未授权使用" + "\"}";
}
else if (Parame.tcpClient == null)
{
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "硬件服务未启动" + "\"}";
}
else
{
string paramsString = "{\"callback\":\"" + callback + "\",\"type\":\"8\",\"param\":{\"url\":\"" + url + "\"}}";
@ -385,7 +417,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser
string base64 = str2Base64(paramsString);
string str = tcpClients.SendDataWithHeader(Parame.tcpClient.GetStream(), base64);
string data = Base64str2(str);
if (data == "400")
if (data == "400"|| data.Contains("fali"))
{
string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "获取签字失败" + "\"}";
SubmitLogs(result, "OpenSign");
@ -426,6 +458,10 @@ namespace AKS.EnterpriseLibrary.WebBrowser
Utils.MessagesBox("录音设备未授权使用");
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "录音设备未授权使用" + "\"}";
}
else if (Parame.tcpClient == null)
{
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "硬件服务未启动" + "\"}";
}
else
{
string paramsString = "{\"callback\":\"" + callback + "\",\"type\":\"11\",\"param\":{\"isopen\":\"" + isopen + "\",\"url\":\"" + url + "\"}}";
@ -436,7 +472,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser
if (!string.IsNullOrEmpty(url) && !isopen)
{
string tt = Base64str2(str);
Log.Info(tt);
Log.Info("结束录音上传文件"+tt);
//下载文件
DateTime dateTime = DateTime.Now;
string time = DateTime.Now.ToString(
@ -447,7 +483,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser
Directory.CreateDirectory(dirpath);
}
var filepath = System.IO.Path.Combine(dirpath, time);
string path = dirpath + @"/" + time + ".wav" ;
string path = dirpath + @"/" + time + ".wav";
WebRequest request = WebRequest.Create(tt);
WebResponse response = request.GetResponse();
using (Stream stream = response.GetResponseStream())
@ -459,7 +495,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser
}
response.Close();
//上传文件
Task.Run(async () =>{UploadInfo(url, path);});
Task.Run(async () => { UploadInfo(url, path); });
@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);//获取的是一个数组
@ -501,6 +537,10 @@ namespace AKS.EnterpriseLibrary.WebBrowser
Utils.MessagesBox("打印机设备未授权使用");
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "打印机设备未授权使用" + "\"}";
}
else if (Parame.tcpClient == null)
{
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "硬件服务未启动" + "\"}";
}
else
{
Task.Run(async () =>
@ -529,15 +569,6 @@ namespace AKS.EnterpriseLibrary.WebBrowser
string command = $"lp -d {PrinterName} {path}";
ShllCommad(command);
});
//string id = Guid.NewGuid().ToString();
////通过文件发送数据
//com.NewMethod(path, id);
//string paramsString = "{\"callback\":\"" + callback + "\",\"bsid\":\"" + id + "\",\"type\":\"9\",\"param\":{\"url\":\"" + url + "\",\"ext\":\"" + ext + "\"}}";
//Log.Info("根据文件地址在线打印: " + paramsString + "");
//string base64_1 = str2Base64(paramsString);
//string str = com.SendData(base64_1, callback);
//return Base64str2(str);
string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + "打印成功" + "\"}";
SubmitLogs(result, "PrintFile");
return result;
@ -569,6 +600,10 @@ namespace AKS.EnterpriseLibrary.WebBrowser
Utils.MessagesBox("打印机设备未授权使用");
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "打印机设备未授权使用" + "\"}";
}
else if (Parame.tcpClient == null)
{
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "硬件服务未启动" + "\"}";
}
else
{
Task.Run(async () =>
@ -643,10 +678,12 @@ namespace AKS.EnterpriseLibrary.WebBrowser
Utils.MessagesBox("音频设备未授权使用");
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "音频设备未授权使用" + "\"}";
}
else if (Parame.tcpClient == null)
{
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "硬件服务未启动" + "\"}";
}
else
{
Log.Info("播放音频文件: " + url + "");
Log.Info("是否播放: " + ispaly + "");
if (ispaly)
{
Task.Run(() =>

2
CPF_Cef/Parame.cs

@ -17,6 +17,8 @@ namespace AksWebBrowser
public static string apiUrl = "http://192.168.0.34:92";
//授权key
public static string key = "1";
//硬件Ip
public static string Ip = "192.168.1.166";
}
public struct Func
{

Loading…
Cancel
Save