|
|
|
|
using AksWebBrowser.Common;
|
|
|
|
|
using AKSWebBrowser.Commen;
|
|
|
|
|
using AKSWebBrowser.Common;
|
|
|
|
|
using CPF.Cef;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using static System.Net.Mime.MediaTypeNames;
|
|
|
|
|
|
|
|
|
|
namespace AKS.EnterpriseLibrary.WebBrowser
|
|
|
|
|
{
|
|
|
|
|
public class MainModel : CPF.CpfObject
|
|
|
|
|
{
|
|
|
|
|
public COMUtils com = new COMUtils();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 读取身份证卡号
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="paramsString"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[JSFunction]
|
|
|
|
|
public string IDCardRead(string paramsString)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
paramsString = "{\"type\":\"1\",\"param\":{\"data\":\"" + "" + "\"}}";
|
|
|
|
|
Log.Info("读取身份证卡号: " + paramsString + "");
|
|
|
|
|
string base64 = str2Base64(paramsString);
|
|
|
|
|
string str = com.SendData(base64);
|
|
|
|
|
if (string.IsNullOrEmpty(str))
|
|
|
|
|
{
|
|
|
|
|
return "{\"message\":\"success\",\"code\":\"400\",\"status\":false,\"data\":\"" + "获取数据失败" + "\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return Base64str2(str);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Log.Error("读取身份证卡号异常: " + ex.Message + "");
|
|
|
|
|
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 打印排队票据
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ph">排号</param>
|
|
|
|
|
/// <param name="ddrs">等待人数</param>
|
|
|
|
|
/// <param name="qrcode">二维码</param>
|
|
|
|
|
/// <param name="ywmc">办理业务名称</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[JSFunction]
|
|
|
|
|
public string SendByPrint(string ph, string ddrs, string qrcode, string ywmc)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string paramsString = "{\"type\":\"2\",\"param\":{\"ph\":\"" + ph + "\",\"ddrs\":\"" + ddrs + "\",\"qrcode\":\"" + qrcode + "\",\"ywmc\":\"" + ywmc + "\"}}";
|
|
|
|
|
Log.Info("打印排队票据: " + paramsString + "");
|
|
|
|
|
string base64 = str2Base64(paramsString);
|
|
|
|
|
string str = com.SendData(base64);
|
|
|
|
|
if (string.IsNullOrEmpty(str))
|
|
|
|
|
{
|
|
|
|
|
return "{\"message\":\"success\",\"code\":\"400\",\"status\":false,\"data\":\"" + "打印排队票据失败" + "\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return Base64str2(str);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Log.Error("打印排队票据异常: " + ex.Message + "");
|
|
|
|
|
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 文字语音播报
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="text"></param>
|
|
|
|
|
/// <param name="ispaye"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[JSFunction]
|
|
|
|
|
public string payleText(string text, bool ispaye)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (text.Length > 65535)
|
|
|
|
|
{
|
|
|
|
|
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":" + "文字太长" + "}";
|
|
|
|
|
}
|
|
|
|
|
string paramsString = "{\"type\":\"3\",\"param\":{\"text\":\"" + text + "\",\"ispaye\":\"" + ispaye + "\"}}";
|
|
|
|
|
Log.Info("文字语音播报: " + paramsString + "");
|
|
|
|
|
string base64 = str2Base64(paramsString);
|
|
|
|
|
if (base64.Length > 1024)
|
|
|
|
|
{
|
|
|
|
|
string url = "http://192.168.0.34:92/api/UploadFP/UploadFP";
|
|
|
|
|
Task.Run(async () =>
|
|
|
|
|
{
|
|
|
|
|
DateTime dateTime = DateTime.Now;
|
|
|
|
|
string time = DateTime.Now.ToString(
|
|
|
|
|
"yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo);
|
|
|
|
|
var dirpath = Path.Combine(Environment.CurrentDirectory, "wwwroot", "TempFile");
|
|
|
|
|
if (!Directory.Exists(dirpath))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(dirpath);
|
|
|
|
|
}
|
|
|
|
|
var filepath = Path.Combine(dirpath, time);
|
|
|
|
|
string path = dirpath + @"/" + time + ".txt";
|
|
|
|
|
base64 = str2Base64(text);
|
|
|
|
|
byte[] bytes = Convert.FromBase64String(base64);
|
|
|
|
|
System.IO.FileStream stream = new System.IO.FileStream(path, System.IO.FileMode.CreateNew);
|
|
|
|
|
System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream);
|
|
|
|
|
writer.Write(bytes, 0, bytes.Length);
|
|
|
|
|
writer.Close();
|
|
|
|
|
Log.Info("文字语音播报临时文件: " + path + "");
|
|
|
|
|
UploadInfo(url, path);
|
|
|
|
|
});
|
|
|
|
|
@event2.WaitOne();
|
|
|
|
|
Regex re = new Regex(@"(((?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(:[0-9]+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)");
|
|
|
|
|
MatchCollection mc = re.Matches(url);//获取的是一个数组
|
|
|
|
|
string pdfurl = mc[0].ToString() + "://" + mc[1].ToString() + urlpath;
|
|
|
|
|
paramsString = "{\"type\":\"3\",\"param\":{\"text\":\"" + pdfurl + "\",\"ispaye\":\"" + ispaye + "\"}}";
|
|
|
|
|
Log.Info("文字语音播报: " + paramsString + "");
|
|
|
|
|
base64 = str2Base64(paramsString);
|
|
|
|
|
}
|
|
|
|
|
string str = com.SendData(base64);
|
|
|
|
|
if (string.IsNullOrEmpty(str))
|
|
|
|
|
{
|
|
|
|
|
return "{\"message\":\"success\",\"code\":\"400\",\"status\":false,\"data\":\"" + "文字语音播报失败" + "\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return Base64str2(str);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Log.Error("文字语音播报异常: " + ex.Message + "");
|
|
|
|
|
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 发送短信
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="content"></param>
|
|
|
|
|
/// <param name="phone"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[JSFunction]
|
|
|
|
|
public string SendSSM(string content, string phone)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string paramsString = "{\"type\":\"4\",\"param\":{\"content\":\"" + content + "\",\"phone\":\"" + phone + "\"}}";
|
|
|
|
|
Log.Info("发送短信: " + paramsString + "");
|
|
|
|
|
string base64 = str2Base64(paramsString);
|
|
|
|
|
string str = com.SendData(base64);
|
|
|
|
|
if (string.IsNullOrEmpty(str))
|
|
|
|
|
{
|
|
|
|
|
return "{\"message\":\"success\",\"code\":\"400\",\"status\":false,\"data\":\"" + "发送短信失败" + "\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return Base64str2(str);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Log.Error("发送短信异常: " + ex.Message + "");
|
|
|
|
|
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 打开高拍仪并且进行快速扫描文件
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="url"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[JSFunction]
|
|
|
|
|
public string openCamera(string url)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string paramsString = "{\"type\":\"5\",\"param\":{\"url\":\"" + url + "\"}}";
|
|
|
|
|
Log.Info("打开高拍仪并且进行快速扫描文件: " + paramsString + "");
|
|
|
|
|
string base64 = str2Base64(paramsString);
|
|
|
|
|
string str = com.SendData(base64);
|
|
|
|
|
if (string.IsNullOrEmpty(str))
|
|
|
|
|
{
|
|
|
|
|
return "{\"message\":\"success\",\"code\":\"400\",\"status\":false,\"data\":\"" + "打开高拍仪并且进行快速扫描文件失败" + "\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return Base64str2(str);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Log.Error("打开高拍仪并且进行快速扫描文件异常: " + ex.Message + "");
|
|
|
|
|
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 打开签字版
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="paramsString"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[JSFunction]
|
|
|
|
|
public string OpenSign(string paramsString)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
paramsString = "{\"type\":\"6\",\"param\":{\"data\":\"" + "" + "\"}}";
|
|
|
|
|
Log.Info("打开签字版: " + paramsString + "");
|
|
|
|
|
string base64 = str2Base64(paramsString);
|
|
|
|
|
string str = com.SendData(base64);
|
|
|
|
|
if (string.IsNullOrEmpty(str))
|
|
|
|
|
{
|
|
|
|
|
return "{\"message\":\"success\",\"code\":\"400\",\"status\":false,\"data\":\"" + "打开签字版失败" + "\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return Base64str2(str);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Log.Error("打开签字版异常: " + ex.Message + "");
|
|
|
|
|
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 关闭签字版
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="paramsString"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[JSFunction]
|
|
|
|
|
public string CloseSign(string paramsString)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
paramsString = "{\"type\":\"7\",\"param\":{\"data\":\"" + "" + "\"}}";
|
|
|
|
|
Log.Info("关闭签字版: " + paramsString + "");
|
|
|
|
|
string base64 = str2Base64(paramsString);
|
|
|
|
|
string str = com.SendData(base64);
|
|
|
|
|
if (string.IsNullOrEmpty(str))
|
|
|
|
|
{
|
|
|
|
|
return "{\"message\":\"success\",\"code\":\"400\",\"status\":false,\"data\":\"" + "关闭签字版失败" + "\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return Base64str2(str);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Log.Error("关闭签字版异常: " + ex.Message + "");
|
|
|
|
|
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取签字版数据
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="url"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[JSFunction]
|
|
|
|
|
public string GetSignData(string url)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string paramsString = "{\"type\":\"8\",\"param\":{\"url\":\"" + url + "\"}}";
|
|
|
|
|
Log.Info("获取签字版数据: " + paramsString + "");
|
|
|
|
|
string base64 = str2Base64(paramsString);
|
|
|
|
|
string str = com.SendData(base64);
|
|
|
|
|
if (string.IsNullOrEmpty(str))
|
|
|
|
|
{
|
|
|
|
|
return "{\"message\":\"success\",\"code\":\"400\",\"status\":false,\"data\":\"" + "获取签字版数据失败" + "\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return Base64str2(str);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Log.Error("获取签字版数据异常: " + ex.Message + "");
|
|
|
|
|
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 开始录音、取消录音、结束录音
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="isopen"></param>
|
|
|
|
|
/// <param name="url"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[JSFunction]
|
|
|
|
|
public string SoundRecording(bool isopen, string url)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string paramsString = "{\"type\":\"11\",\"param\":{\"isopen\":\"" + isopen + "\",\"url\":\"" + url + "\"}}";
|
|
|
|
|
Log.Info("开始录音、取消录音、结束录音: " + paramsString + "");
|
|
|
|
|
string base64 = str2Base64(paramsString);
|
|
|
|
|
string str = com.SendData(base64);
|
|
|
|
|
if (string.IsNullOrEmpty(str))
|
|
|
|
|
{
|
|
|
|
|
return "{\"message\":\"success\",\"code\":\"400\",\"status\":false,\"data\":\"" + "开始录音、取消录音、结束录音失败" + "\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return Base64str2(str);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Log.Error("开始录音、取消录音、结束录音异常: " + ex.Message + "");
|
|
|
|
|
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据文件地址在线打印
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="filename"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[JSFunction]
|
|
|
|
|
public string PrintFile(string url, string ext)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string paramsString = "{\"type\":\"9\",\"param\":{\"url\":\"" + url + "\",\"ext\":\"" + ext + "\"}}";
|
|
|
|
|
Log.Info("根据文件地址在线打印: " + paramsString + "");
|
|
|
|
|
string base64_1 = str2Base64(paramsString);
|
|
|
|
|
string str = com.SendData(base64_1);
|
|
|
|
|
if (string.IsNullOrEmpty(str))
|
|
|
|
|
{
|
|
|
|
|
return "{\"message\":\"success\",\"code\":\"400\",\"status\":false,\"data\":\"" + "根据文件地址在线打印失败" + "\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return Base64str2(str);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Log.Error("根据文件地址在线打印异常: " + ex.Message + "");
|
|
|
|
|
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据文件base64打印
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="base64"></param>
|
|
|
|
|
/// <param name="ext"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[JSFunction]
|
|
|
|
|
public string PrintBase64(string url, string base64, string ext)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Task.Run(async () =>
|
|
|
|
|
{
|
|
|
|
|
DateTime dateTime = DateTime.Now;
|
|
|
|
|
string time = DateTime.Now.ToString(
|
|
|
|
|
"yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo);
|
|
|
|
|
var dirpath = Path.Combine(Environment.CurrentDirectory, "wwwroot", "PrintFile");
|
|
|
|
|
if (!Directory.Exists(dirpath))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(dirpath);
|
|
|
|
|
}
|
|
|
|
|
var filepath = Path.Combine(dirpath, time);
|
|
|
|
|
string path = dirpath + @"/" + time + "." + ext;
|
|
|
|
|
byte[] bytes = Convert.FromBase64String(base64);
|
|
|
|
|
System.IO.FileStream stream = new System.IO.FileStream(path, System.IO.FileMode.CreateNew);
|
|
|
|
|
System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream);
|
|
|
|
|
writer.Write(bytes, 0, bytes.Length);
|
|
|
|
|
writer.Close();
|
|
|
|
|
Log.Info("根据文件base64打印: " + path + "");
|
|
|
|
|
UploadInfo(url, path);
|
|
|
|
|
});
|
|
|
|
|
@event2.WaitOne();
|
|
|
|
|
Regex re = new Regex(@"(((?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(:[0-9]+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)");
|
|
|
|
|
MatchCollection mc = re.Matches(url);//获取的是一个数组
|
|
|
|
|
string pdfurl = mc[0].ToString() + "://" + mc[1].ToString() + urlpath;
|
|
|
|
|
Log.Info("根据文件base64打印: " + pdfurl + "");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string paramsString = "{\"type\":\"9\",\"param\":{\"url\":\"" + pdfurl + "\",\"ext\":\"" + ext + "\"}}";
|
|
|
|
|
Log.Info("根据文件base64打印: " + paramsString + "");
|
|
|
|
|
string base64_1 = str2Base64(paramsString);
|
|
|
|
|
string str = com.SendData(base64_1);
|
|
|
|
|
if (string.IsNullOrEmpty(str))
|
|
|
|
|
{
|
|
|
|
|
return "{\"message\":\"success\",\"code\":\"400\",\"status\":false,\"data\":\"" + "根据文件base64打印失败" + "\"}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return Base64str2(str);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Log.Error("根据文件base64打印异常: " + ex.Message + "");
|
|
|
|
|
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 初始文件上传
|
|
|
|
|
/// </summary>
|
|
|
|
|
private string urlpath = string.Empty;
|
|
|
|
|
private AutoResetEvent @event2 = new AutoResetEvent(false);
|
|
|
|
|
private async void UploadInfo(string url, string srpath)
|
|
|
|
|
{
|
|
|
|
|
var httpClient = new HttpClient();
|
|
|
|
|
var uploader = new ChunkedUpload(httpClient);
|
|
|
|
|
urlpath = await uploader.UploadFileAsync(url, srpath);
|
|
|
|
|
@event2.Set();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// string 转换为 base64
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static string str2Base64(string str)
|
|
|
|
|
{
|
|
|
|
|
byte[] b = System.Text.Encoding.UTF8.GetBytes(str);
|
|
|
|
|
string result = Convert.ToBase64String(b);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// base64 转换为 string
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="data"></param>
|
|
|
|
|
public static string Base64str2(string data)
|
|
|
|
|
{
|
|
|
|
|
byte[] c = Convert.FromBase64String(data);
|
|
|
|
|
string result = System.Text.Encoding.UTF8.GetString(c);
|
|
|
|
|
Log.Info("接收返回数据:" + result);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据程序名称杀死进程
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="processName"></param>
|
|
|
|
|
public static void KillProcessByName(string processName)
|
|
|
|
|
{
|
|
|
|
|
Process[] processes = Process.GetProcessesByName(processName);
|
|
|
|
|
foreach (Process process in processes)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
process.Kill();
|
|
|
|
|
process.WaitForExit(); // 等待进程退出
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex) { }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 关闭串口
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void CLoseCOM()
|
|
|
|
|
{
|
|
|
|
|
com.ClosePort();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|