@@ -170,9 +170,9 @@ public class FileController {
|
||||
@Operation(summary = "校验验证码")
|
||||
public CommonResult<String> verifyCode(@Valid @RequestParam Long fileId, @RequestParam String code) throws Exception {
|
||||
Long userId = getLoginUserId();
|
||||
byte[] content = fileService.verifyCodeAndGetFile(fileId, userId, code);
|
||||
if(content == null || content.length == 0){
|
||||
return CommonResult.customize(null, HttpStatus.INTERNAL_SERVER_ERROR.value(), "验证码校验失败");
|
||||
boolean flag = fileService.verifyCode(fileId, userId, code);
|
||||
if(!flag){
|
||||
return CommonResult.customize(null, HttpStatus.INTERNAL_SERVER_ERROR.value(), "验证码错误");
|
||||
}
|
||||
return CommonResult.customize(null, HttpStatus.OK.value(), "验证码校验通过");
|
||||
}
|
||||
|
||||
@@ -102,4 +102,5 @@ public interface FileService {
|
||||
*/
|
||||
FileDO getActiveFileById(Long fileId);
|
||||
|
||||
boolean verifyCode(Long fileId, Long userId, String code) throws Exception;
|
||||
}
|
||||
|
||||
@@ -289,5 +289,15 @@ public class FileServiceImpl implements FileService {
|
||||
// 由于 FileDO 没有状态字段,直接查主键即为生效中的文件
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user