Class CaptchaImageRenderer

java.lang.Object
com.sankcrm.erp.auth.infrastructure.captcha.CaptchaImageRenderer

@Component public class CaptchaImageRenderer extends Object
适配开源 easy-captcha 库生成六档图形验证码;档位只约定字符集与图片类型,不代表 OCR 难度评估结论。 答案只返回给受信挑战编排层,不得记录日志。
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    渲染结果仅供服务端挑战编排使用。答案以 SecretKey 类型供项目敏感 JSON 工具脱敏, 并使用 transient 字段且不提供 Bean getter,避免普通 JSON 输出答案明文;图片通过 Bean getter 输出。
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected Font
    中文验证码使用逻辑字体,由 Java 字体映射到系统已安装的中文字体。
    protected com.pig4cloud.captcha.base.Captcha
    createCaptcha(int level)
    创建指定档位的库内验证码实现,供测试替换异常或字体边界。
    protected InputStream
    openFontResource(String resourceName)
    打开验证码依赖包内的固定字体资源;资源缺失时由调用方保留异常并关闭服务。
    render(int level)
    按策略档位生成新的答案及 PNG 或 GIF data URL。
    protected int
    每个挑战只从固定白名单中的库内字体选择一种,避免逐字符混排导致字形不一致。

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • CaptchaImageRenderer

      public CaptchaImageRenderer()
  • Method Details

    • render

      public CaptchaImageRenderer.RenderedCaptcha render(int level)
      按策略档位生成新的答案及 PNG 或 GIF data URL。

      同一个短命实例先生成答案,再输出图片,确保两者对应同一挑战。

      Parameters:
      level - 验证码档位,取值 1 至 6
      Returns:
      配对的敏感答案与展示图片;调用方必须只保存答案摘要
      Throws:
      com.sankcrm.erp.common.exception.CoreRuntimeException - 档位无效、字体不可用或图片生成失败时以验证码服务不可用异常抛出
    • createCaptcha

      protected com.pig4cloud.captcha.base.Captcha createCaptcha(int level)
      创建指定档位的库内验证码实现,供测试替换异常或字体边界。
    • selectFontId

      protected int selectFontId()
      每个挑战只从固定白名单中的库内字体选择一种,避免逐字符混排导致字形不一致。
    • openFontResource

      protected InputStream openFontResource(String resourceName)
      打开验证码依赖包内的固定字体资源;资源缺失时由调用方保留异常并关闭服务。
    • chineseFont

      protected Font chineseFont()
      中文验证码使用逻辑字体,由 Java 字体映射到系统已安装的中文字体。