Commit 620adf45 by 段启岩

添加短信发送太频繁提示

parent 5af56dc2
......@@ -9,5 +9,6 @@ public enum ParamType {
BLOG,
PROJECT,
QUESTION,
SMS_CODE,
SEARCH_KEYWORDS_TOPIC
}
......@@ -3,9 +3,13 @@ package cn.meteor.beyondclouds.modules.sms.api;
import cn.meteor.beyondclouds.core.annotation.Anonymous;
import cn.meteor.beyondclouds.core.api.Response;
import cn.meteor.beyondclouds.core.constant.RegexPatterns;
import cn.meteor.beyondclouds.core.flow.AccessInfo;
import cn.meteor.beyondclouds.core.flow.CollectAccessInfo;
import cn.meteor.beyondclouds.core.flow.ParamType;
import cn.meteor.beyondclouds.modules.sms.enums.SmsErrorCode;
import cn.meteor.beyondclouds.modules.sms.exception.SmsServiceException;
import cn.meteor.beyondclouds.modules.sms.service.ISmsService;
import cn.meteor.beyondclouds.util.AccessInfoUtils;
import cn.meteor.beyondclouds.util.VerifyCodeUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
......@@ -35,10 +39,19 @@ public class SmsApi {
@Anonymous
@ApiOperation("发送验证码")
@GetMapping("/verifyCode")
public Response sendVerify(@RequestParam("mobile") String mobile) {
public Response sendVerify(@RequestParam("mobile") String mobile,
@CollectAccessInfo(paramName = "mobile", type = ParamType.SMS_CODE) AccessInfo accessInfo) {
if (!mobile.matches(RegexPatterns.MOBILE)) {
return Response.error(SmsErrorCode.INVALID_MOBILE);
}
if (AccessInfoUtils.hasFieldInfo(accessInfo)) {
Integer count = accessInfo.getFieldVisitCount();
if (count > 2) {
return Response.error(SmsErrorCode.TOO_FREQUENT);
}
}
try {
smsService.sendVerifyCode(mobile, VerifyCodeUtils.randomVerifyCode());
return Response.success();
......
......@@ -10,7 +10,8 @@ public enum SmsErrorCode implements IErrorCode {
SERVER_ERROR(2001, "发送短信时阿里的服务器出现了异常"),
CLIENT_ERROR(2002, "发送短信时自己的服务器出现了异常"),
SEND_FAILURE(2004, "短信发送失败"),
INVALID_MOBILE(2005, "手机号格式错误");
INVALID_MOBILE(2005, "手机号格式错误"),
TOO_FREQUENT(2006, "短信发生太频繁");
private long code;
private String msg;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment