-
Notifications
You must be signed in to change notification settings - Fork 837
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
更新V3.13.0版本:【新增】顶部菜单模式;【优化】因kaptcha有漏洞,弃用;【优化】三级等保默认值
- Loading branch information
zhuoda
committed
Jan 19, 2025
1 parent
96d498f
commit e74f179
Showing
35 changed files
with
1,510 additions
and
489 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,22 @@ | ||
package net.lab1024.sa.base.module.support.captcha; | ||
|
||
import com.google.code.kaptcha.impl.DefaultKaptcha; | ||
import cn.hutool.captcha.CaptchaUtil; | ||
import cn.hutool.captcha.LineCaptcha; | ||
import cn.hutool.core.img.ImgUtil; | ||
import cn.hutool.core.util.RandomUtil; | ||
import jakarta.annotation.Resource; | ||
import lombok.extern.slf4j.Slf4j; | ||
import net.lab1024.sa.base.common.constant.StringConst; | ||
import net.lab1024.sa.base.common.domain.ResponseDTO; | ||
import net.lab1024.sa.base.common.domain.SystemEnvironment; | ||
import net.lab1024.sa.base.common.exception.BusinessException; | ||
import net.lab1024.sa.base.constant.RedisKeyConst; | ||
import net.lab1024.sa.base.module.support.captcha.domain.CaptchaForm; | ||
import net.lab1024.sa.base.module.support.captcha.domain.CaptchaVO; | ||
import net.lab1024.sa.base.module.support.redis.RedisService; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.util.Base64Utils; | ||
|
||
import javax.imageio.ImageIO; | ||
import java.awt.image.BufferedImage; | ||
import java.io.ByteArrayOutputStream; | ||
import java.awt.*; | ||
import java.util.Objects; | ||
import java.util.UUID; | ||
|
||
|
@@ -29,7 +27,7 @@ | |
* @Date 2021/8/31 20:52 | ||
* @Wechat zhuoda1024 | ||
* @Email [email protected] | ||
* @Copyright <a href="https://1024lab.net">1024创新实验室</a> | ||
* @Copyright <a href="https://1024lab.net">1024创新实验室</a> | ||
*/ | ||
@Slf4j | ||
@Service | ||
|
@@ -40,9 +38,6 @@ public class CaptchaService { | |
*/ | ||
private static final long EXPIRE_SECOND = 65L; | ||
|
||
@Resource | ||
private DefaultKaptcha defaultKaptcha; | ||
|
||
@Resource | ||
private SystemEnvironment systemEnvironment; | ||
|
||
|
@@ -52,20 +47,23 @@ public class CaptchaService { | |
/** | ||
* 生成图形验证码 | ||
* 默认 1 分钟有效期 | ||
* | ||
*/ | ||
public CaptchaVO generateCaptcha() { | ||
String captchaText = defaultKaptcha.createText(); | ||
BufferedImage image = defaultKaptcha.createImage(captchaText); | ||
|
||
String base64Code; | ||
try (ByteArrayOutputStream os = new ByteArrayOutputStream()) { | ||
ImageIO.write(image, "jpg", os); | ||
base64Code = Base64Utils.encodeToString(os.toByteArray()); | ||
} catch (Exception e) { | ||
log.error("generateCaptcha error:", e); | ||
throw new BusinessException("生成验证码错误"); | ||
} | ||
|
||
//生成四位验证码 | ||
String captchaText = RandomUtil.randomNumbers(4); | ||
|
||
//定义图形验证码的长、宽、验证码位数、干扰线数量 | ||
LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(125, 43, 4, 80); | ||
|
||
//设置背景颜色 | ||
lineCaptcha.setBackground(new Color(230, 244, 255)); | ||
|
||
//生成图片 | ||
Image image = lineCaptcha.createImage(captchaText); | ||
|
||
//转为base64 | ||
String base64Code = ImgUtil.toBase64(image, "jpg"); | ||
|
||
/* | ||
* 返回验证码对象 | ||
|
@@ -88,7 +86,6 @@ public CaptchaVO generateCaptcha() { | |
|
||
/** | ||
* 校验图形验证码 | ||
* | ||
*/ | ||
public ResponseDTO<String> checkCaptcha(CaptchaForm captchaForm) { | ||
if (StringUtils.isBlank(captchaForm.getCaptchaUuid()) || StringUtils.isBlank(captchaForm.getCaptchaCode())) { | ||
|
38 changes: 0 additions & 38 deletions
38
...sa-base/src/main/java/net/lab1024/sa/base/module/support/captcha/config/CaptchaColor.java
This file was deleted.
Oops, something went wrong.
46 changes: 0 additions & 46 deletions
46
...a-base/src/main/java/net/lab1024/sa/base/module/support/captcha/config/CaptchaConfig.java
This file was deleted.
Oops, something went wrong.
44 changes: 0 additions & 44 deletions
44
...sa-base/src/main/java/net/lab1024/sa/base/module/support/captcha/config/CaptchaNoise.java
This file was deleted.
Oops, something went wrong.
74 changes: 0 additions & 74 deletions
74
.../src/main/java/net/lab1024/sa/base/module/support/captcha/config/CaptchaWordRenderer.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.