You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
672 lines
32 KiB
672 lines
32 KiB
using AksWebBrowser; |
|
using AksWebBrowser.Devices; |
|
using AKSWebBrowser.Commen; |
|
using Newtonsoft.Json; |
|
using Newtonsoft.Json.Linq; |
|
using System; |
|
using System.Collections.Generic; |
|
using System.Globalization; |
|
using System.IO; |
|
using System.Net.Http; |
|
using System.Threading.Tasks; |
|
|
|
namespace AksWebBrowser.Common |
|
{ |
|
public class ChunkedUpload |
|
{ |
|
private readonly HttpClient _httpClient; |
|
public static string callback = string.Empty; |
|
public ChunkedUpload(HttpClient httpClient) |
|
{ |
|
_httpClient = httpClient; |
|
} |
|
|
|
public async Task<string> UploadFileAsync(string url, string filePath) |
|
{ |
|
string ret = string.Empty; |
|
using (var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read)) |
|
{ |
|
FileInfo fileInfo = new FileInfo(filePath); |
|
int totalParts = 1; |
|
int chunkNumber = 1; |
|
// 读取文件流其实位置 |
|
var fileStreamPos = 0; |
|
var uploadUrl = $"{url}?partNumber={chunkNumber}&chunks={totalParts}&size={fileInfo.Length}&start={fileStreamPos}&end={fileInfo.Length}&total={fileInfo.Length}&FileName={Path.GetFileName(filePath)}"; |
|
|
|
using (var client = new HttpClient()) |
|
{ |
|
|
|
var formData = new MultipartFormDataContent(); |
|
formData.Add(new StreamContent(fileStream, (int)fileStream.Length), "file", Path.GetFileName(filePath) + ".partNumber-1"); |
|
var response = await client.PostAsync(uploadUrl, formData); |
|
var responseString = await response.Content.ReadAsStringAsync(); |
|
fileStream.Close(); |
|
fileStream.Dispose(); |
|
ret = responseString; |
|
JObject jo = (JObject)JsonConvert.DeserializeObject(ret); |
|
Log.Info("上传文件返回:" + ret); |
|
if (Convert.ToBoolean(jo["IsSucceed"].ToString()) == true) |
|
{ |
|
string result = jo["result"].ToString(); |
|
JObject jo1 = (JObject)JsonConvert.DeserializeObject(result); |
|
ret = jo1["url"].ToString(); |
|
} |
|
} |
|
} |
|
return ret; |
|
} |
|
|
|
/// <summary> |
|
/// get请求 Task<string> |
|
/// </summary> |
|
/// <returns></returns> |
|
|
|
public async Task<string> getReq(string query) |
|
{ |
|
string ret = string.Empty; |
|
ret = await NewMethod(query, ret); |
|
if (query.Contains("getFrame")) |
|
{ |
|
string img = string.Empty; |
|
int num = 0; |
|
while (string.IsNullOrEmpty(img) && num < 5) |
|
{ |
|
JObject jo = (JObject)JsonConvert.DeserializeObject(ret); |
|
if (jo["returnCode"].ToString() == "0") |
|
{ |
|
string data = jo["data"].ToString(); |
|
JObject jo1 = (JObject)JsonConvert.DeserializeObject(data); |
|
//Log.Info("img" + num + (jo1["img"].ToString())); |
|
if (string.IsNullOrEmpty(jo1["img"].ToString())) |
|
{ |
|
ret = await NewMethod(query, ret); |
|
} |
|
else |
|
{ |
|
img = jo1["img"].ToString(); |
|
num = 6; |
|
} |
|
} |
|
else |
|
{ |
|
if (jo["returnCode"].ToString() == "1") |
|
{ |
|
Parame.isGPY = false; |
|
} |
|
ret = await NewMethod(query, ret); |
|
} |
|
num++; |
|
} |
|
} |
|
return ret; |
|
} |
|
|
|
private static async Task<string> NewMethod(string query, string ret) |
|
{ |
|
using (var httpClient = new HttpClient()) |
|
{ |
|
// 构建带参数的请求URI |
|
var uri = Parame.gpyUrl + query; |
|
try |
|
{ |
|
// 发送GET请求 |
|
HttpResponseMessage response = await httpClient.GetAsync(uri); |
|
response.EnsureSuccessStatusCode(); |
|
if (response.StatusCode.ToString() == "OK") |
|
{ |
|
// 读取响应内容 |
|
string body = await response.Content.ReadAsStringAsync(); |
|
ret = body; |
|
} |
|
} |
|
catch (HttpRequestException e) |
|
{ |
|
//Log.Error(" get请求: " + e.Message); |
|
} |
|
} |
|
|
|
return ret; |
|
} |
|
|
|
/// <summary> |
|
/// 获取签字版数据 |
|
/// </summary> |
|
/// <returns></returns> |
|
public async Task<string> PostSign(string type, int typeCode, string code, int timeout) |
|
{ |
|
try |
|
{ |
|
//关闭签字版 |
|
await PublicSign("close", 2, timeout); |
|
Task.Delay(500).Wait(); |
|
string body = await PublicSign(type, typeCode, timeout); |
|
if (!string.IsNullOrEmpty(body)) |
|
{ |
|
if (type == "open" && typeCode == 1) |
|
{ |
|
JObject jo = (JObject)JsonConvert.DeserializeObject(body); |
|
string ret = jo["ret_info"].ToString(); |
|
JObject 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 if (jo2["code"].ToString() == "1") |
|
{ |
|
Task.Delay(500).Wait(); |
|
//关闭签字版 |
|
await PublicSign("close", 2, timeout); |
|
Task.Delay(500).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\":\"" + "" + "\",\"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\":\"" + "" + "\",\"keycode\":\"" + code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"suffix\":\"png\",\"data\":\"" + "取消签字" + "\"}"; |
|
} |
|
else |
|
{ |
|
//Log.Error("请求签字失败" + jo["message"].ToString()); |
|
return "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"suffix\":\"png\",\"data\":\"" + "签字失败" + "\"}"; |
|
} |
|
} |
|
else |
|
{ |
|
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() + "\",\"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\":\"" + "关闭签字失败" + "\"}"; |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
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\":\"" + "签字异常" + "\"}"; |
|
} |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 签字版公共请求 |
|
/// </summary> |
|
/// <param name="type"></param> |
|
/// <param name="typeCode"></param> |
|
/// <param name="timeout"></param> |
|
/// <returns></returns> |
|
public async Task<string> 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; |
|
} |
|
|
|
/// <summary> |
|
/// 文字转语音 |
|
/// </summary> |
|
/// <returns></returns> |
|
public async Task<string> PostTTS(string type, int typeCode, string tts_text) |
|
{ |
|
try |
|
{ |
|
if (tts_text.Length <= 2000) |
|
{ |
|
var client = new HttpClient(); |
|
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"); |
|
request.Content = content; |
|
var response = await client.SendAsync(request); |
|
response.EnsureSuccessStatusCode(); |
|
if (response.StatusCode.ToString() == "OK") |
|
{ |
|
// 读取响应内容 |
|
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); |
|
if (jo2["code"].ToString() == "0") |
|
{ |
|
//读取data数据 |
|
//读取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 sound_path = jo4["sound_path"].ToString(); |
|
return sound_path; |
|
} |
|
else |
|
{ |
|
//Log.Error("请求签字失败" + jo["message"].ToString()); |
|
return ""; |
|
} |
|
} |
|
else |
|
{ |
|
return ""; |
|
} |
|
} |
|
else |
|
{ |
|
int segmentLength = 2000; |
|
string[] segments = Utils.SplitTextIntoSegments(tts_text, segmentLength); |
|
List<string> lit = new List<string>(); |
|
string _tmp = string.Empty; |
|
foreach (string segment in segments) |
|
{ |
|
var client = new HttpClient(); |
|
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\": \"" + segment + "\"\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 response.Content.ReadAsStringAsync(); |
|
// Log.Info("文字转语音:" + body); |
|
JObject jo = (JObject)JsonConvert.DeserializeObject(body); |
|
string ret = jo["ret_info"].ToString(); |
|
JObject jo2 = (JObject)JsonConvert.DeserializeObject(ret); |
|
if (jo2["code"].ToString() == "0") |
|
{ |
|
//读取data数据 |
|
//读取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 sound_path = jo4["sound_path"].ToString(); |
|
lit.Add(sound_path); |
|
_tmp = _tmp + " " + sound_path + " "; |
|
} |
|
} |
|
|
|
} |
|
if (lit.Count == segments.Length) |
|
{ |
|
string time = DateTime.Now.ToString("yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo); |
|
string path = $"/tmp/{time}.wav"; |
|
string command = $"sox {_tmp} -m {path}"; |
|
MainModel.ShllCommad(command); |
|
return path; |
|
} |
|
else |
|
{ |
|
return ""; |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
return ""; |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 获取指纹 |
|
/// </summary> |
|
/// <returns></returns> |
|
public async Task<string> PostFinger(string type, int typeCode, int timeout) |
|
{ |
|
try |
|
{ |
|
await PublicFinger("close", 2, timeout); |
|
Task.Delay(500).Wait(); |
|
string body = await PublicFinger(type, typeCode, timeout); |
|
if (!string.IsNullOrEmpty(body)) |
|
{ |
|
|
|
JObject jo = (JObject)JsonConvert.DeserializeObject(body); |
|
string ret = jo["ret_info"].ToString(); |
|
JObject jo2 = (JObject)JsonConvert.DeserializeObject(ret); |
|
if (jo2["code"].ToString() == "0") |
|
{ |
|
if (type == "open" && typeCode == 1) |
|
{ |
|
//读取指纹 |
|
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 "200"; |
|
} |
|
|
|
} |
|
else if (jo2["code"].ToString() == "1") |
|
{ |
|
Task.Delay(500).Wait(); |
|
body = await PublicFinger("close", 2, timeout); |
|
Task.Delay(500).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()); |
|
return ""; |
|
} |
|
|
|
} |
|
else |
|
{ |
|
return ""; |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
if (ex.Message.Contains("HttpClient.Timeout")) |
|
{ |
|
return "HttpClient.Timeout"; |
|
} |
|
else |
|
{ |
|
return ""; |
|
} |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 公共读取指纹 |
|
/// </summary> |
|
/// <param name="type"></param> |
|
/// <param name="typeCode"></param> |
|
/// <param name="timeout"></param> |
|
/// <returns></returns> |
|
public async Task<string> PublicFinger(string type, int typeCode, int timeout) |
|
{ |
|
string body = string.Empty; |
|
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\": \"" + 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(); |
|
} |
|
} |
|
catch (Exception) |
|
{ |
|
|
|
return ""; |
|
} |
|
return body; |
|
} |
|
|
|
/// <summary> |
|
/// 读取身份证 |
|
/// </summary> |
|
/// <returns></returns> |
|
public async Task<string> OpenGetIdcard(string type, int typeCode, int timeout) |
|
{ |
|
try |
|
{ |
|
//关闭身份证 |
|
await PublicIdcard(type, typeCode, timeout); |
|
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\": \"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; |
|
var response = await client.SendAsync(request); |
|
response.EnsureSuccessStatusCode(); |
|
if (response.StatusCode.ToString() == "OK") |
|
{ |
|
// 读取响应内容 |
|
string body = await response.Content.ReadAsStringAsync(); |
|
JObject jo = (JObject)JsonConvert.DeserializeObject(body); |
|
string ret = jo["ret_info"].ToString(); |
|
JObject 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); |
|
string base64 = jo4["face_data"].ToString(); |
|
IDCardModel iDCardModel = new IDCardModel(); |
|
iDCardModel.Name = jo4["cn_name"].ToString(); |
|
iDCardModel.Sex = jo4["sex"].ToString(); |
|
iDCardModel.Nation = jo4["nation"].ToString(); |
|
iDCardModel.BirthDay = jo4["birth_date"].ToString(); |
|
iDCardModel.Addr = jo4["address"].ToString(); |
|
iDCardModel.Id = jo4["idcard_number"].ToString(); |
|
iDCardModel.Regorg = jo4["deparment"].ToString(); |
|
iDCardModel.StartDate = jo4["validity_begin"].ToString(); |
|
iDCardModel.EndDate = jo4["balidity_end"].ToString(); |
|
iDCardModel.ImageBase64 = "data:image/jpg;base64," + base64; |
|
var OBJ = new |
|
{ |
|
Data = iDCardModel |
|
}; |
|
return JsonConvert.SerializeObject(OBJ); |
|
} |
|
else |
|
{ |
|
//关闭 |
|
return "200"; |
|
} |
|
} |
|
else |
|
{ |
|
//Log.Error("请求签字失败" + jo["message"].ToString()); |
|
return ""; |
|
} |
|
} |
|
else |
|
{ |
|
return ""; |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
if (ex.Message.Contains("HttpClient.Timeout")) |
|
{ |
|
return "HttpClient.Timeout"; |
|
} |
|
else |
|
{ |
|
return ""; |
|
} |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 公共读取身份证 |
|
/// </summary> |
|
/// <param name="type"></param> |
|
/// <param name="typeCode"></param> |
|
/// <param name="timeout"></param> |
|
/// <returns></returns> |
|
public async Task<string> PublicIdcard(string type, int typeCode, int timeout) |
|
{ |
|
string body = string.Empty; |
|
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\": \"idcard\",\r\n \"command_num\": 141,\r\n \"data\": {\r\n \"operation\": \"close\",\r\n \"operation_code\": 2,\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(); |
|
} |
|
} |
|
catch (Exception) |
|
{ |
|
return ""; |
|
} |
|
return body; |
|
} |
|
|
|
/// <summary> |
|
/// 获取问题 |
|
/// </summary> |
|
/// <param name="PetitionId"></param> |
|
/// <param name="PId"></param> |
|
/// <param name="Name"></param> |
|
/// <param name="PageIndex"></param> |
|
/// <param name="PageSize"></param> |
|
/// <returns></returns> |
|
public async Task<string> GetQuestionAnswer(string PetitionId, string PId, string Name, int PageIndex, int PageSize) |
|
{ |
|
string body = string.Empty; |
|
try |
|
{ |
|
var client = new HttpClient(); |
|
var request = new HttpRequestMessage(HttpMethod.Post, Parame.qwUrl + "/api/QuestionAnswer/Query"); |
|
var content = new StringContent("{\r\n \"PetitionId\": \"" + PetitionId + "\",\r\n \"PId\": \"" + PId + "\",\r\n \"Name\": \"" + Name + "\",\r\n \"PageIndex\": " + PageIndex + ",\r\n \"PageSize\": " + PageSize + "\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(); |
|
} |
|
} |
|
catch (Exception) |
|
{ |
|
return ""; |
|
} |
|
return body; |
|
} |
|
|
|
|
|
} |
|
}
|
|
|