增加企业执照文件,身份证文件验证上传,增加人脸特征上传
| | |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using TencentCloud.Iai.V20200303.Models; |
| | | using TencentCloud.Ocr.V20181119.Models; |
| | | |
| | | namespace EzTencentCloud |
| | |
| | | BizLicenseOCRResponse BizLicenseOCR(string ImageBase64); |
| | | #endregion |
| | | #region iai 人脸识别 |
| | | /// <summary> |
| | | /// 创建人脸库,一般一个云账号只需要创建一次 |
| | | /// </summary> |
| | | public void IaiCreatGroup(); |
| | | /// <summary> |
| | | /// 人脸验证 一般分数超过50 分识别为一个人 |
| | | /// </summary> |
| | | /// <param name="img64"></param> |
| | | /// <param name="PersonNameId"></param> |
| | | /// <returns></returns> |
| | | public VerifyFaceResponse VerifyFace(string img64, string PersonNameId); |
| | | /// <summary> |
| | | /// 增加一个人的人脸图片特征,一个最多只允许有五个人脸特这 |
| | | /// </summary> |
| | | /// <param name="img64"></param> |
| | | /// <param name="PersonNameId"></param> |
| | | /// <param name="PersonName"></param> |
| | | /// <param name="PersonGender"></param> |
| | | /// <returns></returns> |
| | | public bool IaiAddPersoImg(string img64, string PersonNameId, string PersonName, int PersonGender); |
| | | |
| | | /// <summary> |
| | | /// 增加一个人 |
| | | /// </summary> |
| | | /// <param name="img64">人脸照</param> |
| | | /// <param name="PersonNameId">人脸ID 一个云账户中唯一</param> |
| | | /// <param name="PersonName">姓名</param> |
| | | /// <param name="PersonGender">性别 0代表未填写,1代表男性,2代表女性。</param> |
| | | /// <returns></returns> |
| | | public bool IaiAddPerso(string img64, string PersonNameId, string PersonName, int PersonGender); |
| | | #endregion |
| | | |
| | | } |
| | |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | public VerifyFaceResponse VerifyFace(string img64, string PersonNameId) |
| | | { |
| | | 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.VerifyFaceSync(new TencentCloud.Iai.V20200303.Models.VerifyFaceRequest |
| | | { |
| | | |
| | | PersonId = PersonNameId, |
| | | Image= img64 |
| | | |
| | | |
| | | |
| | | }); |
| | | return ret; |
| | | |
| | | |
| | | |
| | | } |
| | | #endregion |
| | | |
| | | } |
| | |
| | | |
| | | } |
| | | |
| | | public async Task<(IDCardOCRResponse,string)> UpIdCord( string PageName = "FRONT") |
| | | |
| | | |
| | | |
| | | #endregion |
| | | |
| | | #region 识别上传 |
| | | public async Task<(IDCardOCRResponse, string)> UpIdCord(string PageName = "FRONT") |
| | | { |
| | | try |
| | | { |
| | |
| | | |
| | | url = await UploadFilesFByBase64(_tcs.GetIdCordImg()); |
| | | |
| | | return ( idcordinfo, url ); |
| | | return (idcordinfo, url); |
| | | |
| | | } |
| | | catch (Exception e) |
| | |
| | | } |
| | | |
| | | |
| | | public async Task<(bool,string)> IaiAddPerso(string CoredID,string Name,int PersonGender) |
| | | { |
| | | 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); |
| | | |
| | | bool info = false; |
| | | string url = ""; |
| | | |
| | | try |
| | | { |
| | | info = _tcs.IaiAddPerso(img64, CoredID, Name, PersonGender); |
| | | |
| | | url = await UploadFilesFByBase64(img64); |
| | | |
| | | return (info, url); |
| | | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | |
| | | throw Oops.Oh(e.Message); |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | |
| | | throw Oops.Oh(e.Message); |
| | | } |
| | | } |
| | | |
| | | |
| | | #endregion |
| | | |
| | | |
| | | } |
| | | } |
| | |
| | | /// <returns></returns> |
| | | Task<(BizLicenseOCRResponse, string)> UpBizLicense(); |
| | | |
| | | /// <summary> |
| | | /// 创建人脸特征 |
| | | /// </summary> |
| | | /// <param name="CoredID"> 身份证号</param> |
| | | /// <param name="Name">姓名</param> |
| | | /// <param name="PersonGender"> 性别 0代表未填写,1代表男性,2代表女性。</param> |
| | | /// <returns></returns> |
| | | Task<(bool, string)> IaiAddPerso(string CoredID, string Name, int PersonGender); |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | return await fileUploadService.UpBizLicense(); |
| | | |
| | | } |
| | | /// <summary> |
| | | /// 增加人脸特征 |
| | | /// </summary> |
| | | /// <param name="CordId">身份证号</param> |
| | | /// <param name="Name">名称</param> |
| | | /// <param name="Gender">0代表未填写,1代表男性,2代表女性。</param> |
| | | /// <returns></returns> |
| | | [HttpPost] |
| | | public async Task<(bool , string)> IaiAddPerso([FromServices] IEzFileUploadService fileUploadService, IFormFile file,[FromQuery] string CordId, [FromQuery] string Name, [FromQuery] int Gender) |
| | | { |
| | | |
| | | |
| | | return await fileUploadService.IaiAddPerso(CordId, Name,Gender); |
| | | |
| | | |
| | | } |
| | | public async Task test([FromServices] ITencentCloudService fileUploadService) |
| | | { |
| | | |
| | |
| | | [SugarColumn(ColumnDescription = "人脸库名称", IsNullable = true)] |
| | | public string? IAIGroupName { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 性别 0代表未填写,1代表男性,2代表女性。 |
| | | /// </summary> |
| | | [SugarColumn(ColumnDescription = "人脸库名称", IsNullable = true)] |
| | | public long? Gender { get; set; } = 0; |
| | | |
| | | } |
| | | } |