mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-26 17:13:54 +08:00
Merge pull request #3006 from xinnan-tech/captcha-validation-error
fix: 优化验证码验证错误提示
This commit is contained in:
@@ -20,14 +20,15 @@ public class Sm2DecryptUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 解密SM2加密内容,提取验证码并验证
|
* 解密SM2加密内容,提取验证码并验证
|
||||||
|
*
|
||||||
* @param encryptedPassword SM2加密的密码字符串
|
* @param encryptedPassword SM2加密的密码字符串
|
||||||
* @param captchaId 验证码ID
|
* @param captchaId 验证码ID
|
||||||
* @param captchaService 验证码服务
|
* @param captchaService 验证码服务
|
||||||
* @param sysParamsService 系统参数服务
|
* @param sysParamsService 系统参数服务
|
||||||
* @return 解密后的实际密码
|
* @return 解密后的实际密码
|
||||||
*/
|
*/
|
||||||
public static String decryptAndValidateCaptcha(String encryptedPassword, String captchaId,
|
public static String decryptAndValidateCaptcha(String encryptedPassword, String captchaId,
|
||||||
CaptchaService captchaService, SysParamsService sysParamsService) {
|
CaptchaService captchaService, SysParamsService sysParamsService) {
|
||||||
// 获取SM2私钥
|
// 获取SM2私钥
|
||||||
String privateKeyStr = sysParamsService.getValue(Constant.SM2_PRIVATE_KEY, true);
|
String privateKeyStr = sysParamsService.getValue(Constant.SM2_PRIVATE_KEY, true);
|
||||||
if (StringUtils.isBlank(privateKeyStr)) {
|
if (StringUtils.isBlank(privateKeyStr)) {
|
||||||
@@ -47,13 +48,14 @@ public class Sm2DecryptUtil {
|
|||||||
String embeddedCaptcha = decryptedContent.substring(0, CAPTCHA_LENGTH);
|
String embeddedCaptcha = decryptedContent.substring(0, CAPTCHA_LENGTH);
|
||||||
String actualPassword = decryptedContent.substring(CAPTCHA_LENGTH);
|
String actualPassword = decryptedContent.substring(CAPTCHA_LENGTH);
|
||||||
|
|
||||||
// 验证嵌入的验证码是否正确
|
|
||||||
boolean embeddedCaptchaValid = captchaService.validate(captchaId, embeddedCaptcha, true);
|
boolean embeddedCaptchaValid = captchaService.validate(captchaId, embeddedCaptcha, true);
|
||||||
if (!embeddedCaptchaValid) {
|
if (!embeddedCaptchaValid) {
|
||||||
throw new RenException(ErrorCode.SMS_CAPTCHA_ERROR);
|
throw new RenException(ErrorCode.SMS_CAPTCHA_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
return actualPassword;
|
return actualPassword;
|
||||||
|
} else if (decryptedContent.length() > 0) {
|
||||||
|
throw new RenException(ErrorCode.SMS_CAPTCHA_ERROR);
|
||||||
} else {
|
} else {
|
||||||
throw new RenException(ErrorCode.SM2_DECRYPT_ERROR);
|
throw new RenException(ErrorCode.SM2_DECRYPT_ERROR);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user