From 7d44a17ac0a6039d332712acc91d7a972153a015 Mon Sep 17 00:00:00 2001 From: 移动系统liao <liaoxujun@qq.com> Date: 星期一, 19 八月 2024 14:12:19 +0800 Subject: [PATCH] no message --- cylsg/EzUpFile/EzFileUploadService.cs | 69 ++++++++++++++++++++++ cylsg/EzTencentCloud/ITencentCloudService.cs | 9 ++ cylsg/EzUpFile/UpFileController.cs | 14 ++++ cylsg/EzTencentCloud/TencentCloudService.cs | 39 +++++++++++++ cylsg/EzUpFile/IEzFileUploadService.cs | 9 ++ 5 files changed, 137 insertions(+), 3 deletions(-) diff --git a/cylsg/EzTencentCloud/ITencentCloudService.cs b/cylsg/EzTencentCloud/ITencentCloudService.cs index 338aef4..4cc0e0a 100644 --- a/cylsg/EzTencentCloud/ITencentCloudService.cs +++ b/cylsg/EzTencentCloud/ITencentCloudService.cs @@ -17,7 +17,7 @@ /// <summary> /// 韬唤璇佽瘑鍒紝骞跺壀瑁� /// </summary> - /// <param name="ImageBase64"></param> + /// <param name="ImageBase64">鍥剧墖base64</param> /// <param name="isFRONT"></param> /// <returns></returns> IDCardOCRResponse IdCord(string ImageBase64, bool isFRONT); @@ -26,9 +26,16 @@ /// </summary> /// <returns></returns> string GetIdCordImg(); + /// <summary> + /// 钀ヤ笟鎵х収璁よ瘉 + /// </summary> + /// <param name="ImageBase64"> 鍥剧墖base64</param> + /// <returns></returns> + BizLicenseOCRResponse BizLicenseOCR(string ImageBase64); #endregion #region iai 浜鸿劯璇嗗埆 public void IaiCreatGroup(); + #endregion } diff --git a/cylsg/EzTencentCloud/TencentCloudService.cs b/cylsg/EzTencentCloud/TencentCloudService.cs index b192d1f..aa364a0 100644 --- a/cylsg/EzTencentCloud/TencentCloudService.cs +++ b/cylsg/EzTencentCloud/TencentCloudService.cs @@ -117,6 +117,45 @@ } + + + + public BizLicenseOCRResponse BizLicenseOCR(string ImageBase64) + { + try + { + + 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 = ("ocr.tencentcloudapi.com"); + clientProfile.HttpProfile = httpProfile; + + var _ocrClient = new OcrClient(cred, "ap-chengdu", clientProfile); + + var ret = _ocrClient.BizLicenseOCRSync(new BizLicenseOCRRequest() + { + ImageBase64 = ImageBase64, + }); + + return ret; + } + catch (Exception) + { + throw; + } + + + } + + #endregion #region iai 浜鸿劯璇嗗埆 diff --git a/cylsg/EzUpFile/EzFileUploadService.cs b/cylsg/EzUpFile/EzFileUploadService.cs index de9639b..ea94781 100644 --- a/cylsg/EzUpFile/EzFileUploadService.cs +++ b/cylsg/EzUpFile/EzFileUploadService.cs @@ -14,6 +14,8 @@ using System.Globalization; using System.Security.Policy; using TencentCloud.Ocr.V20181119.Models; +using TencentCloud.Teo.V20220901.Models; +using Task = System.Threading.Tasks.Task; namespace EzUpFile { /// <summary> @@ -349,7 +351,72 @@ } - + public async Task<(BizLicenseOCRResponse, string)> UpBizLicense() + { + 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); + + BizLicenseOCRResponse info = null; + string url = ""; + + try + { + info = _tcs.BizLicenseOCR(img64); + + url = await UploadFilesFByBase64(img64); + + return (info, url); + + } + catch (Exception e) + { + + throw Oops.Oh(e.Message); + } + } + catch (Exception e) + { + + throw Oops.Oh(e.Message); + } + } + + #endregion diff --git a/cylsg/EzUpFile/IEzFileUploadService.cs b/cylsg/EzUpFile/IEzFileUploadService.cs index e135c0b..dae0969 100644 --- a/cylsg/EzUpFile/IEzFileUploadService.cs +++ b/cylsg/EzUpFile/IEzFileUploadService.cs @@ -33,7 +33,14 @@ /// <param name="Path"></param> /// <returns></returns> Task<(IDCardOCRResponse, string)> UpIdCord(string PageName = "FRONT"); - + + + /// <summary> + /// 涓婁紶钀ヤ笟鎵х収 + /// </summary> + /// <returns></returns> + Task<(BizLicenseOCRResponse, string)> UpBizLicense(); + } diff --git a/cylsg/EzUpFile/UpFileController.cs b/cylsg/EzUpFile/UpFileController.cs index a32f885..62d9d3a 100644 --- a/cylsg/EzUpFile/UpFileController.cs +++ b/cylsg/EzUpFile/UpFileController.cs @@ -35,6 +35,20 @@ return await fileUploadService.UpIdCord(PageName); } + + /// <summary> + /// 涓婁紶鍜岃瘑鍒惀涓氭墽鐓� + /// </summary> + /// <param name="PageName"> 韬唤璇佹鍙嶉潰 FRONT 姝i潰 Back 鍥藉窘鍙嶉潰 </param> + /// <returns></returns> + [HttpPost] + public async Task<(BizLicenseOCRResponse, string)> UpBizLicense([FromServices] IEzFileUploadService fileUploadService, IFormFile file) + { + + + return await fileUploadService.UpBizLicense(); + + } public async Task test([FromServices] ITencentCloudService fileUploadService) { -- Gitblit v1.9.1