# tianai-captcha-solon-plugin **Repository Path**: tianai/tianai-captcha-solon-plugin ## Basic Information - **Project Name**: tianai-captcha-solon-plugin - **Description**: tianai-captcha的solon脚手架插件 - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 3 - **Forks**: 1 - **Created**: 2024-09-03 - **Last Updated**: 2026-04-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ``` captcha: # Redis缓存key前缀,如果没实现Redis接口则使用内存 prefix: captcha # 验证码过期时间,默认是 2 分钟,单位毫秒, 可以根据自身业务进行调整 expire: 120000 limit: # 是否开启限流 enable: true # 每分钟请求次数 req-limit: 30 # 每分钟错误次数 error-limit: 10 secondary: # 二次验证, 默认false 不开启 enabled: true # 二次验证过期时间, 默认 2 分钟 expire: 120000 # 二次验证缓存key前缀,默认是 captcha:secondary keyPrefix: "captcha:secondary" # 资源配置 resources: # 自动添加资源到某个类型 auto: true autoType: SLIDER,WORD_IMAGE_CLICK,ROTATE,CONCAT images: - captcha/image/1.jpg - captcha/image/2.jpg - captcha/image/3.jpg # 如果设置了auto,以下就不生效 SLIDER: - captcha/image/1.jpg CONCAT: - captcha/image/1.jpg ROTATE: - captcha/image/1.jpg WORD_IMAGE_CLICK: - captcha/image/1.jpg ``` * 需要自己实现 CaptchaRedisCacheService 缓存器 * Solon版本已实现每分钟限流、错误次数限制,需自己捕获 ImageCaptchaException 异常,示例代码如下: ``` @Component(index = -101) public class GlobalPageInterceptor implements RouterInterceptor { @Override public void doIntercept(Context ctx, Handler mainHandler, RouterInterceptorChain chain){ try { if(mainHandler == null){ ctx.setHandled(true); ctx.outputAsJson(JSONUtil.toJsonStr(R.error("页面或接口不存在!"))); return; } chain.doIntercept(ctx, mainHandler); } catch (Throwable throwable) { ctx.status(500); Object message = switch (throwable) { case ValidatorException ignored -> R.error(throwable.getMessage()); case ImageCaptchaException ignored -> ApiResponse.ofError(ignored.getMessage()); default -> R.error("系统异常,请稍后再试!"); }; ctx.outputAsJson(JSONUtil.toJsonStr(message)); } } } ``` * 前端示例代码: ``` initTAC('/tac', config, style).then((tacApp: any) => { tacApp.config.requestChain[0].postRequest = (type, requestParam, res) => { if (res.code === 500) { // 这里换成自己的错误提示 // msg.error(res.msg) const loadingDom = document.getElementById('tianai-captcha-loading') nextTick(() => { loadingDom.style.display = 'block' setTimeout(() => { tacApp.destroyWindow(); }, 300) }) } } }) ```