验证码时效

This commit is contained in:
mashuai 2024-06-14 16:17:07 +08:00
parent fe70c92210
commit 8c78471e2f
1 changed files with 10 additions and 1 deletions

View File

@ -23,6 +23,9 @@ import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.temporal.ChronoUnit;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
@ -162,8 +165,14 @@ public class SysSmsServiceImpl implements ISysSmsService {
} else { } else {
sendCount++; sendCount++;
} }
// 获取当前日期和时间
LocalDateTime now = LocalDateTime.now();
// 获取当天午夜时间
LocalDateTime midnight = LocalDateTime.of(now.toLocalDate(), LocalTime.MIDNIGHT).plusDays(1);
// 计算当前时间到当天午夜的时间差
long secondsUntilMidnight = now.until(midnight, ChronoUnit.SECONDS);
//存储一天手机号发送验证码数据 //存储一天手机号发送验证码数据
redisService.setCacheObject(key, sendCount, 1L, TimeUnit.DAYS); redisService.setCacheObject(key, sendCount, secondsUntilMidnight, TimeUnit.SECONDS);
return success("手机号:" + phone + ",短信验证码发送成功 "); return success("手机号:" + phone + ",短信验证码发送成功 ");
} catch (Exception e) { } catch (Exception e) {
return AjaxResult.error("发送失败:" + e.getMessage()); return AjaxResult.error("发送失败:" + e.getMessage());