/**
 * Project Name:aiop-web File Name:MyCaptchaProducer.java Package Name:com.asiainfo.biapp.aiop.web.common
 * Date:2017年8月29日下午2:39:40 Copyright (c) 2017, chenzhou1025@126.com All Rights Reserved.
 *
 */

package com.ozs.account.config;

import java.util.Properties;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.google.code.kaptcha.Constants;
import com.google.code.kaptcha.impl.DefaultKaptcha;

/* *
 * @Description 配置验证码
**/
@Configuration
public class KaptchaProducer {

    @Bean(name = "defaultKaptcha")
    public DefaultKaptcha getMyCaptchaProducer() {
        Properties properties = new Properties();
        properties.setProperty("kaptcha.border", "no");
        properties.setProperty("kaptcha.textproducer.font.color", "43,111,213");
        properties.setProperty("kaptcha.image.width", "100");
        properties.setProperty("kaptcha.image.height", "40");
        properties.setProperty("kaptcha.textproducer.font.size", "30");
        properties.setProperty("kaptcha.textproducer.char.length", "4");
        //properties.setProperty("kaptcha.textproducer.font.names", "宋体,楷体,微软雅黑");
        // 此处需要注意服务器部署时字体问题
        properties.setProperty("kaptcha.textproducer.font.names", "DejaVu Sans");
        properties.setProperty("kaptcha.background.clear.from", "246,254,239");
        properties.setProperty("kaptcha.background.clear.to", "246,254,239");
        properties.setProperty(Constants.KAPTCHA_WORDRENDERER_IMPL,"com.google.code.kaptcha.text.impl.DefaultWordRenderer");
        properties.setProperty(Constants.KAPTCHA_NOISE_IMPL, "com.google.code.kaptcha.impl.NoNoise");
        properties.setProperty(Constants.KAPTCHA_TEXTPRODUCER_CHAR_STRING, "abcdef0123456789");
        properties.setProperty(Constants.KAPTCHA_TEXTPRODUCER_CHAR_SPACE, "3");

        com.google.code.kaptcha.util.Config config = new com.google.code.kaptcha.util.Config(properties);

        DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
        defaultKaptcha.setConfig(config);

        return defaultKaptcha;
    }

}

