jinpengyong
2021-08-09 d6c509ab43bd472e56e3d9a9ddde0b335b7fd67e
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
package com.moral.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;
 
/**
 * @ClassName KaptchaConfig
 * @Description TODO
 * @Author 陈凯裕
 * @Date 2021/3/16 14:04
 * @Version TODO
 **/
@Configuration
public class KaptchaConfig {
 
    @Bean(name = "kaptchaProducer")
    public DefaultKaptcha getDefaultKaptcha(){
        DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
        Properties properties = new Properties();
        //设置边框
        properties.put("kaptcha.border", "no");
        //字体颜色
        properties.put("kaptcha.textproducer.font.color", "blue");
        //文字间隔
        properties.put("kaptcha.textproducer.char.space", "15");
        //验证码长度
        properties.put("kaptcha.textproducer.char.length","4");
        //图片高度
        properties.put("kaptcha.image.height","34");
        //文字尺寸
        properties.put("kaptcha.textproducer.font.size","25");
        //干扰实现类
        /*不使用干扰*/
        //properties.put("kaptcha.noise.impl","com.google.code.kaptcha.impl.NoNoise");
        /*使用默认干扰实现类*/
        properties.put("kaptcha.noise.impl","com.google.code.kaptcha.impl.DefaultNoise");
        //字体
        //properties.setProperty("kaptcha.textproducer.font.names", "宋体");
 
        Config config = new Config(properties);
        defaultKaptcha.setConfig(config);
        return defaultKaptcha;
    }
}