using FluentValidation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OASystem.Domain.Dtos.Tencent
{
///
/// TencentOCR ID证件识别
///
public class IDCardOCRDto:DtoBase
{
public int UserId { get; set; }
///
/// 语言
/// ch 中文
/// en 英文
///
public string Language { get; set; }
///
/// 图片的 Base64 值。要求图片经Base64编码后不超过 7M,分辨率建议500*800以上,支持PNG、JPG、JPEG、BMP格式。建议卡片部分占据图片2/3以上。
///
public string picBase64 { get; set; }
///
/// 0 FRONT:身份证有照片的一面(人像面)
/// 1 BACK:身份证有国徽的一面(国徽面)
/// 该参数如果不填,将为您自动判断身份证正反面。
///
public int CardSide { get; set; }
}
///
/// TencentOCR ID证件识别 DTO 验证
///
public class IDCardOCRDtoFoalidator : AbstractValidator
{
private readonly List _languages = new List() { "ch", "en" };
public IDCardOCRDtoFoalidator()
{
RuleFor(it => it.UserId)
.GreaterThan(0)
.WithMessage($"请传入有效的用户UserId值") ;
RuleFor(it => it.Language)
.NotNull()
.NotEmpty()
.WithMessage($"Language:参数值为空")
.Must(LanguageBeAllowedValue)
.WithMessage($"Language:无效值");
RuleFor(it => it.picBase64).NotNull().NotEmpty().WithMessage("picBase64为空");
RuleFor(it => it.picBase64).Must(base64 => OCRVerifyMethod.ImageSize(base64)).WithMessage("图片不能大于7M!");
RuleFor(it => it.picBase64).Must(base64 => OCRVerifyMethod.ImageType(base64)).WithMessage("图片格式不正确!只支持 PNG、JPG、JPEG、BMP格式的文件!");//
RuleFor(it => it.CardSide).InclusiveBetween(0, 1).WithMessage("CardSide(超出范围):0 人像面 1 国徽面");
}
private bool LanguageBeAllowedValue(string value)
{
return _languages.Contains(value.ToLower());
}
}
}