puzhibing
2023-08-03 7558a21c1ae1b48b0888f3e3906eb4ba6a68b06f
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,13 +47,13 @@
     */
    @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;
        }
//        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();
@@ -72,10 +76,33 @@
        // store the text in the session
        session.setAttribute(Constants.KAPTCHA_SESSION_KEY, capText);
        redisUtil.setStrValue(phone+"_Code",capText);
//        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();