| | |
| | | |
| | | import com.google.code.kaptcha.Constants; |
| | | import com.google.code.kaptcha.Producer; |
| | | import com.google.code.kaptcha.impl.DefaultKaptcha; |
| | | import com.google.code.kaptcha.util.Config; |
| | | import com.google.code.kaptcha.util.Configurable; |
| | | import com.stylefeng.guns.config.properties.GunsProperties; |
| | | import com.stylefeng.guns.core.util.FileUtil; |
| | | import com.stylefeng.guns.modular.system.util.RedisUtil; |
| | |
| | | import javax.servlet.http.HttpSession; |
| | | import java.awt.image.BufferedImage; |
| | | import java.io.IOException; |
| | | import java.util.Properties; |
| | | |
| | | /** |
| | | * 验证码生成 |
| | |
| | | * @date 2017-05-05 23:10 |
| | | */ |
| | | @Controller |
| | | @RequestMapping("/kaptcha") |
| | | @RequestMapping("/base/kaptcha") |
| | | public class KaptchaController { |
| | | |
| | | @Autowired |
| | |
| | | redisUtil.setStrValue(phone+"_Code",capText); |
| | | |
| | | // create the image with the text |
| | | BufferedImage bi = producer.createImage(capText); |
| | | Properties properties = new Properties(); |
| | | // 设置边框 |
| | | properties.setProperty("kaptcha.border", "no"); |
| | | // 设置颜色 |
| | | properties.setProperty("kaptcha.border.color", "105,179,90"); |
| | | // 设置字体颜色 |
| | | properties.setProperty("kaptcha.textproducer.font.color", "blue"); |
| | | // 设置宽度 |
| | | properties.setProperty("kaptcha.image.width", "125"); |
| | | // 高度 |
| | | properties.setProperty("kaptcha.image.height", "42"); |
| | | // 设置session.key |
| | | properties.setProperty("kaptcha.session.key", "code"); |
| | | // 设置文本长度 |
| | | properties.setProperty("kaptcha.textproducer.char.length", "4"); |
| | | // 设置字体 |
| | | properties.setProperty("kaptcha.textproducer.font.names", "宋体,楷体,微软雅黑"); |
| | | //字体大小 |
| | | properties.setProperty("kaptcha.textproducer.font.size", "35"); |
| | | |
| | | Config config = new Config(properties); |
| | | DefaultKaptcha defaultKaptcha = new DefaultKaptcha(); |
| | | defaultKaptcha.setConfig(config); |
| | | BufferedImage bi = defaultKaptcha.createImage(capText); |
| | | ServletOutputStream out = null; |
| | | try { |
| | | out = response.getOutputStream(); |