From f9d9eb2d70458839d292a5d34d18ddc79888f80e Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期四, 12 一月 2023 15:11:56 +0800 Subject: [PATCH] fix 修复 新版本 Redisson 存在与 boot 2.X 的兼容性问题 --- ruoyi-framework/src/main/java/com/ruoyi/framework/config/CaptchaConfig.java | 119 ++++++++++++++++++++++++----------------------------------- 1 files changed, 49 insertions(+), 70 deletions(-) diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/CaptchaConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/CaptchaConfig.java index 43e78ae..b284216 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/CaptchaConfig.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/CaptchaConfig.java @@ -1,83 +1,62 @@ package com.ruoyi.framework.config; -import java.util.Properties; +import cn.hutool.captcha.CaptchaUtil; +import cn.hutool.captcha.CircleCaptcha; +import cn.hutool.captcha.LineCaptcha; +import cn.hutool.captcha.ShearCaptcha; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import com.google.code.kaptcha.impl.DefaultKaptcha; -import com.google.code.kaptcha.util.Config; -import static com.google.code.kaptcha.Constants.*; +import org.springframework.context.annotation.Lazy; + +import java.awt.*; /** * 楠岃瘉鐮侀厤缃� - * - * @author ruoyi + * + * @author Lion Li */ @Configuration -public class CaptchaConfig -{ - @Bean(name = "captchaProducer") - public DefaultKaptcha getKaptchaBean() - { - DefaultKaptcha defaultKaptcha = new DefaultKaptcha(); - Properties properties = new Properties(); - // 鏄惁鏈夎竟妗� 榛樿涓簍rue 鎴戜滑鍙互鑷繁璁剧疆yes锛宯o - properties.setProperty(KAPTCHA_BORDER, "yes"); - // 楠岃瘉鐮佹枃鏈瓧绗﹂鑹� 榛樿涓篊olor.BLACK - properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_COLOR, "black"); - // 楠岃瘉鐮佸浘鐗囧搴� 榛樿涓�200 - properties.setProperty(KAPTCHA_IMAGE_WIDTH, "160"); - // 楠岃瘉鐮佸浘鐗囬珮搴� 榛樿涓�50 - properties.setProperty(KAPTCHA_IMAGE_HEIGHT, "60"); - // 楠岃瘉鐮佹枃鏈瓧绗﹀ぇ灏� 榛樿涓�40 - properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_SIZE, "38"); - // KAPTCHA_SESSION_KEY - properties.setProperty(KAPTCHA_SESSION_CONFIG_KEY, "kaptchaCode"); - // 楠岃瘉鐮佹枃鏈瓧绗﹂暱搴� 榛樿涓�5 - properties.setProperty(KAPTCHA_TEXTPRODUCER_CHAR_LENGTH, "4"); - // 楠岃瘉鐮佹枃鏈瓧浣撴牱寮� 榛樿涓簄ew Font("Arial", 1, fontSize), new Font("Courier", 1, fontSize) - properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_NAMES, "Arial,Courier"); - // 鍥剧墖鏍峰紡 姘寸汗com.google.code.kaptcha.impl.WaterRipple 楸肩溂com.google.code.kaptcha.impl.FishEyeGimpy 闃村奖com.google.code.kaptcha.impl.ShadowGimpy - properties.setProperty(KAPTCHA_OBSCURIFICATOR_IMPL, "com.google.code.kaptcha.impl.ShadowGimpy"); - Config config = new Config(properties); - defaultKaptcha.setConfig(config); - return defaultKaptcha; +public class CaptchaConfig { + + private static final int WIDTH = 160; + private static final int HEIGHT = 60; + private static final Color BACKGROUND = Color.PINK; + private static final Font FONT = new Font("Arial", Font.BOLD, 48); + + /** + * 鍦嗗湀骞叉壈楠岃瘉鐮� + */ + @Lazy + @Bean + public CircleCaptcha circleCaptcha() { + CircleCaptcha captcha = CaptchaUtil.createCircleCaptcha(WIDTH, HEIGHT); + captcha.setBackground(BACKGROUND); + captcha.setFont(FONT); + return captcha; } - @Bean(name = "captchaProducerMath") - public DefaultKaptcha getKaptchaBeanMath() - { - DefaultKaptcha defaultKaptcha = new DefaultKaptcha(); - Properties properties = new Properties(); - // 鏄惁鏈夎竟妗� 榛樿涓簍rue 鎴戜滑鍙互鑷繁璁剧疆yes锛宯o - properties.setProperty(KAPTCHA_BORDER, "yes"); - // 杈规棰滆壊 榛樿涓篊olor.BLACK - properties.setProperty(KAPTCHA_BORDER_COLOR, "105,179,90"); - // 楠岃瘉鐮佹枃鏈瓧绗﹂鑹� 榛樿涓篊olor.BLACK - properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_COLOR, "blue"); - // 楠岃瘉鐮佸浘鐗囧搴� 榛樿涓�200 - properties.setProperty(KAPTCHA_IMAGE_WIDTH, "160"); - // 楠岃瘉鐮佸浘鐗囬珮搴� 榛樿涓�50 - properties.setProperty(KAPTCHA_IMAGE_HEIGHT, "60"); - // 楠岃瘉鐮佹枃鏈瓧绗﹀ぇ灏� 榛樿涓�40 - properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_SIZE, "35"); - // KAPTCHA_SESSION_KEY - properties.setProperty(KAPTCHA_SESSION_CONFIG_KEY, "kaptchaCodeMath"); - // 楠岃瘉鐮佹枃鏈敓鎴愬櫒 - properties.setProperty(KAPTCHA_TEXTPRODUCER_IMPL, "com.ruoyi.framework.config.KaptchaTextCreator"); - // 楠岃瘉鐮佹枃鏈瓧绗﹂棿璺� 榛樿涓�2 - properties.setProperty(KAPTCHA_TEXTPRODUCER_CHAR_SPACE, "3"); - // 楠岃瘉鐮佹枃鏈瓧绗﹂暱搴� 榛樿涓�5 - properties.setProperty(KAPTCHA_TEXTPRODUCER_CHAR_LENGTH, "6"); - // 楠岃瘉鐮佹枃鏈瓧浣撴牱寮� 榛樿涓簄ew Font("Arial", 1, fontSize), new Font("Courier", 1, fontSize) - properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_NAMES, "Arial,Courier"); - // 楠岃瘉鐮佸櫔鐐归鑹� 榛樿涓篊olor.BLACK - properties.setProperty(KAPTCHA_NOISE_COLOR, "white"); - // 骞叉壈瀹炵幇绫� - properties.setProperty(KAPTCHA_NOISE_IMPL, "com.google.code.kaptcha.impl.NoNoise"); - // 鍥剧墖鏍峰紡 姘寸汗com.google.code.kaptcha.impl.WaterRipple 楸肩溂com.google.code.kaptcha.impl.FishEyeGimpy 闃村奖com.google.code.kaptcha.impl.ShadowGimpy - properties.setProperty(KAPTCHA_OBSCURIFICATOR_IMPL, "com.google.code.kaptcha.impl.ShadowGimpy"); - Config config = new Config(properties); - defaultKaptcha.setConfig(config); - return defaultKaptcha; + /** + * 绾挎骞叉壈鐨勯獙璇佺爜 + */ + @Lazy + @Bean + public LineCaptcha lineCaptcha() { + LineCaptcha captcha = CaptchaUtil.createLineCaptcha(WIDTH, HEIGHT); + captcha.setBackground(BACKGROUND); + captcha.setFont(FONT); + return captcha; } + + /** + * 鎵洸骞叉壈楠岃瘉鐮� + */ + @Lazy + @Bean + public ShearCaptcha shearCaptcha() { + ShearCaptcha captcha = CaptchaUtil.createShearCaptcha(WIDTH, HEIGHT); + captcha.setBackground(BACKGROUND); + captcha.setFont(FONT); + return captcha; + } + } -- Gitblit v1.9.3