Commit bc5d1a76 authored by 技术部-任文超's avatar 技术部-任文超

优化改进:短信验证码计数器/账密计数器 的生命期,从每次递增24小时 --变更未-->当日有效(自然日)

parent 3d2a4744
...@@ -45,7 +45,6 @@ public interface Constants { ...@@ -45,7 +45,6 @@ public interface Constants {
* redis中token的key值前缀 * redis中token的key值前缀
*/ */
String SESSION_PREFIX = "spring:session:sessions:"; String SESSION_PREFIX = "spring:session:sessions:";
Long ONE_DAY = 24 * 60 * 60L;
interface Channel { interface Channel {
long LKB = 1; // 量化派 long LKB = 1; // 量化派
......
...@@ -234,7 +234,7 @@ public class SmsController implements IBaseController { ...@@ -234,7 +234,7 @@ 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);
redisTemplate.expire(verificationPhoneCountKey, Constants.ONE_DAY,TimeUnit.SECONDS); redisTemplate.expire(verificationPhoneCountKey, DateUtils.getSeconds(), TimeUnit.SECONDS);
if (getPhoneVerificationCount > PHONE_MAX_PER_DAY) { if (getPhoneVerificationCount > PHONE_MAX_PER_DAY) {
LOGGER.info("您手机号已经达到获取今天短信验证码上限:phoneNo:{},deviceId:{},ip:{}",phoneNo,deviceId,getIp()); LOGGER.info("您手机号已经达到获取今天短信验证码上限:phoneNo:{},deviceId:{},ip:{}",phoneNo,deviceId,getIp());
...@@ -255,7 +255,7 @@ public class SmsController implements IBaseController { ...@@ -255,7 +255,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);
redisTemplate.expire(verificationDeviceCountKey, Constants.ONE_DAY,TimeUnit.SECONDS); redisTemplate.expire(verificationDeviceCountKey, DateUtils.getSeconds(), TimeUnit.SECONDS);
if (getDeviceVerificationCount > DEVICE_MAX_PER_DAY) { if (getDeviceVerificationCount > DEVICE_MAX_PER_DAY) {
LOGGER.info("您设备已经达到获取今天短信验证码上限:phoneNo:{},deviceId:{},ip:{}",phoneNo,verificationDeviceCountKey,getIp()); LOGGER.info("您设备已经达到获取今天短信验证码上限:phoneNo:{},deviceId:{},ip:{}",phoneNo,verificationDeviceCountKey,getIp());
return JsonResult.buildErrorStateResult("您设备已经达到获取今天短信验证码上限", null); return JsonResult.buildErrorStateResult("您设备已经达到获取今天短信验证码上限", null);
...@@ -311,7 +311,7 @@ public class SmsController implements IBaseController { ...@@ -311,7 +311,7 @@ public class SmsController implements IBaseController {
if (!StringUtils.isEmpty(deviceId)) { if (!StringUtils.isEmpty(deviceId)) {
String verificationDeviceCountKey = Constants.REDIS_VOICE_DEVICE_COUNT + deviceId; String verificationDeviceCountKey = Constants.REDIS_VOICE_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);
redisTemplate.expire(verificationDeviceCountKey, Constants.ONE_DAY,TimeUnit.SECONDS); redisTemplate.expire(verificationDeviceCountKey, DateUtils.getSeconds(), TimeUnit.SECONDS);
if (getDeviceVerificationCount > DEVICE_MAX_PER_DAY) { if (getDeviceVerificationCount > DEVICE_MAX_PER_DAY) {
return JsonResult.buildErrorStateResult("您设备已经达到获取今天语音验证码上限", null); return JsonResult.buildErrorStateResult("您设备已经达到获取今天语音验证码上限", null);
} }
......
...@@ -21,6 +21,7 @@ import cn.quantgroup.xyqb.service.sms.ISmsService; ...@@ -21,6 +21,7 @@ import cn.quantgroup.xyqb.service.sms.ISmsService;
import cn.quantgroup.xyqb.service.user.IUserDetailService; import cn.quantgroup.xyqb.service.user.IUserDetailService;
import cn.quantgroup.xyqb.service.user.IUserService; import cn.quantgroup.xyqb.service.user.IUserService;
import cn.quantgroup.xyqb.service.wechat.IWechatService; import cn.quantgroup.xyqb.service.wechat.IWechatService;
import cn.quantgroup.xyqb.util.DateUtils;
import cn.quantgroup.xyqb.util.MqUtils; import cn.quantgroup.xyqb.util.MqUtils;
import cn.quantgroup.xyqb.util.PasswordUtil; import cn.quantgroup.xyqb.util.PasswordUtil;
import cn.quantgroup.xyqb.util.ValidationUtil; import cn.quantgroup.xyqb.util.ValidationUtil;
...@@ -543,7 +544,7 @@ public class UserController implements IBaseController { ...@@ -543,7 +544,7 @@ public class UserController implements IBaseController {
// 密码错误时,给该账号添加计数器 // 密码错误时,给该账号添加计数器
String key = Constants.REDIS_PASSWORD_ERROR_COUNT + userName; String key = Constants.REDIS_PASSWORD_ERROR_COUNT + userName;
if (!stringRedisTemplate.hasKey(key)) { if (!stringRedisTemplate.hasKey(key)) {
stringRedisTemplate.opsForValue().set(key, String.valueOf(0), Constants.ONE_DAY, TimeUnit.SECONDS); stringRedisTemplate.opsForValue().set(key, String.valueOf(0), DateUtils.getSeconds(), TimeUnit.SECONDS);
} }
// 密码错误计数 // 密码错误计数
Long errorCount = stringRedisTemplate.opsForValue().increment(key, 1L); Long errorCount = stringRedisTemplate.opsForValue().increment(key, 1L);
......
...@@ -7,7 +7,7 @@ import java.util.Calendar; ...@@ -7,7 +7,7 @@ import java.util.Calendar;
*/ */
public class DateUtils { public class DateUtils {
/** /**
* 计算当前时间到当天23:59:59时间差, * 计算当前时间到当天 23:59:59.999 时间差,
* 返回时间差(单位秒) * 返回时间差(单位秒)
* @return * @return
*/ */
...@@ -16,9 +16,10 @@ public class DateUtils { ...@@ -16,9 +16,10 @@ public class DateUtils {
endOfDay.set(Calendar.HOUR_OF_DAY, 23); endOfDay.set(Calendar.HOUR_OF_DAY, 23);
endOfDay.set(Calendar.MINUTE, 59); endOfDay.set(Calendar.MINUTE, 59);
endOfDay.set(Calendar.SECOND, 59); endOfDay.set(Calendar.SECOND, 59);
endOfDay.set(Calendar.MILLISECOND, 999);
long timeStamp = endOfDay.getTimeInMillis(); long timeStamp = endOfDay.getTimeInMillis();
Calendar current = Calendar.getInstance(); Calendar current = Calendar.getInstance();
long now = current.getTimeInMillis(); long now = System.currentTimeMillis();
long during = (timeStamp - now) / 1000; long during = (timeStamp - now) / 1000;
return during; return during;
} }
......
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