worktile/src/main/java/com/nbclass/config/KaptchaConfig.java
2021-05-08 19:58:22 +08:00

35 lines
1.6 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.nbclass.config;
import java.util.Properties;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
/**
* kaptcha验证码参数配置
* @author Leon
* @datetime 2019年4月17日 上午10:23:09
*/
@Component
public class KaptchaConfig {
@Bean
public DefaultKaptcha getDefaultKaptcha(){
DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
Properties properties = new Properties();
properties.setProperty("kaptcha.border", "no"); // 图片边框合法值yes , no
properties.setProperty("kaptcha.border.color", "105,179,90"); // 边框颜色,合法值: r,g,b (and optional alpha) 或者 white,black,blue.
properties.setProperty("kaptcha.textproducer.font.color", "black"); // 字体颜色,合法值: r,g,b 或者 white,black,blue.
properties.setProperty("kaptcha.image.width", "125"); // 图片宽
properties.setProperty("kaptcha.image.height", "45"); // 图片高
properties.setProperty("kaptcha.textproducer.font.size", "35"); // 字体大小
properties.setProperty("kaptcha.textproducer.char.length", "4"); // 验证码长度
properties.setProperty("kaptcha.textproducer.font.names", "宋体,楷体,微软雅黑"); // 字体
properties.setProperty("kaptcha.noise.impl", "com.google.code.kaptcha.impl.NoNoise"); // 去除干扰线
Config config = new Config(properties);
defaultKaptcha.setConfig(config);
return defaultKaptcha;
}
}