yanjinhui
2025-06-12 95ac5296182b763d12125c1d47f53c00632ffc41
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
 
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; }
    }
}