优化验证码模块相关代码,解决一个可能由于并发导致多发短信,或者多生成验证结果的情景。

This commit is contained in:
Chopper
2021-11-03 09:14:05 +08:00
parent af37386821
commit 956a6e465a
7 changed files with 20 additions and 32 deletions

View File

@@ -32,14 +32,8 @@ public class SliderImageController {
@GetMapping("/{verificationEnums}")
@ApiOperation(value = "获取校验接口,一分钟同一个ip请求10次")
public ResultMessage getSliderImage(@RequestHeader String uuid, @PathVariable VerificationEnums verificationEnums) {
try {
return ResultUtil.data(verificationService.createVerification(verificationEnums, uuid));
} catch (ServiceException e) {
throw e;
} catch (Exception e) {
log.error("获取校验接口错误", e);
throw new ServiceException(ResultCode.VERIFICATION_EXIST);
}
return ResultUtil.data(verificationService.createVerification(verificationEnums, uuid));
}
@LimitPoint(name = "slider_image", key = "verification_pre_check", limit = 600)

View File

@@ -42,11 +42,8 @@ public class SmsController {
@RequestHeader String uuid,
@PathVariable String mobile,
@PathVariable VerificationEnums verificationEnums) {
if (verificationService.check(uuid, verificationEnums)) {
smsUtil.sendSmsCode(mobile, verificationEnums, uuid);
return ResultUtil.success(ResultCode.VERIFICATION_SEND_SUCCESS);
} else {
throw new ServiceException(ResultCode.VERIFICATION_SMS_EXPIRED_ERROR);
}
verificationService.check(uuid, verificationEnums);
smsUtil.sendSmsCode(mobile, verificationEnums, uuid);
return ResultUtil.success(ResultCode.VERIFICATION_SEND_SUCCESS);
}
}