From 4c3ac42be64eae9c92d9b876b16312d5de46338e Mon Sep 17 00:00:00 2001 From: 移动系统liao <liaoxujun@qq.com> Date: 星期五, 16 八月 2024 14:16:49 +0800 Subject: [PATCH] 完成身份证上传验证接口,完成创建人脸库,创建人员库 --- cylsg/EzUpFile/EzFileUploadService.cs | 77 ++++++++++++ cylsg/EzUpFile/EzUpFile.csproj | 2 cylsg/EzTencentCloud/ITencentCloudService.cs | 6 + cylsg/cylsg.Application/System/Services/SystemService.cs | 2 cylsg/cylsg.Model/UserModel/UserWorker.cs | 21 +++ cylsg/EzTencentCloud/TencentCloudConfig.json | 10 + cylsg/EzUpFile/UpFileController.cs | 30 ++++ cylsg/cylsg.Authorization/cylsg.Authorization.csproj | 1 cylsg/EzTencentCloud/TencentCloudService.cs | 143 +++++++++++++++++++++++ cylsg/EzUpFile/IEzFileUploadService.cs | 12 ++ 10 files changed, 294 insertions(+), 10 deletions(-) diff --git a/cylsg/EzTencentCloud/ITencentCloudService.cs b/cylsg/EzTencentCloud/ITencentCloudService.cs index 8a43e16..338aef4 100644 --- a/cylsg/EzTencentCloud/ITencentCloudService.cs +++ b/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 + } } diff --git a/cylsg/EzTencentCloud/TencentCloudConfig.json b/cylsg/EzTencentCloud/TencentCloudConfig.json index e52425a..0623d8f 100644 --- a/cylsg/EzTencentCloud/TencentCloudConfig.json +++ b/cylsg/EzTencentCloud/TencentCloudConfig.json @@ -1,6 +1,12 @@ { "TencentCloud": { - "SecretId": "AKIDIPFp9CyThfMmvoQlpeCl34pKYVBahY9T", - "SecretKey": "4rNcaHhrkMhmb9QQ9bmgKipfFZcOt86n" + "SecretId": "AKIDIPFp9CyThfMmvoQlpeCl34pKYVBahY9T", + "SecretKey": "4rNcaHhrkMhmb9QQ9bmgKipfFZcOt86n" + }, + //浜鸿劯搴撶浉鍏抽厤缃� + "IAIGroupSet": { + "ID": "cylsg", + "Name": "宸濆嵃涓存椂宸�" } + } diff --git a/cylsg/EzTencentCloud/TencentCloudService.cs b/cylsg/EzTencentCloud/TencentCloudService.cs index 5d2919d..b192d1f 100644 --- a/cylsg/EzTencentCloud/TencentCloudService.cs +++ b/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> @@ -31,13 +45,14 @@ } - public IDCardOCRResponse IdCord(string ImageBase64, bool isFRONT) + public IDCardOCRResponse IdCord(string ImageBase64, bool isFRONT) { try { + Credential cred = new Credential { - SecretId = App.Configuration["TencentCloud:SecretId"] ??"AKIDIPFp9CyThfMmvoQlpeCl34pKYVBahY9T", + SecretId = App.Configuration["TencentCloud:SecretId"] ?? "AKIDIPFp9CyThfMmvoQlpeCl34pKYVBahY9T", SecretKey = App.Configuration["TencentCloud:SecretKey"] ?? "4rNcaHhrkMhmb9QQ9bmgKipfFZcOt86n" }; @@ -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 } diff --git a/cylsg/EzUpFile/EzFileUploadService.cs b/cylsg/EzUpFile/EzFileUploadService.cs index a10403d..de9639b 100644 --- a/cylsg/EzUpFile/EzFileUploadService.cs +++ b/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 diff --git a/cylsg/EzUpFile/EzUpFile.csproj b/cylsg/EzUpFile/EzUpFile.csproj index 7e6ce6a..d21d20d 100644 --- a/cylsg/EzUpFile/EzUpFile.csproj +++ b/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> diff --git a/cylsg/EzUpFile/IEzFileUploadService.cs b/cylsg/EzUpFile/IEzFileUploadService.cs index 3af7ecc..e135c0b 100644 --- a/cylsg/EzUpFile/IEzFileUploadService.cs +++ b/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"); + } + + + + } diff --git a/cylsg/EzUpFile/UpFileController.cs b/cylsg/EzUpFile/UpFileController.cs index a9b428c..a32f885 100644 --- a/cylsg/EzUpFile/UpFileController.cs +++ b/cylsg/EzUpFile/UpFileController.cs @@ -1,10 +1,15 @@ -锘縰sing Microsoft.AspNetCore.Http; +锘縰sing 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 姝i潰 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> diff --git a/cylsg/cylsg.Application/System/Services/SystemService.cs b/cylsg/cylsg.Application/System/Services/SystemService.cs index 13bd938..6c72041 100644 --- a/cylsg/cylsg.Application/System/Services/SystemService.cs +++ b/cylsg/cylsg.Application/System/Services/SystemService.cs @@ -4,6 +4,6 @@ { public string GetDescription() { - return "宸濆嵃鎷涜仒"; + return "宸濆嵃鎷涜仒鏈嶅姟"; } } diff --git a/cylsg/cylsg.Authorization/cylsg.Authorization.csproj b/cylsg/cylsg.Authorization/cylsg.Authorization.csproj index 7250e20..2704b18 100644 --- a/cylsg/cylsg.Authorization/cylsg.Authorization.csproj +++ b/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> diff --git a/cylsg/cylsg.Model/UserModel/UserWorker.cs b/cylsg/cylsg.Model/UserModel/UserWorker.cs index 4a3235d..6eba7b5 100644 --- a/cylsg/cylsg.Model/UserModel/UserWorker.cs +++ b/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> + /// 浜鸿劯搴揑D + /// </summary> + [SugarColumn(ColumnDescription = "浜鸿劯搴揑D", IsNullable = true)] + public string? IAIGroupId { get; set; } + + + /// <summary> + /// 浜鸿劯搴撳悕绉� + /// </summary> + [SugarColumn(ColumnDescription = "浜鸿劯搴撳悕绉�", IsNullable = true)] + public string? IAIGroupName { get; set; } + } } -- Gitblit v1.9.1