Browse Source

新增超时设置

master
胡超1 1 year ago
parent
commit
ed14cb66cc
  1. 63
      CPF_Cef/Common/ChunkedUpload.cs
  2. 392
      CPF_Cef/MainModel.cs
  3. 2
      CPF_Cef/Parame.cs

63
CPF_Cef/Common/ChunkedUpload.cs

@ -20,6 +20,7 @@ using static System.Net.Mime.MediaTypeNames;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using AksWebBrowser.Devices; using AksWebBrowser.Devices;
using LibVLCSharp.Shared; using LibVLCSharp.Shared;
using System.Threading;
namespace AksWebBrowser.Common namespace AksWebBrowser.Common
{ {
@ -143,11 +144,12 @@ namespace AksWebBrowser.Common
/// 获取签字版数据 /// 获取签字版数据
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public async Task<string> PostSign(string type, int typeCode, string code) public async Task<string> PostSign(string type, int typeCode, string code, int timeout)
{ {
try try
{ {
var client = new HttpClient(); var client = new HttpClient();
client.Timeout = TimeSpan.FromSeconds(timeout);
var request = new HttpRequestMessage(HttpMethod.Post, Parame.signUrl); var request = new HttpRequestMessage(HttpMethod.Post, Parame.signUrl);
var content = new StringContent("{\r\n \"command\": \"sign\",\r\n \"command_num\": 111,\r\n \"data\": {\r\n \"operation\": \"" + type + "\",\r\n \"operation_code\": " + typeCode + ",\r\n \"parameters\": {\r\n \"data_type\": 1\r\n }\r\n }\r\n}", null, "application/json"); var content = new StringContent("{\r\n \"command\": \"sign\",\r\n \"command_num\": 111,\r\n \"data\": {\r\n \"operation\": \"" + type + "\",\r\n \"operation_code\": " + typeCode + ",\r\n \"parameters\": {\r\n \"data_type\": 1\r\n }\r\n }\r\n}", null, "application/json");
request.Content = content; request.Content = content;
@ -171,47 +173,41 @@ namespace AksWebBrowser.Common
string parameters = jo3["parameters"].ToString(); string parameters = jo3["parameters"].ToString();
JObject jo4 = (JObject)JsonConvert.DeserializeObject(parameters); JObject jo4 = (JObject)JsonConvert.DeserializeObject(parameters);
string sign_pic = jo4["sign_pic"].ToString(); string sign_pic = jo4["sign_pic"].ToString();
return "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + code + "\",\"message\":\"success\",\"code\":200,\"status\":true,\"suffix\":\"png\",\"data\":\"" + sign_pic + "\"}";
//string dirpath = Utils.getSystemPaht() + @"/wwwroot/SignFile";
//if (!Directory.Exists(dirpath))
//{
// Directory.CreateDirectory(dirpath);
//}
//var tempFile = dirpath + "/sign.jpg";
//string command = $"convert {sign_pic_path} -quality 10 {tempFile}";
//MainModel.ShllCommad(command);
//byte[] byteArray = File.ReadAllBytes(tempFile);
//string base64String = Convert.ToBase64String(byteArray);
return "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"message\":\"success\",\"code\":200,\"status\":true,\"suffix\":\"png\",\"data\":\"" + sign_pic + "\"}";
} }
else else
{ {
//Log.Error("请求签字失败" + jo["message"].ToString()); //Log.Error("请求签字失败" + jo["message"].ToString());
return "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"suffix\":\"png\",\"data\":\"" + "签字失败" + "\"}"; return "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"suffix\":\"png\",\"data\":\"" + "签字失败" + "\"}";
} }
} }
else else
{ {
return "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"png\",\"data\":\"" + "关闭成功" + "\"}"; return "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + code + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"png\",\"data\":\"" + "关闭成功" + "\"}";
} }
} }
else else
{ {
if (type == "open" && typeCode == 1) if (type == "open" && typeCode == 1)
{ {
return "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"suffix\":\"png\",\"data\":\"" + "签字失败" + "\"}"; return "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"suffix\":\"png\",\"data\":\"" + "签字失败" + "\"}";
} }
else else
{ {
return "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"suffix\":\"png\",\"data\":\"" + "关闭签字失败" + "\"}"; return "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"suffix\":\"png\",\"data\":\"" + "关闭签字失败" + "\"}";
} }
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
//Log.Error("签字异常:" + ex.Message); if (ex.Message.Contains("HttpClient.Timeout"))
return "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"suffix\":\"png\",\"data\":\"" + "签字异常" + "\"}"; {
return "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"suffix\":\"png\",\"data\":\"" + "在规定时间内未签字" + "\"}";
}
else
{
return "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"suffix\":\"png\",\"data\":\"" + "签字异常" + "\"}";
}
} }
} }
@ -263,7 +259,6 @@ namespace AksWebBrowser.Common
} }
catch (Exception ex) catch (Exception ex)
{ {
//Log.Error("签字异常:" + ex.Message);
return ""; return "";
} }
} }
@ -272,11 +267,12 @@ namespace AksWebBrowser.Common
/// 获取指纹 /// 获取指纹
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public async Task<string> PostFinger(string type, int typeCode) public async Task<string> PostFinger(string type, int typeCode,int timeout)
{ {
try try
{ {
var client = new HttpClient(); var client = new HttpClient();
client.Timeout = TimeSpan.FromSeconds(timeout);
var request = new HttpRequestMessage(HttpMethod.Post, Parame.signUrl); var request = new HttpRequestMessage(HttpMethod.Post, Parame.signUrl);
var content = new StringContent("{\r\n \"command\": \"finger\",\r\n \"command_num\": 121,\r\n \"data\": {\r\n \"operation\": \"open\",\r\n \"operation_code\": 1,\r\n \"parameters\": {\r\n }\r\n }\r\n}", null, "text/plain"); var content = new StringContent("{\r\n \"command\": \"finger\",\r\n \"command_num\": 121,\r\n \"data\": {\r\n \"operation\": \"open\",\r\n \"operation_code\": 1,\r\n \"parameters\": {\r\n }\r\n }\r\n}", null, "text/plain");
request.Content = content; request.Content = content;
@ -324,8 +320,14 @@ namespace AksWebBrowser.Common
} }
catch (Exception ex) catch (Exception ex)
{ {
//Log.Error("签字异常:" + ex.Message); if (ex.Message.Contains("HttpClient.Timeout"))
return ""; {
return "HttpClient.Timeout";
}
else
{
return "";
}
} }
} }
@ -333,11 +335,12 @@ namespace AksWebBrowser.Common
/// 读取身份证 /// 读取身份证
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public async Task<string> OpenGetIdcard(string type, int typeCode) public async Task<string> OpenGetIdcard(string type, int typeCode, int timeout)
{ {
try try
{ {
var client = new HttpClient(); var client = new HttpClient();
client.Timeout = TimeSpan.FromSeconds(timeout);
var request = new HttpRequestMessage(HttpMethod.Post, Parame.signUrl); var request = new HttpRequestMessage(HttpMethod.Post, Parame.signUrl);
var content = new StringContent("{\r\n \"command\": \"idcard\",\r\n \"command_num\": 141,\r\n \"data\": {\r\n \"operation\": \"open\",\r\n \"operation_code\": 1,\r\n \"parameters\": {\r\n }\r\n }\r\n}", null, "text/plain"); var content = new StringContent("{\r\n \"command\": \"idcard\",\r\n \"command_num\": 141,\r\n \"data\": {\r\n \"operation\": \"open\",\r\n \"operation_code\": 1,\r\n \"parameters\": {\r\n }\r\n }\r\n}", null, "text/plain");
request.Content = content; request.Content = content;
@ -458,8 +461,14 @@ namespace AksWebBrowser.Common
} }
catch (Exception ex) catch (Exception ex)
{ {
//Log.Error("签字异常:" + ex.Message); if (ex.Message.Contains("HttpClient.Timeout"))
return ""; {
return "HttpClient.Timeout";
}
else
{
return "";
}
} }
} }

392
CPF_Cef/MainModel.cs

File diff suppressed because one or more lines are too long

2
CPF_Cef/Parame.cs

@ -26,7 +26,7 @@ namespace AksWebBrowser
//高拍仪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 signUrl = "http://127.0.0.1:9399/device"; public static string signUrl = "http://192.168.0.234:9399/device";
//票据打印机 //票据打印机
public static string pritPj = "/dev/ttyS7"; public static string pritPj = "/dev/ttyS7";
//波特率 //波特率

Loading…
Cancel
Save