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(); 
 | 
        // 是否有边框。默认true,可选:yes,no 
 | 
        properties.setProperty("kaptcha.border", "yes"); 
 | 
        //设置图片边框颜色 
 | 
        properties.setProperty("kaptcha.border.color", "green"); 
 | 
        // 验证码文本字符颜色。默认Color.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"); 
 | 
        // 图片样式。 
 | 
        // 水纹: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.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,可设置:yes,no 
 | 
        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"); 
 | 
        // 图片样式。 
 | 
        // 水纹: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.WaterRipple"); 
 | 
        // 返回生成的配置类 
 | 
        return properties; 
 | 
    } 
 | 
} 
 |