|
|
|
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;
|
|
|
|
using System.Net.Http;
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
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(200).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")
|
|
|
|
{
|
|
|
|
//关闭签字版
|
|
|
|
await PublicSign("close", 2, timeout);
|
|
|
|
Task.Delay(200).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")
|
|
|
|
{
|
|
|
|
//关闭签字版
|
|
|
|
await PublicSign("close", 2, timeout);
|
|
|
|
//读取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
|
|
|
|
{
|
|
|
|
//关闭签字版
|
|
|
|
await PublicSign("close", 2, timeout);
|
|
|
|
//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")
|
|
|
|
{
|
|
|
|
//关闭签字版
|
|
|
|
await PublicSign("close", 2, timeout);
|
|
|
|
return "{\"timestamp\":\"" + "" + "\",\"keycode\":\"" + code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"suffix\":\"png\",\"data\":\"" + "取消签字" + "\"}";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//关闭签字版
|
|
|
|
await PublicSign("close", 2, timeout);
|
|
|
|
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")
|
|
|
|
{
|
|
|
|
//关闭签字版
|
|
|
|
await PublicSign("close", 2, timeout);
|
|
|
|
return "{\"timestamp\":\"" + "" + "\",\"keycode\":\"" + code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"suffix\":\"png\",\"data\":\"" + "取消签字" + "\"}";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//关闭签字版
|
|
|
|
await PublicSign("close", 2, timeout);
|
|
|
|
//Log.Error("请求签字失败" + jo["message"].ToString());
|
|
|
|
return "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + code + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"suffix\":\"png\",\"data\":\"" + "签字失败" + "\"}";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//关闭签字版
|
|
|
|
await PublicSign("close", 2, timeout);
|
|
|
|
return "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + code + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"png\",\"data\":\"" + "关闭成功" + "\"}";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//关闭签字版
|
|
|
|
await PublicSign("close", 2, timeout);
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
Log.Error("获取签字版数据异常:" + ex.Message);
|
|
|
|
//关闭签字版
|
|
|
|
await PublicSign("close", 2, timeout);
|
|
|
|
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;
|
|
|
|
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")
|
|
|
|
{
|
|
|
|
body = await response.Content.ReadAsStringAsync();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
Log.Error("签字版公共请求异常:" + ex.Message);
|
|
|
|
}
|
|
|
|
return body;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 文字转语音
|
|
|
|
/// </summary>
|
|
|
|
/// <returns></returns>
|
|
|
|
public async Task<string> PostTTS(string type, int typeCode, string tts_text)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (tts_text.Length <= 2000)
|
|
|
|
{
|
|
|
|
tts_text =Regex.Replace(tts_text, @" ", " ").Trim();
|
|
|
|
tts_text = Regex.Replace(tts_text, @"\s+", "").Trim();
|
|
|
|
Log.Info("处理后文字:"+tts_text);
|
|
|
|
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数据
|
|
|
|
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数据
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
Log.Error("文字转语音异常:" + ex.Message);
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
await PublicFinger("close", 2, timeout);
|
|
|
|
//读取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
|
|
|
|
{
|
|
|
|
await PublicFinger("close", 2, timeout);
|
|
|
|
//关闭指纹
|
|
|
|
return "200";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
await PublicFinger("close", 2, timeout);
|
|
|
|
//关闭指纹
|
|
|
|
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")
|
|
|
|
{
|
|
|
|
await PublicFinger("close", 2, timeout);
|
|
|
|
//读取指纹
|
|
|
|
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
|
|
|
|
{
|
|
|
|
await PublicFinger("close", 2, timeout);
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { await PublicFinger("close", 2, timeout); return ""; }
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
await PublicFinger("close", 2, timeout);
|
|
|
|
//Log.Error("请求签字失败" + jo["message"].ToString());
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
await PublicFinger("close", 2, timeout);
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
Log.Error("获取指纹异常:" + ex.Message);
|
|
|
|
await PublicFinger("close", 2, timeout);
|
|
|
|
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 ex)
|
|
|
|
{
|
|
|
|
Log.Error("公共读取指纹异常:" + ex.Message);
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
return body;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 读取身份证
|
|
|
|
/// </summary>
|
|
|
|
/// <returns></returns>
|
|
|
|
public async Task<string> OpenGetIdcard(string type, int typeCode, int timeout)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
//关闭身份证
|
|
|
|
await PublicIdcard(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)
|
|
|
|
{
|
|
|
|
//关闭身份证
|
|
|
|
await PublicIdcard(timeout);
|
|
|
|
//读取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;
|
|
|
|
//当前刷身份证的人
|
|
|
|
Parame.ImgBase64 = base64;
|
|
|
|
var OBJ = new
|
|
|
|
{
|
|
|
|
Data = iDCardModel
|
|
|
|
};
|
|
|
|
return JsonConvert.SerializeObject(OBJ);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//关闭身份证
|
|
|
|
await PublicIdcard(timeout);
|
|
|
|
//关闭
|
|
|
|
return "200";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//关闭身份证
|
|
|
|
await PublicIdcard(timeout);
|
|
|
|
//Log.Error("请求签字失败" + jo["message"].ToString());
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//关闭身份证
|
|
|
|
await PublicIdcard(timeout);
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
Log.Error("读取身份证"+ex.Message);
|
|
|
|
//关闭身份证
|
|
|
|
await PublicIdcard(timeout);
|
|
|
|
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(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 ex)
|
|
|
|
{
|
|
|
|
Log.Error("公共读取身份证异常:" + ex.Message);
|
|
|
|
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 ex)
|
|
|
|
{
|
|
|
|
Log.Error("获取问题异常:" + ex.Message);
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
return body;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 读取body数据
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="type"></param>
|
|
|
|
/// <param name="typeCode"></param>
|
|
|
|
/// <param name="timeout"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
public async Task<string> ReadBody()
|
|
|
|
{
|
|
|
|
string body = string.Empty;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Init();
|
|
|
|
|
|
|
|
HttpClientHandler httpClientHandler = new HttpClientHandler();
|
|
|
|
httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain,
|
|
|
|
errors) => true;
|
|
|
|
HttpClient httpClient = new HttpClient(httpClientHandler);
|
|
|
|
|
|
|
|
Log.Info("开始读取body数据");
|
|
|
|
var client = new HttpClient();
|
|
|
|
var request = new HttpRequestMessage
|
|
|
|
{
|
|
|
|
Method = HttpMethod.Get,
|
|
|
|
RequestUri = new Uri("https://wsxf.gj.jcy/xfnwweb/nwxf/tyyw_kg_xfjsdj/ty_v2_zhcxeditform/get?openviewtag=READONLY&srfkey=2af82e4c14bfb5f34fe01f3ed98a9f16"),
|
|
|
|
Headers = {
|
|
|
|
{ "Authorization", "Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiLmnajpkat8NTEwMTkyIiwiZXhwIjoxNzE5MjExNzczLCJpYXQiOjE3MTkxOTczNzN9.y3rq49XSvCMFSb_RxX5SsuC13v_2CR1yG8WbztOsv2uhQS2UL8pP7IY2s2Rbg-G4e0Xz4dFg0Oc9TvvVqp4YAQ" },
|
|
|
|
{ "User-Agent", "Apipost/8 (https://www.apipost.cn)" },
|
|
|
|
},
|
|
|
|
};
|
|
|
|
using (var response = await client.SendAsync(request))
|
|
|
|
{
|
|
|
|
response.EnsureSuccessStatusCode();
|
|
|
|
body = await response.Content.ReadAsStringAsync();
|
|
|
|
}
|
|
|
|
Log.Info("结束读取body数据");
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
body=ex.Message;
|
|
|
|
}
|
|
|
|
return body;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void Init()
|
|
|
|
{
|
|
|
|
#if NETSTANDARD || NET5_0_OR_GREATER
|
|
|
|
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
|
|
|
|
#else
|
|
|
|
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3
|
|
|
|
| SecurityProtocolType.Tls
|
|
|
|
| SecurityProtocolType.Tls11
|
|
|
|
| SecurityProtocolType.Tls12;
|
|
|
|
#endif
|
|
|
|
ServicePointManager.ServerCertificateValidationCallback = (a, b, c, d) => { return true; };
|
|
|
|
ServicePointManager.CheckCertificateRevocationList = true;
|
|
|
|
ServicePointManager.DefaultConnectionLimit = 1000;
|
|
|
|
ServicePointManager.Expect100Continue = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static string NumberToChinese(int number)
|
|
|
|
{
|
|
|
|
string[] chineseNumbers = new string[] { "零", "一", "二", "三", "四", "五", "六", "七", "八", "九" };
|
|
|
|
string[] chineseUnits = new string[] { "", "十", "百", "千", "万" };
|
|
|
|
|
|
|
|
string result = "";
|
|
|
|
int unitPlace = 0;
|
|
|
|
|
|
|
|
if (number == 0)
|
|
|
|
{
|
|
|
|
return chineseNumbers[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
while (number > 0)
|
|
|
|
{
|
|
|
|
int part = number % 10;
|
|
|
|
if (part != 0 || (part == 0 && result.Length > 0 && result[0] != '零'))
|
|
|
|
{
|
|
|
|
result = string.Format("{0}{1}{2}", chineseNumbers[part], chineseUnits[unitPlace], result);
|
|
|
|
}
|
|
|
|
number /= 10;
|
|
|
|
unitPlace++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|