OCRDtoBase.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using FluentValidation;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace OASystem.Domain.Dtos.Tencent
  8. {
  9. /// <summary>
  10. /// OCR 继承基类
  11. /// </summary>
  12. public class OCRDtoBase
  13. {
  14. /// <summary>
  15. /// 图片转base64 字符串
  16. /// </summary>
  17. public string picBase64 { get; set; }
  18. /// <summary>
  19. /// 语种
  20. /// 1 中文
  21. /// 2 英文
  22. /// </summary>
  23. public int language { get; set; }
  24. }
  25. /// <summary>
  26. /// 验证
  27. /// </summary>
  28. public class OCRDtoBaseFoalidator : AbstractValidator<OCRDtoBase>
  29. {
  30. public OCRDtoBaseFoalidator()
  31. {
  32. RuleFor(it => it.picBase64)
  33. .NotEmpty()
  34. .NotNull()
  35. .WithMessage("picBase64为空");
  36. RuleFor(it => it.picBase64)
  37. .Must(base64 => OCRVerifyMethod.ImageSize(base64))
  38. .WithMessage("图片不能大于7M!");
  39. //RuleFor(it => it.picBase64)
  40. // .Must(base64 => OCRVerifyMethod.ImageType(base64))
  41. // .WithMessage("图片格式不正确!只支持 PNG、JPG、JPEG、BMP格式的文件!");
  42. RuleFor(it => it.language)
  43. .InclusiveBetween(1, 2)
  44. .WithMessage("language(超出范围):1 中文 2 英文");
  45. }
  46. }
  47. }