Browse Source

身份证与双目识别分离,新增双目识别接口

master
胡超1 1 year ago
parent
commit
39a5a45727
  1. 49
      CPF_Cef/Common/ChunkedUpload.cs
  2. 25
      CPF_Cef/Common/WebSocketClientWithHeartbeat.cs
  3. 4
      CPF_Cef/FrmMain.cs
  4. 26
      CPF_Cef/MainModel.cs
  5. 2
      CPF_Cef/Parame.cs

49
CPF_Cef/Common/ChunkedUpload.cs

@ -123,7 +123,7 @@ namespace AksWebBrowser.Common
} }
catch (HttpRequestException e) catch (HttpRequestException e)
{ {
//Log.Error(" get请求: " + e.Message); Log.Error(" get请求: " + e.Message);
} }
} }
@ -250,6 +250,7 @@ namespace AksWebBrowser.Common
} }
catch (Exception ex) catch (Exception ex)
{ {
Log.Error("获取签字版数据异常:" + ex.Message);
//关闭签字版 //关闭签字版
await PublicSign("close", 2, timeout); await PublicSign("close", 2, timeout);
if (ex.Message.Contains("HttpClient.Timeout")) if (ex.Message.Contains("HttpClient.Timeout"))
@ -273,17 +274,24 @@ namespace AksWebBrowser.Common
public async Task<string> PublicSign(string type, int typeCode, int timeout) public async Task<string> PublicSign(string type, int typeCode, int timeout)
{ {
string body = string.Empty; string body = string.Empty;
timeout = timeout == 0 ? Parame.timeout : timeout; try
var client = new HttpClient(); {
client.Timeout = TimeSpan.FromSeconds(timeout); timeout = timeout == 0 ? Parame.timeout : timeout;
var request = new HttpRequestMessage(HttpMethod.Post, Parame.signUrl); var client = new HttpClient();
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"); client.Timeout = TimeSpan.FromSeconds(timeout);
request.Content = content; var request = new HttpRequestMessage(HttpMethod.Post, Parame.signUrl);
var response = await client.SendAsync(request); 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");
response.EnsureSuccessStatusCode(); request.Content = content;
if (response.StatusCode.ToString() == "OK") var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
if (response.StatusCode.ToString() == "OK")
{
body = await response.Content.ReadAsStringAsync();
}
}
catch (Exception ex)
{ {
body = await response.Content.ReadAsStringAsync(); Log.Error("签字版公共请求异常:" + ex.Message);
} }
return body; return body;
} }
@ -298,6 +306,9 @@ namespace AksWebBrowser.Common
{ {
if (tts_text.Length <= 2000) if (tts_text.Length <= 2000)
{ {
tts_text =Regex.Replace(tts_text, @"&nbsp;", " ").Trim();
tts_text = Regex.Replace(tts_text, @"\s+", "").Trim();
Log.Info("处理后文字:"+tts_text);
var client = new HttpClient(); var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, Parame.signUrl); var request = new HttpRequestMessage(HttpMethod.Post, Parame.signUrl);
var content = new StringContent("{\r\n \"command\": \"tts\",\r\n \"command_num\": 201,\r\n \"data\": {\r\n \"operation\": \"text_to_wav\",\r\n \"operation_code\": 1,\r\n \"parameters\": {\r\n \"data_type\": 1,\r\n \"tts_text\": \"" + tts_text + "\"\r\n }\r\n }\r\n }", null, "application/json"); var content = new StringContent("{\r\n \"command\": \"tts\",\r\n \"command_num\": 201,\r\n \"data\": {\r\n \"operation\": \"text_to_wav\",\r\n \"operation_code\": 1,\r\n \"parameters\": {\r\n \"data_type\": 1,\r\n \"tts_text\": \"" + tts_text + "\"\r\n }\r\n }\r\n }", null, "application/json");
@ -389,6 +400,7 @@ namespace AksWebBrowser.Common
} }
catch (Exception ex) catch (Exception ex)
{ {
Log.Error("文字转语音异常:" + ex.Message);
return ""; return "";
} }
} }
@ -500,6 +512,7 @@ namespace AksWebBrowser.Common
} }
catch (Exception ex) catch (Exception ex)
{ {
Log.Error("获取指纹异常:" + ex.Message);
await PublicFinger("close", 2, timeout); await PublicFinger("close", 2, timeout);
if (ex.Message.Contains("HttpClient.Timeout")) if (ex.Message.Contains("HttpClient.Timeout"))
{ {
@ -537,9 +550,9 @@ namespace AksWebBrowser.Common
body = await response.Content.ReadAsStringAsync(); body = await response.Content.ReadAsStringAsync();
} }
} }
catch (Exception) catch (Exception ex)
{ {
Log.Error("公共读取指纹异常:" + ex.Message);
return ""; return "";
} }
return body; return body;
@ -594,6 +607,8 @@ namespace AksWebBrowser.Common
iDCardModel.StartDate = jo4["validity_begin"].ToString(); iDCardModel.StartDate = jo4["validity_begin"].ToString();
iDCardModel.EndDate = jo4["balidity_end"].ToString(); iDCardModel.EndDate = jo4["balidity_end"].ToString();
iDCardModel.ImageBase64 = "data:image/jpg;base64," + base64; iDCardModel.ImageBase64 = "data:image/jpg;base64," + base64;
//当前刷身份证的人
Parame.ImgBase64 = base64;
var OBJ = new var OBJ = new
{ {
Data = iDCardModel Data = iDCardModel
@ -625,6 +640,7 @@ namespace AksWebBrowser.Common
} }
catch (Exception ex) catch (Exception ex)
{ {
Log.Error("读取身份证"+ex.Message);
//关闭身份证 //关闭身份证
await PublicIdcard(timeout); await PublicIdcard(timeout);
if (ex.Message.Contains("HttpClient.Timeout")) if (ex.Message.Contains("HttpClient.Timeout"))
@ -663,8 +679,9 @@ namespace AksWebBrowser.Common
body = await response.Content.ReadAsStringAsync(); body = await response.Content.ReadAsStringAsync();
} }
} }
catch (Exception) catch (Exception ex)
{ {
Log.Error("公共读取身份证异常:" + ex.Message);
return ""; return "";
} }
return body; return body;
@ -695,14 +712,14 @@ namespace AksWebBrowser.Common
body = await response.Content.ReadAsStringAsync(); body = await response.Content.ReadAsStringAsync();
} }
} }
catch (Exception) catch (Exception ex)
{ {
Log.Error("获取问题异常:" + ex.Message);
return ""; return "";
} }
return body; return body;
} }
/// <summary> /// <summary>
/// 读取body数据 /// 读取body数据
/// </summary> /// </summary>

25
CPF_Cef/Common/WebSocketClientWithHeartbeat.cs

@ -80,14 +80,7 @@ namespace AksWebBrowser.Common
string results = Parame.ImgBase64; string results = Parame.ImgBase64;
if (!string.IsNullOrEmpty(results)) if (!string.IsNullOrEmpty(results))
{ {
JObject jo1 = (JObject)JsonConvert.DeserializeObject(results); string ImageBase64 = Parame.ImgBase64;
string data = jo1["data"].ToString();
jo1 = (JObject)JsonConvert.DeserializeObject(data);
string data2 = jo1["Data"].ToString();
jo1 = (JObject)JsonConvert.DeserializeObject(data2);
string ImageBase64 = jo1["ImageBase64"].ToString();
//var faceA = "/data/home/aks/aks/wwwroot/TmpFile/faceA.jpg";
//var faceB = "/data/home/aks/aks/wwwroot/TmpFile/faceB.jpg";
string faceA = Utils.Base64ByImagesPath(ImageBase64.Replace("data:image/jpg;base64,", ""), "faceA"); string faceA = Utils.Base64ByImagesPath(ImageBase64.Replace("data:image/jpg;base64,", ""), "faceA");
string faceB = Utils.Base64ByImagesPath(jo["ImgBase64"].ToString(), "faceB"); string faceB = Utils.Base64ByImagesPath(jo["ImgBase64"].ToString(), "faceB");
var mode2 = new var mode2 = new
@ -103,12 +96,11 @@ namespace AksWebBrowser.Common
else else
{ {
timer.Stop(); timer.Stop();
results = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + "aks100101" + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "人证合一验证失败." + "\"}"; results = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + "aks100120" + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "人证合一验证失败." + "\"}";
Parame.socket.Send(results); Parame.socket.Send(results);
// 断开连接 // 断开连接
_webSocket.Dispose(); _webSocket.Dispose();
} }
} }
} }
} }
@ -122,17 +114,24 @@ namespace AksWebBrowser.Common
string results = string.Empty; string results = string.Empty;
if (status == "0") if (status == "0")
{ {
results = Parame.ImgBase64; results = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + "aks100120" + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + "人证合一验证成功." + "\"}";
} }
else else
{ {
results = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + "aks100101" + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "人证合一验证失败." + "\"}"; results = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + "aks100120" + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "人证合一验证失败." + "\"}";
} }
timer.Stop(); timer.Stop();
Parame.socket.Send(results); Parame.socket.Send(results);
// 断开连接 // 断开连接
_webSocket.Dispose(); _webSocket.Dispose();
} }
else if (functionName == "VideoStream")
{
string VideoBase64 = jo["VideoBase64"].ToString();
string src = "data:image/jpg;base64," + VideoBase64;
string results = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + "aks100121" + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"data\":\"" + src + "\"}";
Parame.socket.Send(results);
}
} }
} }
} }
@ -209,7 +208,7 @@ namespace AksWebBrowser.Common
Send("{\"function\":\"CF_StopLiveDetect\"}", "CF_StopLiveDetect"); Send("{\"function\":\"CF_StopLiveDetect\"}", "CF_StopLiveDetect");
//关闭摄像头 //关闭摄像头
Send("{\"function\":\"CF_CloseCamera\"}", "CF_CloseCamera"); Send("{\"function\":\"CF_CloseCamera\"}", "CF_CloseCamera");
string results = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + "aks100101" + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "活体检测超时." + "\"}"; string results = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + "aks100120" + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "活体检测超时." + "\"}";
Parame.socket.Send(results); Parame.socket.Send(results);
} }
catch { } catch { }

4
CPF_Cef/FrmMain.cs

@ -81,9 +81,9 @@ namespace AksWebBrowser
//浏览器大小 //浏览器大小
Parame.webBrowser.Width = w; Parame.webBrowser.Width = w;
Parame.webBrowser.Height = h; Parame.webBrowser.Height = h;
//Parame.webBrowser.Url = "http://127.0.0.1:8096/#/main-out"; Parame.webBrowser.Url = "http://127.0.0.1:8096/#/main-out";
//Parame.webBrowser.Url = "http://192.168.0.232:8848/html/index.html"; //Parame.webBrowser.Url = "http://192.168.0.232:8848/html/index.html";
Parame.webBrowser.Url = "http://192.168.0.34:8078/#/main-out"; //Parame.webBrowser.Url = "http://192.168.0.34:8078/#/main-out";
//Parame.webBrowser.Url = Application.StartupPath + @"\html\index.html"; //Parame.webBrowser.Url = Application.StartupPath + @"\html\index.html";
//开发者工具暂时只能支持Windows //开发者工具暂时只能支持Windows
//webBrowser.ShowDev(); //webBrowser.ShowDev();

26
CPF_Cef/MainModel.cs

@ -84,6 +84,11 @@ namespace AksWebBrowser
case "aks100101": case "aks100101":
result = IDCardRead(content); result = IDCardRead(content);
break; break;
//aks100120
//开启双目 {"code":"aks100120"}
case "aks100120":
StartFace();
break;
//aks100102 //aks100102
//打印排队票据 {"code":"aks100102","ph":"100101","ddrs":"中国检察","qrcode":"90087100100124433002","ywmc":"信访"} //打印排队票据 {"code":"aks100102","ph":"100101","ddrs":"中国检察","qrcode":"90087100100124433002","ywmc":"信访"}
case "aks100102": case "aks100102":
@ -284,23 +289,9 @@ namespace AksWebBrowser
} }
else else
{ {
string results = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + param.code + "\",\"message\":\"seccse\",\"code\":\"200\",\"status\":true,\"data\":" + IdcardStr + "}";
if (Parame.isSM)
{
Task.Run(async () =>
{
string results = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + param.code + "\",\"message\":\"seccse\",\"code\":\"200\",\"status\":true,\"data\":" + IdcardStr + "}";
StartFace(results);
});
result = "";
}
else
{
result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + param.code + "\",\"message\":\"seccse\",\"code\":\"200\",\"status\":true,\"data\":" + IdcardStr + "}";
}
return result; return result;
} }
} }
SubmitLogs(result, "IDCardRead"); SubmitLogs(result, "IDCardRead");
return result; return result;
@ -1725,16 +1716,15 @@ namespace AksWebBrowser
/// </summary> /// </summary>
private static string smresults = string.Empty; private static string smresults = string.Empty;
private static AutoResetEvent @event9 = new AutoResetEvent(false); private static AutoResetEvent @event9 = new AutoResetEvent(false);
private static async void StartFace(string ImageBase64) private static void StartFace()
{ {
try try
{ {
WebSocketClientWithHeartbeat webSocket = new WebSocketClientWithHeartbeat(); WebSocketClientWithHeartbeat webSocket = new WebSocketClientWithHeartbeat();
Parame.ImgBase64 = ImageBase64;
var mode = new var mode = new
{ {
function = "CF_OpenCamera", function = "CF_OpenCamera",
show = 1, show = 0,
fx = 150, fx = 150,
fy = 800, fy = 800,
fw = 800, fw = 800,

2
CPF_Cef/Parame.cs

@ -19,7 +19,7 @@ namespace AksWebBrowser
public static Window frm { get; set; } public static Window frm { get; set; }
public static List<Func> FuncObject { get; set; } public static List<Func> FuncObject { get; set; }
//接口地址 //接口地址
public static string apiUrl = "http://127.0.0.1:8098";// "http://192.168.0.34:92"; public static string apiUrl = "http://127.0.0.1:8098";//"http://192.168.0.34:92";//
//授权key //授权key
public static string key = "1"; public static string key = "1";
//硬件Ip //硬件Ip

Loading…
Cancel
Save