修改每天次数

parent 9cde4e28
...@@ -45,6 +45,9 @@ public class SmsController implements IBaseController { ...@@ -45,6 +45,9 @@ public class SmsController implements IBaseController {
private static final String IMAGE_PHONE_COUNT = "image:phone"; private static final String IMAGE_PHONE_COUNT = "image:phone";
private static final String IMAGE_DEVICEID_COUNT = "image:deviceId:"; private static final String IMAGE_DEVICEID_COUNT = "image:deviceId:";
private static final Long IP_MAX_PER_DAY = 30L;
private static final Long PHONE_MAX_PER_DAY = 20L;
private static final Long DEVICE_MAX_PER_DAY = 20L;
/** /**
* 短信验证码: for H5 * 短信验证码: for H5
* 使用 @FPLock 注解并加入自定义限制参数, 做针对手机号的发送次数限制 * 使用 @FPLock 注解并加入自定义限制参数, 做针对手机号的发送次数限制
...@@ -220,14 +223,14 @@ public class SmsController implements IBaseController { ...@@ -220,14 +223,14 @@ public class SmsController implements IBaseController {
} }
String verificationPhoneCountKey = Constants.REDIS_SMS_CODE_COUNT + phoneNo; String verificationPhoneCountKey = Constants.REDIS_SMS_CODE_COUNT + phoneNo;
Long getPhoneVerificationCount = redisTemplate.opsForHash().increment(verificationPhoneCountKey, Constants.REDIS_SMS_CODE_COUNT, 1); Long getPhoneVerificationCount = redisTemplate.opsForHash().increment(verificationPhoneCountKey, Constants.REDIS_SMS_CODE_COUNT, 1);
if (getPhoneVerificationCount > 20) { if (getPhoneVerificationCount > PHONE_MAX_PER_DAY) {
return JsonResult.buildErrorStateResult("今天已获取20次短信验证码,请使用语音验证码或明天再试", null); return JsonResult.buildErrorStateResult("今天已获取20次短信验证码,请使用语音验证码或明天再试", null);
} }
String verificationIPCountKey = getIp(); String verificationIPCountKey = getIp();
if (!StringUtils.isEmpty(verificationIPCountKey)) { if (!StringUtils.isEmpty(verificationIPCountKey)) {
verificationIPCountKey=Constants.REDIS_SMS_IP_COUNT+verificationIPCountKey; verificationIPCountKey=Constants.REDIS_SMS_IP_COUNT+verificationIPCountKey;
Long getIPVerificationCount = redisTemplate.opsForHash().increment(verificationIPCountKey, Constants.REDIS_SMS_IP_COUNT, 1); Long getIPVerificationCount = redisTemplate.opsForHash().increment(verificationIPCountKey, Constants.REDIS_SMS_IP_COUNT, 1);
if (getIPVerificationCount > 5000) { if (getIPVerificationCount > IP_MAX_PER_DAY) {
return JsonResult.buildErrorStateResult("您当前ip已经达到获取今天验证码上限", null); return JsonResult.buildErrorStateResult("您当前ip已经达到获取今天验证码上限", null);
} }
} }
...@@ -235,7 +238,7 @@ public class SmsController implements IBaseController { ...@@ -235,7 +238,7 @@ public class SmsController implements IBaseController {
if (!StringUtils.isEmpty(deviceId)) { if (!StringUtils.isEmpty(deviceId)) {
String verificationDeviceCountKey = Constants.REDIS_SMS_DEVICE_COUNT + deviceId; String verificationDeviceCountKey = Constants.REDIS_SMS_DEVICE_COUNT + deviceId;
Long getDeviceVerificationCount = redisTemplate.opsForHash().increment(verificationDeviceCountKey, Constants.REDIS_SMS_DEVICE_COUNT, 1); Long getDeviceVerificationCount = redisTemplate.opsForHash().increment(verificationDeviceCountKey, Constants.REDIS_SMS_DEVICE_COUNT, 1);
if (getDeviceVerificationCount > 20) { if (getDeviceVerificationCount > DEVICE_MAX_PER_DAY) {
return JsonResult.buildErrorStateResult("您设备已经达到获取今天短信验证码上限", null); return JsonResult.buildErrorStateResult("您设备已经达到获取今天短信验证码上限", null);
} }
} }
...@@ -275,14 +278,14 @@ public class SmsController implements IBaseController { ...@@ -275,14 +278,14 @@ public class SmsController implements IBaseController {
String verificationCountKey = Constants.REDIS_VOICE_CODE_COUNT + phoneNo; String verificationCountKey = Constants.REDIS_VOICE_CODE_COUNT + phoneNo;
Long getVerificationCount = redisTemplate.opsForHash().increment(verificationCountKey, usage.toString(), 1); Long getVerificationCount = redisTemplate.opsForHash().increment(verificationCountKey, usage.toString(), 1);
if (getVerificationCount > 5) { if (getVerificationCount > PHONE_MAX_PER_DAY) {
return JsonResult.buildErrorStateResult("今天已获取5次语音验证码,请使用短信验证码或明天再试", null); return JsonResult.buildErrorStateResult("今天已获取5次语音验证码,请使用短信验证码或明天再试", null);
} }
String verificationIPCountKey = getIp(); String verificationIPCountKey = getIp();
if (!StringUtils.isEmpty(verificationIPCountKey)) { if (!StringUtils.isEmpty(verificationIPCountKey)) {
verificationIPCountKey=Constants.REDIS_VOICE_IP_COUNT+verificationIPCountKey; verificationIPCountKey=Constants.REDIS_VOICE_IP_COUNT+verificationIPCountKey;
Long getIPVerificationCount = redisTemplate.opsForHash().increment(verificationIPCountKey, Constants.REDIS_VOICE_IP_COUNT, 1); Long getIPVerificationCount = redisTemplate.opsForHash().increment(verificationIPCountKey, Constants.REDIS_VOICE_IP_COUNT, 1);
if (getIPVerificationCount > 5000) { if (getIPVerificationCount > IP_MAX_PER_DAY) {
return JsonResult.buildErrorStateResult("您当前ip已经达到获取今天语音验证码上限", null); return JsonResult.buildErrorStateResult("您当前ip已经达到获取今天语音验证码上限", null);
} }
} }
...@@ -290,7 +293,7 @@ public class SmsController implements IBaseController { ...@@ -290,7 +293,7 @@ public class SmsController implements IBaseController {
if (!StringUtils.isEmpty(deviceId)) { if (!StringUtils.isEmpty(deviceId)) {
String verificationDeviceCountKey = Constants.REDIS_SMS_DEVICE_COUNT + deviceId; String verificationDeviceCountKey = Constants.REDIS_SMS_DEVICE_COUNT + deviceId;
Long getDeviceVerificationCount = redisTemplate.opsForHash().increment(verificationDeviceCountKey, Constants.REDIS_VOICE_DEVICE_COUNT, 1); Long getDeviceVerificationCount = redisTemplate.opsForHash().increment(verificationDeviceCountKey, Constants.REDIS_VOICE_DEVICE_COUNT, 1);
if (getDeviceVerificationCount > 20) { if (getDeviceVerificationCount > DEVICE_MAX_PER_DAY) {
return JsonResult.buildErrorStateResult("您设备已经达到获取今天语音验证码上限", null); return JsonResult.buildErrorStateResult("您设备已经达到获取今天语音验证码上限", null);
} }
} }
......
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