2026-03-30 20:47:40 +08:00
|
|
|
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<IdCardRecognitionResult> 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<PassportRecognitionResult> 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);
|
|
|
|
|
}
|
2026-06-15 21:51:42 +08:00
|
|
|
|
|
|
|
|
[HttpPost("recognize/household")]
|
|
|
|
|
[DisplayName("OCR识别户口本")]
|
|
|
|
|
public async Task<HouseholdRecognitionResult> 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);
|
|
|
|
|
}
|
2026-03-30 20:47:40 +08:00
|
|
|
}
|