From 1e3eeec2d3a470d066d21900586b912dfef58c91 Mon Sep 17 00:00:00 2001
From: zhubaomin <zhubaomin>
Date: 星期四, 17 四月 2025 15:07:41 +0800
Subject: [PATCH] 优化代码

---
 pipIrr-platform/pipIrr-web/pipIrr-web-app/src/main/java/com/dy/pipIrrApp/config/KaptchaConfig.java |  126 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 126 insertions(+), 0 deletions(-)

diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-app/src/main/java/com/dy/pipIrrApp/config/KaptchaConfig.java b/pipIrr-platform/pipIrr-web/pipIrr-web-app/src/main/java/com/dy/pipIrrApp/config/KaptchaConfig.java
new file mode 100644
index 0000000..e4fa6c5
--- /dev/null
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-app/src/main/java/com/dy/pipIrrApp/config/KaptchaConfig.java
@@ -0,0 +1,126 @@
+package com.dy.pipIrrApp.config;
+
+import com.google.code.kaptcha.impl.DefaultKaptcha;
+import com.google.code.kaptcha.util.Config;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import java.util.Properties;
+
+/**
+ * @author ZhuBaoMin
+ * @date 2024-09-11 15:52
+ * @LastEditTime 2024-09-11 15:52
+ * @Description
+ */
+
+@Configuration
+public class KaptchaConfig {
+    /**
+     * 楠岃瘉鐮侀厤缃粯璁ら厤缃�
+     * @return
+     */
+    @Bean(name = "captchaProducer")
+    public DefaultKaptcha getKaptchaBean() {
+        DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
+        Properties properties = new Properties();
+        // 鏄惁鏈夎竟妗嗐�傞粯璁rue锛屽彲閫夛細yes锛宯o
+        properties.setProperty("kaptcha.border", "yes");
+        //璁剧疆鍥剧墖杈规棰滆壊
+        properties.setProperty("kaptcha.border.color", "green");
+        // 楠岃瘉鐮佹枃鏈瓧绗﹂鑹层�傞粯璁olor.BLACK
+        properties.setProperty("kaptcha.textproducer.font.color", "black");
+        // 鏂囧瓧闂撮殧
+        properties.put("kaptcha.textproducer.char.space", "10");
+        // 楠岃瘉鐮佸浘鐗囧搴︺�傞粯璁�200
+        properties.setProperty("kaptcha.image.width", "160");
+        // 楠岃瘉鐮佸浘鐗囬珮搴︺�傞粯璁�50
+        properties.setProperty("Kkaptcha.image.height", "60");
+        // 楠岃瘉鐮佹枃鏈瓧绗﹀ぇ灏忋�傞粯璁�40
+        properties.setProperty("kaptcha.textproducer.font.size", "38");
+        // KAPTCHA_SESSION_KEY
+        properties.setProperty("Kkaptcha.session.key", "kaptchaCode");
+        // 楠岃瘉鐮佹枃鏈瓧绗﹂暱搴︺�傞粯璁�5
+        properties.setProperty("kaptcha.textproducer.char.length", "4");
+        // 楠岃瘉鐮佹枃鏈瓧浣撴牱寮忋�傞粯璁わ細new Font("Arial", 1, fontSize), new Font("Courier", 1, fontSize)
+        properties.setProperty("kaptcha.textproducer.font.names", "Arial,Courier");
+        // 骞叉壈瀹炵幇绫�
+        properties.setProperty("kaptcha.noise.impl", "com.google.code.kaptcha.impl.NoNoise");
+        // 鍥剧墖鏍峰紡銆�
+        // 姘寸汗锛歝om.google.code.kaptcha.impl.WaterRipple
+        // 楸肩溂锛歝om.google.code.kaptcha.impl.FishEyeGimpy
+        // 闃村奖锛歝om.google.code.kaptcha.impl.ShadowGimpy
+        properties.setProperty("kaptcha.obscurificator.impl", "com.google.code.kaptcha.impl.WaterRipple");
+        Config config = new Config(properties);
+        defaultKaptcha.setConfig(config);
+        return defaultKaptcha;
+    }
+
+    /**
+     * 楠岃瘉鐮佹暟瀛﹂绫婚厤缃紙涓�浣嶆暟鍔犲噺涔橀櫎锛�
+     * @return 閰嶇疆淇℃伅
+     */
+    @Bean(name = "captchaProducerMathOne")
+    public DefaultKaptcha getKaptchaBeanMathOne() {
+        DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
+        Properties properties = commonConfig("com.dy.pipIrrApp.config.KaptchaMathOneTextCreator");
+        Config config = new Config(properties);
+        defaultKaptcha.setConfig(config);
+        return defaultKaptcha;
+    }
+
+    /**
+     * 楠岃瘉鐮佹暟瀛﹂绫婚厤缃紙涓や綅鏁扮殑鍔犲噺涔橀櫎锛�
+     * @return 閰嶇疆淇℃伅
+     */
+    @Bean(name = "captchaProducerMathTwo")
+    public DefaultKaptcha getKaptchaBeanMathTwo() {
+        DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
+        Properties properties = commonConfig("com.dy.pipIrrApp.config.KaptchaMathTwoTextCreator");
+        Config config = new Config(properties);
+        defaultKaptcha.setConfig(config);
+        return defaultKaptcha;
+    }
+
+    /**
+     * 绠楀紡杩愮畻閰嶇疆鐨勫叕鍏遍厤缃被
+     * @param textImpl 楠岃瘉鐮佹枃鏈敓鎴愬櫒
+     * @return 閰嶇疆绫�
+     */
+    protected static Properties commonConfig(String textImpl) {
+        Properties properties = new Properties();
+        // 鏄惁鏈夎竟妗嗐�傞粯璁や负true锛屽彲璁剧疆锛歽es锛宯o
+        properties.setProperty("kaptcha.border", "yes");
+        // 杈规棰滆壊銆傞粯璁わ細Color.BLACK
+        properties.setProperty("kaptcha.border.color", "105,179,90");
+        // 楠岃瘉鐮佹枃鏈瓧绗﹂鑹层�傞粯璁わ細Color.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.key", "kaptchaCodeMath");
+        // 楠岃瘉鐮佹枃鏈敓鎴愬櫒
+        properties.setProperty("kaptcha.textproducer.impl", textImpl);
+        // 楠岃瘉鐮佹枃鏈瓧绗﹂棿璺濄�傞粯璁わ細2
+        properties.setProperty("kaptcha.textproducer.char.space", "6");
+        // 楠岃瘉鐮佹枃鏈瓧绗﹂暱搴︺�傞粯璁わ細5
+        properties.setProperty("kaptcha.textproducer.char.length", "6");
+        // 楠岃瘉鐮佹枃鏈瓧浣撴牱寮忋�傞粯璁わ細new Font("Arial", 1, fontSize), new Font("Courier", 1, fontSize)
+        properties.setProperty("kaptcha.textproducer.font.names", "Arial,Courier");
+        // 楠岃瘉鐮佸櫔鐐归鑹层�傞粯璁わ細Color.BLACK
+        properties.setProperty("kaptcha.noise.color", "white");
+        // 骞叉壈瀹炵幇绫�
+        properties.setProperty("kaptcha.noise.impl", "com.google.code.kaptcha.impl.NoNoise");
+        // 鍥剧墖鏍峰紡銆�
+        // 姘寸汗锛歝om.google.code.kaptcha.impl.WaterRipple
+        // 楸肩溂锛歝om.google.code.kaptcha.impl.FishEyeGimpy
+        // 闃村奖锛歝om.google.code.kaptcha.impl.ShadowGimpy
+        properties.setProperty("kaptcha.obscurificator.impl", "com.google.code.kaptcha.impl.WaterRipple");
+        // 杩斿洖鐢熸垚鐨勯厤缃被
+        return properties;
+    }
+}

--
Gitblit v1.8.0