From 536ed416e79a76eb497e620059a29ad73c5113b5 Mon Sep 17 00:00:00 2001 From: wu Date: Sun, 2 Mar 2025 13:55:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=9F=AD=E4=BF=A1=E6=8F=90?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/yingji/utils/SmsUtil.java | 48 +++++++++---------- .../main/java/com/yingji/utils/SmsUtil.java | 37 +++++++------- .../main/java/com/yingji/utils/SmsUtil.java | 37 +++++++------- .../main/java/com/yingji/utils/SmsUtil.java | 37 +++++++------- 4 files changed, 86 insertions(+), 73 deletions(-) diff --git a/alarm/src/main/java/com/yingji/utils/SmsUtil.java b/alarm/src/main/java/com/yingji/utils/SmsUtil.java index 0ba4891..7a66769 100644 --- a/alarm/src/main/java/com/yingji/utils/SmsUtil.java +++ b/alarm/src/main/java/com/yingji/utils/SmsUtil.java @@ -39,10 +39,7 @@ public class SmsUtil { bodyMap.put("uid", "yjglj_yjjyszzh"); bodyMap.put("pwd", "f604d2d6de51573b5cef5c95c11ffabe"); String bodyJson = JSONUtil.toJsonStr(bodyMap); - String responseStr = HttpRequest.post("http://2.46.42.43:80/admin-api/sms/token") - .body(bodyJson) - .execute() - .body(); + String responseStr = HttpRequest.post("http://2.46.42.43:80/admin-api/sms/token").body(bodyJson).execute().body(); JSONObject responseJson = JSONUtil.parseObj(responseStr); log.error("----------------------------短信token======================"); log.error("短信token: " + JSONUtil.toJsonStr(responseJson)); @@ -60,34 +57,39 @@ public class SmsUtil { if (errorMes != null) { Integer minutes = redisCache.getCacheObject(errorMes); if (minutes == null) { - redisCache.setCacheObject(errorMes, 1, 10, TimeUnit.MINUTES); + redisCache.setCacheObject(errorMes, 1, 11, TimeUnit.MINUTES); return; } if (minutes < 10) { long expireTime = redisCache.getExpire(errorMes); if (expireTime == -1 || expireTime == -2) { - redisCache.setCacheObject(errorMes, 1, 10, TimeUnit.MINUTES); + redisCache.setCacheObject(errorMes, 1, 11, TimeUnit.MINUTES); } else { redisCache.setCacheObject(errorMes, minutes + 1, (int) expireTime, TimeUnit.SECONDS); } return; } - } - // 限制每种tel每天只能发一次短信 - Map dataKey = redisCache.getCacheMap("dataKey"); - if (CollectionUtil.isNotEmpty(dataKey)) { - String sendDateStr = (String) dataKey.get(content); - LocalDate sendDate = LocalDate.parse(sendDateStr); - if (LocalDate.now().equals(sendDate)) { - return; + // 限制每种tel每天只能发一次短信 + Map dataKey = redisCache.getCacheMap("dataKey"); + if (CollectionUtil.isNotEmpty(dataKey)) { + String sendDateStr = (String) dataKey.get(errorMes); + if (StrUtil.isEmpty(sendDateStr)) { + dataKey.put(errorMes, LocalDate.now()); + redisCache.setCacheMap("dataKey", dataKey); + } else { + LocalDate sendDate = LocalDate.parse(sendDateStr); + if (LocalDate.now().equals(sendDate)) { + return; + } else { + dataKey.put(errorMes, LocalDate.now()); + redisCache.setCacheMap("dataKey", dataKey); + } + } } else { - dataKey.put(content, LocalDate.now()); - redisCache.setCacheMap("dataKey", dataKey); + Map map = new HashMap<>(); + map.put(errorMes, LocalDate.now()); + redisCache.setCacheMap("dataKey", map); } - } else { - Map map = new HashMap<>(); - map.put(content, LocalDate.now()); - redisCache.setCacheMap("dataKey", map); } String token = getSmsToken(); Map bodyMap = new HashMap<>(); @@ -102,11 +104,7 @@ public class SmsUtil { bodyMap.put("content", "市应急局提醒:" + content); String bodyJson = JSONUtil.toJsonStr(bodyMap); log.error("bodyJson: " + bodyJson); - String responseStr = HttpRequest.post("http://2.46.42.43:80/admin-api/sms/send") - .header("Authorization", "Bearer " + token) - .body(bodyJson) - .execute() - .body(); + String responseStr = HttpRequest.post("http://2.46.42.43:80/admin-api/sms/send").header("Authorization", "Bearer " + token).body(bodyJson).execute().body(); log.error("----------------------------短信响应======================"); log.error("短信: " + JSONUtil.toJsonStr(responseStr)); } diff --git a/fire/src/main/java/com/yingji/utils/SmsUtil.java b/fire/src/main/java/com/yingji/utils/SmsUtil.java index 0ba4891..b251feb 100644 --- a/fire/src/main/java/com/yingji/utils/SmsUtil.java +++ b/fire/src/main/java/com/yingji/utils/SmsUtil.java @@ -60,34 +60,39 @@ public class SmsUtil { if (errorMes != null) { Integer minutes = redisCache.getCacheObject(errorMes); if (minutes == null) { - redisCache.setCacheObject(errorMes, 1, 10, TimeUnit.MINUTES); + redisCache.setCacheObject(errorMes, 1, 11, TimeUnit.MINUTES); return; } if (minutes < 10) { long expireTime = redisCache.getExpire(errorMes); if (expireTime == -1 || expireTime == -2) { - redisCache.setCacheObject(errorMes, 1, 10, TimeUnit.MINUTES); + redisCache.setCacheObject(errorMes, 1, 11, TimeUnit.MINUTES); } else { redisCache.setCacheObject(errorMes, minutes + 1, (int) expireTime, TimeUnit.SECONDS); } return; } - } - // 限制每种tel每天只能发一次短信 - Map dataKey = redisCache.getCacheMap("dataKey"); - if (CollectionUtil.isNotEmpty(dataKey)) { - String sendDateStr = (String) dataKey.get(content); - LocalDate sendDate = LocalDate.parse(sendDateStr); - if (LocalDate.now().equals(sendDate)) { - return; + // 限制每种tel每天只能发一次短信 + Map dataKey = redisCache.getCacheMap("dataKey"); + if (CollectionUtil.isNotEmpty(dataKey)) { + String sendDateStr = (String) dataKey.get(errorMes); + if (StrUtil.isEmpty(sendDateStr)) { + dataKey.put(errorMes, LocalDate.now()); + redisCache.setCacheMap("dataKey", dataKey); + } else { + LocalDate sendDate = LocalDate.parse(sendDateStr); + if (LocalDate.now().equals(sendDate)) { + return; + } else { + dataKey.put(errorMes, LocalDate.now()); + redisCache.setCacheMap("dataKey", dataKey); + } + } } else { - dataKey.put(content, LocalDate.now()); - redisCache.setCacheMap("dataKey", dataKey); + Map map = new HashMap<>(); + map.put(errorMes, LocalDate.now()); + redisCache.setCacheMap("dataKey", map); } - } else { - Map map = new HashMap<>(); - map.put(content, LocalDate.now()); - redisCache.setCacheMap("dataKey", map); } String token = getSmsToken(); Map bodyMap = new HashMap<>(); diff --git a/page/src/main/java/com/yingji/utils/SmsUtil.java b/page/src/main/java/com/yingji/utils/SmsUtil.java index 0ba4891..b251feb 100644 --- a/page/src/main/java/com/yingji/utils/SmsUtil.java +++ b/page/src/main/java/com/yingji/utils/SmsUtil.java @@ -60,34 +60,39 @@ public class SmsUtil { if (errorMes != null) { Integer minutes = redisCache.getCacheObject(errorMes); if (minutes == null) { - redisCache.setCacheObject(errorMes, 1, 10, TimeUnit.MINUTES); + redisCache.setCacheObject(errorMes, 1, 11, TimeUnit.MINUTES); return; } if (minutes < 10) { long expireTime = redisCache.getExpire(errorMes); if (expireTime == -1 || expireTime == -2) { - redisCache.setCacheObject(errorMes, 1, 10, TimeUnit.MINUTES); + redisCache.setCacheObject(errorMes, 1, 11, TimeUnit.MINUTES); } else { redisCache.setCacheObject(errorMes, minutes + 1, (int) expireTime, TimeUnit.SECONDS); } return; } - } - // 限制每种tel每天只能发一次短信 - Map dataKey = redisCache.getCacheMap("dataKey"); - if (CollectionUtil.isNotEmpty(dataKey)) { - String sendDateStr = (String) dataKey.get(content); - LocalDate sendDate = LocalDate.parse(sendDateStr); - if (LocalDate.now().equals(sendDate)) { - return; + // 限制每种tel每天只能发一次短信 + Map dataKey = redisCache.getCacheMap("dataKey"); + if (CollectionUtil.isNotEmpty(dataKey)) { + String sendDateStr = (String) dataKey.get(errorMes); + if (StrUtil.isEmpty(sendDateStr)) { + dataKey.put(errorMes, LocalDate.now()); + redisCache.setCacheMap("dataKey", dataKey); + } else { + LocalDate sendDate = LocalDate.parse(sendDateStr); + if (LocalDate.now().equals(sendDate)) { + return; + } else { + dataKey.put(errorMes, LocalDate.now()); + redisCache.setCacheMap("dataKey", dataKey); + } + } } else { - dataKey.put(content, LocalDate.now()); - redisCache.setCacheMap("dataKey", dataKey); + Map map = new HashMap<>(); + map.put(errorMes, LocalDate.now()); + redisCache.setCacheMap("dataKey", map); } - } else { - Map map = new HashMap<>(); - map.put(content, LocalDate.now()); - redisCache.setCacheMap("dataKey", map); } String token = getSmsToken(); Map bodyMap = new HashMap<>(); diff --git a/rescue/src/main/java/com/yingji/utils/SmsUtil.java b/rescue/src/main/java/com/yingji/utils/SmsUtil.java index 0ba4891..b251feb 100644 --- a/rescue/src/main/java/com/yingji/utils/SmsUtil.java +++ b/rescue/src/main/java/com/yingji/utils/SmsUtil.java @@ -60,34 +60,39 @@ public class SmsUtil { if (errorMes != null) { Integer minutes = redisCache.getCacheObject(errorMes); if (minutes == null) { - redisCache.setCacheObject(errorMes, 1, 10, TimeUnit.MINUTES); + redisCache.setCacheObject(errorMes, 1, 11, TimeUnit.MINUTES); return; } if (minutes < 10) { long expireTime = redisCache.getExpire(errorMes); if (expireTime == -1 || expireTime == -2) { - redisCache.setCacheObject(errorMes, 1, 10, TimeUnit.MINUTES); + redisCache.setCacheObject(errorMes, 1, 11, TimeUnit.MINUTES); } else { redisCache.setCacheObject(errorMes, minutes + 1, (int) expireTime, TimeUnit.SECONDS); } return; } - } - // 限制每种tel每天只能发一次短信 - Map dataKey = redisCache.getCacheMap("dataKey"); - if (CollectionUtil.isNotEmpty(dataKey)) { - String sendDateStr = (String) dataKey.get(content); - LocalDate sendDate = LocalDate.parse(sendDateStr); - if (LocalDate.now().equals(sendDate)) { - return; + // 限制每种tel每天只能发一次短信 + Map dataKey = redisCache.getCacheMap("dataKey"); + if (CollectionUtil.isNotEmpty(dataKey)) { + String sendDateStr = (String) dataKey.get(errorMes); + if (StrUtil.isEmpty(sendDateStr)) { + dataKey.put(errorMes, LocalDate.now()); + redisCache.setCacheMap("dataKey", dataKey); + } else { + LocalDate sendDate = LocalDate.parse(sendDateStr); + if (LocalDate.now().equals(sendDate)) { + return; + } else { + dataKey.put(errorMes, LocalDate.now()); + redisCache.setCacheMap("dataKey", dataKey); + } + } } else { - dataKey.put(content, LocalDate.now()); - redisCache.setCacheMap("dataKey", dataKey); + Map map = new HashMap<>(); + map.put(errorMes, LocalDate.now()); + redisCache.setCacheMap("dataKey", map); } - } else { - Map map = new HashMap<>(); - map.put(content, LocalDate.now()); - redisCache.setCacheMap("dataKey", map); } String token = getSmsToken(); Map bodyMap = new HashMap<>();