移动系统liao
2024-08-16 4c3ac42be64eae9c92d9b876b16312d5de46338e
完成身份证上传验证接口,完成创建人脸库,创建人员库
10个文件已修改
296 ■■■■■ 已修改文件
cylsg/EzTencentCloud/ITencentCloudService.cs 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
cylsg/EzTencentCloud/TencentCloudConfig.json 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
cylsg/EzTencentCloud/TencentCloudService.cs 139 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
cylsg/EzUpFile/EzFileUploadService.cs 77 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
cylsg/EzUpFile/EzUpFile.csproj 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
cylsg/EzUpFile/IEzFileUploadService.cs 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
cylsg/EzUpFile/UpFileController.cs 30 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
cylsg/cylsg.Application/System/Services/SystemService.cs 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
cylsg/cylsg.Authorization/cylsg.Authorization.csproj 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
cylsg/cylsg.Model/UserModel/UserWorker.cs 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
cylsg/EzTencentCloud/ITencentCloudService.cs
@@ -13,6 +13,7 @@
    /// </summary>
    public interface ITencentCloudService: IScoped
    {
        #region orc 图文识别
        /// <summary>
        /// 身份证识别,并剪裁
        /// </summary>
@@ -25,5 +26,10 @@
        /// </summary>
        /// <returns></returns>
        string GetIdCordImg();
        #endregion
        #region iai 人脸识别
        public void IaiCreatGroup();
        #endregion
    }
}
cylsg/EzTencentCloud/TencentCloudConfig.json
@@ -2,5 +2,11 @@
  "TencentCloud": {
    "SecretId":    "AKIDIPFp9CyThfMmvoQlpeCl34pKYVBahY9T",
    "SecretKey":   "4rNcaHhrkMhmb9QQ9bmgKipfFZcOt86n"
  },
  //人脸库相关配置
  "IAIGroupSet": {
    "ID": "cylsg",
    "Name": "川印临时工"
  }
}
cylsg/EzTencentCloud/TencentCloudService.cs
@@ -12,11 +12,25 @@
using TencentCloud.Common.Profile;
using Furion.DependencyInjection;
using Furion;
using TencentCloud.Iai.V20200303;
using TencentCloud.Iai.V20200303.Models;
namespace EzTencentCloud
{
    public class TencentCloudService: ITencentCloudService, IScoped
    {
        public   TencentCloudService()
        {
        }
        #region orc 图文识别
        /// <summary>
        /// 剪裁后的身份证图片
        /// </summary>
@@ -35,6 +49,7 @@
        {
            try
            {
                Credential cred = new Credential
                {
                    SecretId = App.Configuration["TencentCloud:SecretId"] ??"AKIDIPFp9CyThfMmvoQlpeCl34pKYVBahY9T",
@@ -48,7 +63,8 @@
                httpProfile.Endpoint = ("ocr.tencentcloudapi.com");
                clientProfile.HttpProfile = httpProfile;
                OcrClient client = new OcrClient(cred, "ap-beijing", clientProfile);
                var _ocrClient = new OcrClient(cred, "ap-chengdu", clientProfile);
                IDCardOCRRequest req = new IDCardOCRRequest();
                if (isFRONT)
                    req.CardSide = "FRONT";
@@ -73,7 +89,7 @@
                    Quality = true,
                });
                IDCardOCRResponse resp =  client.IDCardOCRSync(req);
                IDCardOCRResponse resp = _ocrClient.IDCardOCRSync(req);
                if (resp == null)
                    throw new Exception("图片无法识别,请重新选择身份证图片");
@@ -101,7 +117,126 @@
        }
        #endregion
        #region iai 人脸识别
        public void  IaiCreatGroup()
        {
            Credential cred = new Credential
            {
                SecretId = App.Configuration["TencentCloud:SecretId"] ?? "AKIDIPFp9CyThfMmvoQlpeCl34pKYVBahY9T",
                SecretKey = App.Configuration["TencentCloud:SecretKey"] ?? "4rNcaHhrkMhmb9QQ9bmgKipfFZcOt86n"
            };
            ClientProfile clientProfile = new ClientProfile();
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.Endpoint = ("iai.tencentcloudapi.com");
            clientProfile.HttpProfile = httpProfile;
            var iaiClient = new IaiClient(cred, "ap-chengdu", clientProfile);
            try
            {
                var retinfo = iaiClient.GetGroupInfoSync(new GetGroupInfoRequest
                {
                    GroupId = App.Configuration["IAIGroupSet:ID"] ?? "",
                });
            }
            catch (TencentCloudSDKException e)
            {
                if (e.ErrorCode == "InvalidParameterValue.GroupIdNotExist")
                {
                    CreateGroupRequest request = new CreateGroupRequest()
                    {
                        GroupId = App.Configuration["IAIGroupSet:ID"],
                        GroupName= App.Configuration["IAIGroupSet:Name"],
                    };
                    var aia = iaiClient.CreateGroupSync(request);
                }
            }
        }
        public bool IaiAddPerso( string img64,string PersonNameId,string PersonName,  int PersonGender)
        {
            Credential cred = new Credential
            {
                SecretId = App.Configuration["TencentCloud:SecretId"] ?? "AKIDIPFp9CyThfMmvoQlpeCl34pKYVBahY9T",
                SecretKey = App.Configuration["TencentCloud:SecretKey"] ?? "4rNcaHhrkMhmb9QQ9bmgKipfFZcOt86n"
            };
            ClientProfile clientProfile = new ClientProfile();
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.Endpoint = ("iai.tencentcloudapi.com");
            clientProfile.HttpProfile = httpProfile;
            var iaiClient = new IaiClient(cred, "ap-chengdu", clientProfile);
           var ret=  iaiClient.CreatePerson(new TencentCloud.Iai.V20200303.Models.CreatePersonRequest
            {
                GroupId = App.Configuration["IAIGroupSet:ID"],
                Image = img64,
                 PersonId= PersonNameId,
                PersonName= PersonName,
                Gender=PersonGender,
            });
            if(ret.IsFaulted)
            return false;
            else
            return true;
        }
        public bool IaiAddPersoImg(string img64, string PersonNameId, string PersonName, int PersonGender)
        {
            Credential cred = new Credential
            {
                SecretId = App.Configuration["TencentCloud:SecretId"] ?? "AKIDIPFp9CyThfMmvoQlpeCl34pKYVBahY9T",
                SecretKey = App.Configuration["TencentCloud:SecretKey"] ?? "4rNcaHhrkMhmb9QQ9bmgKipfFZcOt86n"
            };
            ClientProfile clientProfile = new ClientProfile();
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.Endpoint = ("iai.tencentcloudapi.com");
            clientProfile.HttpProfile = httpProfile;
            var iaiClient = new IaiClient(cred, "ap-chengdu", clientProfile);
            var ret = iaiClient.CreateFace( new TencentCloud.Iai.V20200303.Models.CreateFaceRequest
            {
                PersonId = PersonNameId,
                Images = [img64],
            });
            if (ret.IsFaulted)
                return false;
            else
                return true;
        }
        #endregion
    }
cylsg/EzUpFile/EzFileUploadService.cs
@@ -3,14 +3,17 @@
using Aliyun.OSS.Util;
using cylsg.utility;
using cylsg.utility.Extend;
using EzTencentCloud;
using Furion;
using Furion.DependencyInjection;
using Furion.FriendlyException;
using Microsoft.AspNetCore.Http;
using SqlSugar;
using System.Drawing;
using System.Globalization;
using System.Security.Policy;
using TencentCloud.Ocr.V20181119.Models;
namespace EzUpFile
{
    /// <summary>
@@ -21,11 +24,13 @@
        private readonly HttpRequest? _request;
        private readonly ISqlSugarClient _sqlSugarClient;
        public EzFileUploadService(IHttpContextAccessor httpContext, ISqlSugarClient sqlSugarClient)
        private readonly ITencentCloudService _tcs;
        public EzFileUploadService(IHttpContextAccessor httpContext, ISqlSugarClient sqlSugarClient,ITencentCloudService tencentCloudService)
        {
            _request = httpContext.HttpContext?.Request ?? null;
            _sqlSugarClient = sqlSugarClient;
            _tcs= tencentCloudService;
        }
        /// <summary>
@@ -275,6 +280,76 @@
            return true;
        }
        public async Task<(IDCardOCRResponse,string)> UpIdCord(  string PageName = "FRONT")
        {
            try
            {
                var maxSize = 1024 * 1024 * 5; //上传大小5M
                var FileData = _request?.Form?.Files["file"];
                if (FileData.Length > maxSize)
                {
                    throw Oops.Oh(" 上传文件不可超出500K");
                }
                //处理图形
                //  var FileData = Request.Form.Files[0];
                Image oimage = Image.FromStream(FileData.OpenReadStream());
                if (oimage == null)
                {
                    throw Oops.Oh(" 上传失败");
                }
                MemoryStream ms = new MemoryStream();
                if (oimage.Width > 600)
                {
                    if (oimage.Width > oimage.Height)
                        oimage.GetThumbnailImage(600, 400, null, IntPtr.Zero).Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                    else
                        oimage.GetThumbnailImage(400, 600, null, IntPtr.Zero).Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                }
                else
                    oimage.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                ms.Position = 0;
                var arr = ms.ToArray();
                string img64 = Convert.ToBase64String(arr);
                IDCardOCRResponse idcordinfo = null;
                string url = "";
                try
                {
                    idcordinfo = _tcs.IdCord(img64, PageName == "FRONT");
                    url = await UploadFilesFByBase64(_tcs.GetIdCordImg());
                    return ( idcordinfo, url );
                }
                catch (Exception e)
                {
                    throw Oops.Oh(e.Message);
                }
            }
            catch (Exception e)
            {
                throw Oops.Oh(e.Message);
            }
        }
        #endregion
cylsg/EzUpFile/EzUpFile.csproj
@@ -4,6 +4,7 @@
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <GenerateDocumentationFile>True</GenerateDocumentationFile>
  </PropertyGroup>
  <ItemGroup>
@@ -13,6 +14,7 @@
  <ItemGroup>
    <ProjectReference Include="..\cylsg.Core\cylsg.Core.csproj" />
    <ProjectReference Include="..\cylsg.utility\cylsg.utility.csproj" />
    <ProjectReference Include="..\EzTencentCloud\EzTencentCloud.csproj" />
  </ItemGroup>
  <ItemGroup>
cylsg/EzUpFile/IEzFileUploadService.cs
@@ -3,6 +3,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TencentCloud.Ocr.V20181119.Models;
namespace EzUpFile
{
@@ -26,5 +27,16 @@
        /// <returns></returns>
        Task<bool> DelFile(string Path);
        /// <summary>
        /// 上传身份证
        /// </summary>
        /// <param name="Path"></param>
        /// <returns></returns>
        Task<(IDCardOCRResponse, string)> UpIdCord(string PageName = "FRONT");
    }
}
cylsg/EzUpFile/UpFileController.cs
@@ -1,10 +1,15 @@
using Microsoft.AspNetCore.Http;
using EzTencentCloud;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.IdentityModel.Abstractions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TencentCloud.Ocr.V20181119.Models;
namespace EzUpFile
{
@@ -12,10 +17,31 @@
    /// 文件上传下载
    /// </summary>
    [DynamicApiController]
    [ApiDescriptionSettings("FileUpdata@0")]
    [ApiDescriptionSettings("FileUpdata")]
    public class UpFileController
    {
        /// <summary>
        /// 上传身份证信息
        /// </summary>
        /// <param name="PageName"> 身份证正反面 FRONT 正面  Back  国徽反面 </param>
        /// <returns></returns>
        [HttpPost]
        public async Task<(IDCardOCRResponse, string)> UploadIdCord([FromServices] IEzFileUploadService fileUploadService,IFormFile file, [FromQuery] string PageName = "FRONT")
        {
            return await fileUploadService.UpIdCord(PageName);
        }
        public async Task test([FromServices] ITencentCloudService fileUploadService)
        {
            fileUploadService.IaiCreatGroup();
        }
        /// <summary>
        /// 上传附件
        /// </summary>
cylsg/cylsg.Application/System/Services/SystemService.cs
@@ -4,6 +4,6 @@
{
    public string GetDescription()
    {
        return "川印招聘";
        return "川印招聘服务";
    }
}
cylsg/cylsg.Authorization/cylsg.Authorization.csproj
@@ -4,6 +4,7 @@
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <GenerateDocumentationFile>True</GenerateDocumentationFile>
  </PropertyGroup>
  <ItemGroup>
cylsg/cylsg.Model/UserModel/UserWorker.cs
@@ -78,5 +78,26 @@
        [SugarColumn(ColumnDescription = "提现余额", Length = 18, DecimalDigits = 2, IsNullable = true)]
        public decimal? TiXianYue { get; set; }
        /// <summary>
        /// 人脸ID
        /// </summary>
        [SugarColumn(ColumnDescription = "人脸ID", IsNullable = true)]
        public string? IAIPersonId { get; set; }
        /// <summary>
        /// 人脸库ID
        /// </summary>
        [SugarColumn(ColumnDescription = "人脸库ID", IsNullable = true)]
        public string? IAIGroupId { get; set; }
        /// <summary>
        /// 人脸库名称
        /// </summary>
        [SugarColumn(ColumnDescription = "人脸库名称", IsNullable = true)]
        public string? IAIGroupName { get; set; }
    }
}