1. 修改加密附件验证码校验方法

This commit is contained in:
chenbowen
2025-09-12 12:47:50 +08:00
parent 45e2562111
commit 59339cf764
3 changed files with 14 additions and 3 deletions

View File

@@ -170,9 +170,9 @@ public class FileController {
@Operation(summary = "校验验证码") @Operation(summary = "校验验证码")
public CommonResult<String> verifyCode(@Valid @RequestParam Long fileId, @RequestParam String code) throws Exception { public CommonResult<String> verifyCode(@Valid @RequestParam Long fileId, @RequestParam String code) throws Exception {
Long userId = getLoginUserId(); Long userId = getLoginUserId();
byte[] content = fileService.verifyCodeAndGetFile(fileId, userId, code); boolean flag = fileService.verifyCode(fileId, userId, code);
if(content == null || content.length == 0){ if(!flag){
return CommonResult.customize(null, HttpStatus.INTERNAL_SERVER_ERROR.value(), "验证码校验失败"); return CommonResult.customize(null, HttpStatus.INTERNAL_SERVER_ERROR.value(), "验证码错误");
} }
return CommonResult.customize(null, HttpStatus.OK.value(), "验证码校验通过"); return CommonResult.customize(null, HttpStatus.OK.value(), "验证码校验通过");
} }

View File

@@ -102,4 +102,5 @@ public interface FileService {
*/ */
FileDO getActiveFileById(Long fileId); FileDO getActiveFileById(Long fileId);
boolean verifyCode(Long fileId, Long userId, String code) throws Exception;
} }

View File

@@ -289,5 +289,15 @@ public class FileServiceImpl implements FileService {
// 由于 FileDO 没有状态字段,直接查主键即为生效中的文件 // 由于 FileDO 没有状态字段,直接查主键即为生效中的文件
return fileMapper.selectById(fileId); return fileMapper.selectById(fileId);
} }
@Override
public boolean verifyCode(Long fileId, Long userId, String code) {
// 开发模式下,验证码直接获取配置进行比对
if (StringUtils.isNotEmpty(fixedVerifyCode)) {
return fixedVerifyCode.equals(code);
} else {
String codeKey = String.format(RedisKeyConstants.FILE_VERIFICATION_CODE, userId, fileId);
return VerificationCodeUtil.verifyCode(codeKey, code, stringRedisTemplate);
}
}
} }