From 2489c46a7ffe23a95da201a35c40424f2b79dba2 Mon Sep 17 00:00:00 2001
From: 602003139@qq.com <ljh2630734>
Date: 星期四, 21 十月 2021 14:44:53 +0800
Subject: [PATCH] 修复在swagger配置类中无法读取到satoken配置文件的问题

---
 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..3d4bc9e 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 final int width = 160;
+    private final int height = 60;
+    private final Color background = Color.PINK;
+    private 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