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 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 76 insertions(+), 1 deletions(-)

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
 
 

--
Gitblit v1.9.1