using YD_Event.Application.Common.Dtos; using CoreOcrService = YD_Event.Core.Infrastructure.Aliyun.Ocr.OcrService; using YD_Event.Core.Infrastructure.Aliyun.Ocr; namespace YD_Event.Application.Common; [ApiDescriptionSettings("通用服务")] public class OcrService : IDynamicApiController, ITransient { private readonly CoreOcrService _ocrService; public OcrService(CoreOcrService ocrService) { _ocrService = ocrService; } [HttpPost("recognize/idcard")] [DisplayName("OCR识别身份证")] public async Task RecognizeIdCard([FromBody] AthleteOcrInput input) { if (string.IsNullOrWhiteSpace(input.ImageUrl)) { throw Oops.Bah("图片URL不能为空"); } if (!input.ImageUrl.StartsWith("http://") && !input.ImageUrl.StartsWith("https://")) { throw Oops.Bah("请输入有效的图片URL地址"); } return await _ocrService.RecognizeIdCardAsync(input.ImageUrl); } [HttpPost("recognize/passport")] [DisplayName("OCR识别护照")] public async Task RecognizePassport([FromBody] AthleteOcrInput input) { if (string.IsNullOrWhiteSpace(input.ImageUrl)) { throw Oops.Bah("图片URL不能为空"); } if (!input.ImageUrl.StartsWith("http://") && !input.ImageUrl.StartsWith("https://")) { throw Oops.Bah("请输入有效的图片URL地址"); } return await _ocrService.RecognizePassportAsync(input.ImageUrl); } [HttpPost("recognize/household")] [DisplayName("OCR识别户口本")] public async Task RecognizeHousehold([FromBody] AthleteOcrInput input) { if (string.IsNullOrWhiteSpace(input.ImageUrl)) { throw Oops.Bah("图片URL不能为空"); } if (!input.ImageUrl.StartsWith("http://") && !input.ImageUrl.StartsWith("https://")) { throw Oops.Bah("请输入有效的图片URL地址"); } return await _ocrService.RecognizeHouseholdAsync(input.ImageUrl); } }