From 6982ea4c0a5550b3c88670df87539a91287b115d Mon Sep 17 00:00:00 2001 From: puzhibing <393733352@qq.com> Date: 星期四, 03 八月 2023 11:28:43 +0800 Subject: [PATCH] 修改bug --- DriverIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/KaptchaController.java | 28 +++++++++++++++++++++++++++- 1 files changed, 27 insertions(+), 1 deletions(-) diff --git a/DriverIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/KaptchaController.java b/DriverIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/KaptchaController.java index 59bab03..82e4d18 100644 --- a/DriverIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/KaptchaController.java +++ b/DriverIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/KaptchaController.java @@ -2,6 +2,8 @@ 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.stylefeng.guns.config.properties.GunsProperties; import com.stylefeng.guns.core.util.FileUtil; import org.springframework.beans.factory.annotation.Autowired; @@ -16,6 +18,7 @@ import javax.servlet.http.HttpSession; import java.awt.image.BufferedImage; import java.io.IOException; +import java.util.Properties; /** * 验证码生成 @@ -61,7 +64,30 @@ session.setAttribute(Constants.KAPTCHA_SESSION_KEY, 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(); -- Gitblit v1.7.1