|
|
|
@ -25,6 +25,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import java.time.LocalDate;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.concurrent.Executor;
|
|
|
|
@ -57,6 +58,20 @@ public class SmsLoginServiceImpl implements SmsLoginService {
|
|
|
|
|
if (!isPhone) {
|
|
|
|
|
return ResultVoUtil.error("请输入正确的手机号。");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 检查手机号当天获取验证码的次数
|
|
|
|
|
// 获取今天的日期,用于计算当天的发送次数
|
|
|
|
|
LocalDate today = LocalDate.now();
|
|
|
|
|
String cacheKey = "verification_count_" + phone + "_" + today;
|
|
|
|
|
Integer count = iCacheManager.get(CacheConstants.USER_PHONE_MODEL_NAME, cacheKey);
|
|
|
|
|
if (count == null) {
|
|
|
|
|
count = 0;
|
|
|
|
|
}
|
|
|
|
|
if (count >= 10) {
|
|
|
|
|
return ResultVoUtil.error("获取验证码次数超限,请明天再试!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//生成验证码
|
|
|
|
|
String code = RandomUtil.randomNumbers(4);
|
|
|
|
|
|
|
|
|
@ -67,7 +82,10 @@ public class SmsLoginServiceImpl implements SmsLoginService {
|
|
|
|
|
|
|
|
|
|
//用户登录信息写入缓存
|
|
|
|
|
iCacheManager.put(CacheConstants.USER_PHONE_MODEL_NAME,phone,code,CacheConstants.CACHE_TIME);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 更新手机号当天获取验证码的次数
|
|
|
|
|
iCacheManager.put(CacheConstants.USER_PHONE_MODEL_NAME, cacheKey, count + 1, CacheConstants.CACHE_TIME);
|
|
|
|
|
|
|
|
|
|
//保存验证码到 缓存中
|
|
|
|
|
return ResultVoUtil.success(code);
|
|
|
|
|
}
|
|
|
|
|