diff --git a/CPF_Cef/Common/ChunkedUpload.cs b/CPF_Cef/Common/ChunkedUpload.cs index a01d071..7eb27a1 100644 --- a/CPF_Cef/Common/ChunkedUpload.cs +++ b/CPF_Cef/Common/ChunkedUpload.cs @@ -136,21 +136,11 @@ namespace AksWebBrowser.Common { try { - - timeout = timeout == 0 ? Parame.timeout : timeout; - 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; - var response = await client.SendAsync(request); - response.EnsureSuccessStatusCode(); - if (response.StatusCode.ToString() == "OK") + string body = await PublicSign(type, typeCode, timeout); + if (!string.IsNullOrEmpty(body)) { if (type == "open" && typeCode == 1) { - // 读取响应内容 - string body = await response.Content.ReadAsStringAsync(); JObject jo = (JObject)JsonConvert.DeserializeObject(body); string ret = jo["ret_info"].ToString(); JObject jo2 = (JObject)JsonConvert.DeserializeObject(ret); @@ -165,6 +155,56 @@ namespace AksWebBrowser.Common string sign_pic = jo4["sign_pic"].ToString(); return "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + code + "\",\"message\":\"success\",\"code\":200,\"status\":true,\"suffix\":\"png\",\"data\":\"" + sign_pic + "\"}"; } + else if (jo2["code"].ToString() == "1") + { + Task.Delay(1000).Wait(); + //关闭签字版 + await PublicSign("close", 2, timeout); + Task.Delay(1000).Wait(); + //打开签字版 + body = await PublicSign(type, typeCode, timeout); + if (!string.IsNullOrEmpty(body)) + { + jo = (JObject)JsonConvert.DeserializeObject(body); + ret = jo["ret_info"].ToString(); + jo2 = (JObject)JsonConvert.DeserializeObject(ret); + if (jo2["code"].ToString() == "0") + { + //读取data数据 + string data = jo["data"].ToString(); + JObject jo3 = (JObject)JsonConvert.DeserializeObject(data); + //读取parameters数据 + string parameters = jo3["parameters"].ToString(); + JObject jo4 = (JObject)JsonConvert.DeserializeObject(parameters); + string sign_pic = jo4["sign_pic"].ToString(); + 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() + "\",\"keycode\":\"" + code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"suffix\":\"png\",\"data\":\"" + "签字失败" + "\"}"; + } + } + else if (jo2["code"].ToString() == "2") + { + return "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"suffix\":\"png\",\"data\":\"" + "用户取消签字" + "\"}"; + } + else + { + if (type == "open" && typeCode == 1) + { + 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\":\"" + "关闭签字失败" + "\"}"; + } + } + } + else if (jo2["code"].ToString() == "2") + { + return "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"suffix\":\"png\",\"data\":\"" + "用户取消签字" + "\"}"; + } else { //Log.Error("请求签字失败" + jo["message"].ToString()); @@ -201,6 +241,31 @@ namespace AksWebBrowser.Common } } + /// + /// 签字版公共请求 + /// + /// + /// + /// + /// + public static async Task PublicSign(string type, int typeCode, int timeout) + { + string body = string.Empty; + timeout = timeout == 0 ? Parame.timeout : timeout; + 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; + var response = await client.SendAsync(request); + response.EnsureSuccessStatusCode(); + if (response.StatusCode.ToString() == "OK") + { + body = await response.Content.ReadAsStringAsync(); + } + return body; + } + /// /// 文字转语音 /// @@ -316,19 +381,9 @@ namespace AksWebBrowser.Common { try { - timeout = timeout == 0 ? Parame.timeout : timeout; - 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; - var response = await client.SendAsync(request); - response.EnsureSuccessStatusCode(); - if (response.StatusCode.ToString() == "OK") + string body = await PublicFinger(type, typeCode, timeout); + if (!string.IsNullOrEmpty(body)) { - // 读取响应内容 - string body = await response.Content.ReadAsStringAsync(); - // Log.Info("获取指纹:" + body); JObject jo = (JObject)JsonConvert.DeserializeObject(body); string ret = jo["ret_info"].ToString(); JObject jo2 = (JObject)JsonConvert.DeserializeObject(ret); @@ -353,6 +408,45 @@ namespace AksWebBrowser.Common return "200"; } } + else if (jo2["code"].ToString() == "1") + { + Task.Delay(1000).Wait(); + body = await PublicFinger("close", 2, timeout); + Task.Delay(1000).Wait(); + body = await PublicFinger(type, typeCode, timeout); + if (!string.IsNullOrEmpty(body)) + { + jo = (JObject)JsonConvert.DeserializeObject(body); + ret = jo["ret_info"].ToString(); + jo2 = (JObject)JsonConvert.DeserializeObject(ret); + if (jo2["code"].ToString() == "0") + { + //读取指纹 + if (typeCode == 1) + { + //读取data数据 + string data = jo["data"].ToString(); + JObject jo3 = (JObject)JsonConvert.DeserializeObject(data); + //读取parameters数据 + string parameters = jo3["parameters"].ToString(); + JObject jo4 = (JObject)JsonConvert.DeserializeObject(parameters); + //读取签字base64 + string fpr_pic = jo4["fpr_pic"].ToString(); + return fpr_pic; + } + else + { + //关闭指纹 + return "200"; + } + } + else + { + return ""; + } + } + else { return ""; } + } else { //Log.Error("请求签字失败" + jo["message"].ToString()); @@ -377,6 +471,31 @@ namespace AksWebBrowser.Common } } + /// + /// 公共读取指纹 + /// + /// + /// + /// + /// + public static async Task PublicFinger(string type, int typeCode, int timeout) + { + string body = string.Empty; + timeout = timeout == 0 ? Parame.timeout : timeout; + 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\": \"" + type + "\",\r\n \"operation_code\": " + typeCode + ",\r\n \"parameters\": {\r\n }\r\n }\r\n}", null, "text/plain"); + request.Content = content; + var response = await client.SendAsync(request); + response.EnsureSuccessStatusCode(); + if (response.StatusCode.ToString() == "OK") + { + body = await response.Content.ReadAsStringAsync(); + } + return body; + } + /// /// 读取身份证 /// diff --git a/CPF_Cef/MainModel.cs b/CPF_Cef/MainModel.cs index 1cbbfc7..5d8de7b 100644 --- a/CPF_Cef/MainModel.cs +++ b/CPF_Cef/MainModel.cs @@ -54,7 +54,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser { //返回内容 string result = string.Empty; - content = Base64str2(content); + // content = Base64str2(content); // Log.Info("收到请求:" + socket.ConnectionInfo.ClientIpAddress + " 请求参数:" + content); if (!string.IsNullOrEmpty(content)) { @@ -684,7 +684,6 @@ namespace AKS.EnterpriseLibrary.WebBrowser Task.Run(() => {HttpPostResponseByFinger("open", 1, param.timeout); }); event2.WaitOne(); string result = string.Empty; - Log.Info("指纹数据" + fingerStr); if (string.IsNullOrEmpty(fingerStr)) { result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + param.code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "读取失败" + "\"}";