From 8c78471e2fa5b48c28d38f5226290773506882ae Mon Sep 17 00:00:00 2001 From: mashuai Date: Fri, 14 Jun 2024 16:17:07 +0800 Subject: [PATCH] =?UTF-8?q?=E9=AA=8C=E8=AF=81=E7=A0=81=E6=97=B6=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sgzb/system/service/impl/SysSmsServiceImpl.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/sgzb-modules/sgzb-system/src/main/java/com/bonus/sgzb/system/service/impl/SysSmsServiceImpl.java b/sgzb-modules/sgzb-system/src/main/java/com/bonus/sgzb/system/service/impl/SysSmsServiceImpl.java index 8a76cda2..002ed730 100644 --- a/sgzb-modules/sgzb-system/src/main/java/com/bonus/sgzb/system/service/impl/SysSmsServiceImpl.java +++ b/sgzb-modules/sgzb-system/src/main/java/com/bonus/sgzb/system/service/impl/SysSmsServiceImpl.java @@ -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());