|
using System.IO;
|
using System.Net.Mime;
|
using System.Text.RegularExpressions;
|
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.Extensions.Caching.Memory;
|
using Newtonsoft.Json;
|
using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
|
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
|
using StackExchange.Profiling;
|
using WIDESEAWCS_Core;
|
using WIDESEAWCS_Core.Authorization;
|
using WIDESEAWCS_Core.BaseController;
|
using WIDESEAWCS_Core.Const;
|
using WIDESEAWCS_Core.Extensions;
|
using WIDESEAWCS_Core.Helper;
|
using WIDESEAWCS_Core.HttpContextUser;
|
using WIDESEAWCS_Core.Utilities;
|
using WIDESEAWCS_DTO.SerialPort;
|
using WIDESEAWCS_ISystemServices;
|
using WIDESEAWCS_Model;
|
using WIDESEAWCS_Model.Models;
|
using WIDESEAWCS_Model.Models.System;
|
using IOFile = System.IO.File;
|
|
namespace WIDESEAWCS_WCSServer.Controllers
|
{
|
[Route("api/UserFace")]
|
[ApiController]
|
public class Sys_UserFaceController : ApiBaseController<ISys_UserFaceService, Sys_UserFace>
|
{
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
public Sys_UserFaceController(ISys_UserFaceService userService, IHttpContextAccessor httpContextAccessor) : base(userService)
|
{
|
_httpContextAccessor = httpContextAccessor;
|
}
|
[HttpPost, Route("FaceRecognition"), AllowAnonymous]
|
public WebResponseContent FaceRecognition([FromBody] ImageModel model)
|
{
|
return Service.FaceRecognition(model);
|
}
|
|
[HttpPost, Route("FaceEnter")]
|
public WebResponseContent FaceEnter([FromBody] ImageModel model)
|
{
|
return Service.FaceEnter(model);
|
}
|
|
[HttpPost, HttpGet, Route("DownlodaFacePlugin"), AllowAnonymous]
|
public ActionResult DownlodaFacePlugin()
|
{
|
try
|
{
|
string path = $"{AppDomain.CurrentDomain.BaseDirectory}DownLoad/";
|
if (!Directory.Exists(path)) Directory.CreateDirectory(path);
|
path += "face-plugin.zip";
|
|
if (IOFile.Exists(path))
|
{
|
byte[] fileBytes = IOFile.ReadAllBytes(path);
|
return File(
|
fileBytes,
|
MediaTypeNames.Application.Octet,
|
Path.GetFileName(path)
|
);
|
}
|
else
|
{
|
return Json(WebResponseContent.Instance.Error($"未找到文件"));
|
}
|
}
|
catch (Exception ex)
|
{
|
return Json(WebResponseContent.Instance.Error($"下载失败:{ex.Message}"));
|
}
|
}
|
|
[HttpPost, HttpGet, Route("DownloadRegFile"), AllowAnonymous]
|
public ActionResult DownloadRegFile([FromBody] PathModel model)
|
{
|
try
|
{
|
string folderPath = model.Path;
|
|
foreach (var item in folderPath.ToCharArray())
|
{
|
if (Regex.IsMatch(item.ToString(), @"[\u4e00-\u9fa5]"))
|
{
|
return Json(WebResponseContent.Instance.Error($"插件路径不能包含中文"));
|
}
|
}
|
|
string path = $"{AppDomain.CurrentDomain.BaseDirectory}DownLoad/";
|
|
// 如果文件夹不存在,则创建文件夹
|
//if (!Directory.Exists(folderPath))
|
//{
|
// return Json(WebResponseContent.Instance.Error($"插件路径不存在"));
|
//}
|
// 获取日志文件路径
|
string filePath = Path.Combine(path, "reg.reg");
|
|
if (IOFile.Exists(filePath))
|
{
|
IOFile.Delete(filePath); // 删除已存在的日志文件
|
}
|
|
// 构造日志内容
|
string content = $"Windows Registry Editor Version 5.00\r\n[HKEY_CLASSES_ROOT\\myapp]\r\n@=\"URL:MyApp Protocol\"\r\n\"URL Protocol\"=\"\"\r\n[HKEY_CLASSES_ROOT\\myapp\\shell]\r\n[HKEY_CLASSES_ROOT\\myapp\\shell\\open]\r\n[HKEY_CLASSES_ROOT\\myapp\\shell\\open\\command]\r\n@=\"\\\"{model.Path.Replace(@"\", @"\\")}\\\\FaceSdkX64Register.exe\\\" \\\"%1\\\"\"";
|
|
// 将日志内容追加到日志文件中
|
IOFile.AppendAllText(filePath, content);
|
|
byte[] fileBytes = IOFile.ReadAllBytes(filePath);
|
return File(
|
fileBytes,
|
MediaTypeNames.Application.Octet,
|
Path.GetFileName(filePath)
|
);
|
}
|
catch (Exception ex)
|
{
|
return Json(WebResponseContent.Instance.Error($"下载失败:{ex.Message}"));
|
}
|
}
|
}
|
public class PathModel
|
{
|
public string Path { get; set; }
|
}
|
}
|