1
zj
2024-12-30 665c763cb07deb261cf4fa62c6eb574aec1d816a
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package com.nq.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 GoogleCodeConfig {
    //  <!-- 配置驗證碼 -->
    //    <bean id="captchaProducer" class="com.google.code.kaptcha.impl.DefaultKaptcha">
    //        <property name="config">
    //            <bean class="com.google.code.kaptcha.util.Config">
    //                <constructor-arg>
    //                    <props> <!-- 圖片邊框 -->
    //                        <prop key="kaptcha.border">no</prop>
    //                        <!-- 圖片寬度 -->
    //                        <prop key="kaptcha.image.width">100</prop>
    //                        <!-- 圖片高度 -->
    //                        <prop key="kaptcha.image.height">45</prop>
    //                        <!-- 驗證碼背景顏色漸變,開始顏色 -->
    //                        <!--<prop key="kaptcha.background.clear.from">248,248,248</prop>-->
    //                        <!-- 驗證碼背景顏色漸變,結束顏色 -->
    //                        <!--<prop key="kaptcha.background.clear.to">248,248,248</prop>-->
    //                        <!-- 驗證碼的字符 -->
    //                        <prop key="kaptcha.textproducer.char.string">0123456789abcdefg</prop>
    //                        <!-- 驗證碼字體顏色 -->
    //                        <prop key="kaptcha.textproducer.font.color">red</prop>
    //                        <!-- 驗證碼的效果,水紋 -->
    //                        <!--<prop key="kaptcha.obscurificator.impl">com.google.code.kaptcha.impl.WaterRipple</prop>-->
    //                        <!-- 驗證碼字體大小 -->
    //                        <prop key="kaptcha.textproducer.font.size">33</prop>
    //                        <!-- 驗證碼字數 -->
    //                        <prop key="kaptcha.textproducer.char.length">4</prop>
    //                        <!-- 驗證碼文字間距 -->
    //                        <prop key="kaptcha.textproducer.char.space">5</prop>
    //                        <!-- 驗證碼字體 -->
    //                        <prop key="kaptcha.textproducer.font.names">
    //                            宋體,楷體,微軟雅黑
    //                        </prop>
    //                        <!-- 不加噪聲 -->
    //                        <prop key="kaptcha.noise.impl">com.google.code.kaptcha.impl.NoNoise</prop>
    //                    </props>
    //                </constructor-arg>
    //            </bean>
    //        </property>
    //    </bean>
    @Bean
    public DefaultKaptcha captchaProducer() {
 
        DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
        Properties properties = new Properties();
        properties.setProperty("kaptcha.border", "no");
        properties.setProperty("kaptcha.image.width", "100");
        properties.setProperty("kaptcha.image.height", "45");
        properties.setProperty("kaptcha.textproducer.char.string", "0123456789abcdefg");
        properties.setProperty("kaptcha.textproducer.font.color", "red");
        properties.setProperty("kaptcha.textproducer.font.size", "33");
        properties.setProperty("kaptcha.textproducer.char.length", "4");
        properties.setProperty("kaptcha.textproducer.char.space", "5");
        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;
    }
}