From 0208c795499b808c762edbb3d61432410692dd6e Mon Sep 17 00:00:00 2001 From: chenhj <chenhj@lunor.cn> Date: 星期六, 24 五月 2025 14:50:15 +0800 Subject: [PATCH] Merge pull request 'chen' (#7) from chen into master --- ruoyi-framework/src/main/java/com/ruoyi/framework/config/CaptchaConfig.java | 83 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 83 insertions(+), 0 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 new file mode 100644 index 0000000..43e78ae --- /dev/null +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/CaptchaConfig.java @@ -0,0 +1,83 @@ +package com.ruoyi.framework.config; + +import java.util.Properties; +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.*; + +/** + * 楠岃瘉鐮侀厤缃� + * + * @author ruoyi + */ +@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; + } + + @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; + } +} -- Gitblit v1.9.3