package com.xcong.farmer.cms.modules.system.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;
|
|
@Configuration
|
public class KaptchaConfig {
|
@Bean
|
public DefaultKaptcha producer() {
|
//Properties类
|
Properties properties = new Properties();
|
// 图片边框
|
properties.setProperty("kaptcha.border", "no");
|
// 边框颜色
|
// properties.setProperty("kaptcha.border.color", "105,179,90");
|
// 字体颜色
|
properties.setProperty("kaptcha.textproducer.font.color", "black");
|
// 图片宽
|
properties.setProperty("kaptcha.image.width", "160");
|
// 图片高
|
properties.setProperty("kaptcha.image.height", "58");
|
// 文字间隔
|
properties.setProperty("kaptcha.textproducer.font.space", "5");
|
// 字体大小
|
properties.setProperty("kaptcha.textproducer.font.size", "38");
|
// session key
|
properties.setProperty("kaptcha.session.key", "code");
|
// 验证码长度
|
properties.setProperty("kaptcha.textproducer.char.length", "4");
|
// 字体
|
properties.setProperty("kaptcha.textproducer.font.names", "Arial, Courier");
|
//图片干扰
|
// properties.setProperty("kaptcha.noise.impl","com.google.code.kaptcha.impl.DefaultNoise");
|
//去除Kaptcha方法得到验证码的干扰线
|
properties.setProperty("kaptcha.noise.impl","com.google.code.kaptcha.impl.NoNoise");
|
//Kaptcha 使用上述配置
|
Config config = new Config(properties);
|
//DefaultKaptcha对象使用上述配置, 并返回这个Bean
|
DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
|
defaultKaptcha.setConfig(config);
|
return defaultKaptcha;
|
}
|
}
|