KaptchaConfig.java
1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.thinkgem.jeesite.common.kaptchaConfig;
/**
* @author
* @time 2019-10-22 15:02
*/
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 hqk
*/
@Configuration
public class KaptchaConfig {
@Bean
public DefaultKaptcha producer() {
Properties properties = new Properties();
//图片边框
properties.put("kaptcha.border", "yes");
//字体颜色
properties.put("kaptcha.textproducer.font.color", "black");
//验证码长度
properties.put("kaptcha.textproducer.char.space", "5");
// 图片高
properties.setProperty("kaptcha.image.height", "30");
// 图片宽
properties.setProperty("kaptcha.image.width", "110");
//
properties.setProperty("kaptcha.textproducer.font.size", "25");
//如果需要生成算法验证码加上一下配置
properties.put("kaptcha.textproducer.char.string", "1234567890");
// session key
properties.setProperty("kaptcha.session.key", "code");
//如果需要去掉干扰线
properties.put("kaptcha.noise.impl", "com.google.code.kaptcha.impl.NoNoise");
Config config = new Config(properties);
DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
defaultKaptcha.setConfig(config);
return defaultKaptcha;
}
}