Browse Source

新增超时设置

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

59
CPF_Cef/Common/ChunkedUpload.cs

@ -20,6 +20,7 @@ using static System.Net.Mime.MediaTypeNames;
using System.Text.RegularExpressions;
using AksWebBrowser.Devices;
using LibVLCSharp.Shared;
using System.Threading;
namespace AksWebBrowser.Common
{
@ -143,11 +144,12 @@ namespace AksWebBrowser.Common
/// 获取签字版数据
/// </summary>
/// <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
{
var client = new HttpClient();
client.Timeout = TimeSpan.FromSeconds(timeout);
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");
request.Content = content;
@ -171,47 +173,41 @@ namespace AksWebBrowser.Common
string parameters = jo3["parameters"].ToString();
JObject jo4 = (JObject)JsonConvert.DeserializeObject(parameters);
string sign_pic = jo4["sign_pic"].ToString();
//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 + "\"}";
return "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + code + "\",\"message\":\"success\",\"code\":200,\"status\":true,\"suffix\":\"png\",\"data\":\"" + sign_pic + "\"}";
}
else
{
//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
{
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
{
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
{
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)
{
//Log.Error("签字异常:" + ex.Message);
return "{\"timestamp\":\"" + Utils.GetTimestamp()+ "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"suffix\":\"png\",\"data\":\"" + "签字异常" + "\"}";
if (ex.Message.Contains("HttpClient.Timeout"))
{
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)
{
//Log.Error("签字异常:" + ex.Message);
return "";
}
}
@ -272,11 +267,12 @@ namespace AksWebBrowser.Common
/// 获取指纹
/// </summary>
/// <returns></returns>
public async Task<string> PostFinger(string type, int typeCode)
public async Task<string> PostFinger(string type, int typeCode,int timeout)
{
try
{
var client = new HttpClient();
client.Timeout = TimeSpan.FromSeconds(timeout);
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");
request.Content = content;
@ -324,20 +320,27 @@ namespace AksWebBrowser.Common
}
catch (Exception ex)
{
//Log.Error("签字异常:" + ex.Message);
if (ex.Message.Contains("HttpClient.Timeout"))
{
return "HttpClient.Timeout";
}
else
{
return "";
}
}
}
/// <summary>
/// 读取身份证
/// </summary>
/// <returns></returns>
public async Task<string> OpenGetIdcard(string type, int typeCode)
public async Task<string> OpenGetIdcard(string type, int typeCode, int timeout)
{
try
{
var client = new HttpClient();
client.Timeout = TimeSpan.FromSeconds(timeout);
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");
request.Content = content;
@ -458,10 +461,16 @@ namespace AksWebBrowser.Common
}
catch (Exception ex)
{
//Log.Error("签字异常:" + ex.Message);
if (ex.Message.Contains("HttpClient.Timeout"))
{
return "HttpClient.Timeout";
}
else
{
return "";
}
}
}
}
}

324
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
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";
//波特率

Loading…
Cancel
Save