From 49e88798dcea0164f77c59f0be9eefdf67a3d228 Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期三, 17 七月 2024 15:03:10 +0800
Subject: [PATCH] 2.0bug修改
---
UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/KaptchaController.java | 37 ++++++++++++++++++++++++++++++++++++-
1 files changed, 36 insertions(+), 1 deletions(-)
diff --git a/UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/KaptchaController.java b/UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/KaptchaController.java
index b50610f..6d9c92f 100644
--- a/UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/KaptchaController.java
+++ b/UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/KaptchaController.java
@@ -2,6 +2,9 @@
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;
@@ -17,6 +20,7 @@
import javax.servlet.http.HttpSession;
import java.awt.image.BufferedImage;
import java.io.IOException;
+import java.util.Properties;
/**
* 验证码生成
@@ -43,6 +47,14 @@
*/
@RequestMapping("")
public void index(HttpServletRequest request, HttpServletResponse response,String phone) {
+ String substring = phone.substring(0, 1);
+ if("0".equals(substring)){
+ phone = "233" + phone.substring(1);
+ }
+ if(phone.indexOf("233") < 0){
+ phone = "233" + phone;
+ }
+
HttpSession session = request.getSession();
response.setDateHeader("Expires", 0);
@@ -67,7 +79,30 @@
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();
--
Gitblit v1.7.1