验证码时效
This commit is contained in:
parent
fe70c92210
commit
8c78471e2f
|
|
@ -23,6 +23,9 @@ import org.apache.commons.collections4.CollectionUtils;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
|
@ -162,8 +165,14 @@ public class SysSmsServiceImpl implements ISysSmsService {
|
|||
} else {
|
||||
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 + ",短信验证码发送成功 !");
|
||||
} catch (Exception e) {
|
||||
return AjaxResult.error("发送失败:" + e.getMessage());
|
||||
|
|
|
|||
Loading…
Reference in New Issue