From 07859b688a1fd3bad6998c137a20ba466903aeb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E6=B2=90?= Date: Tue, 25 Jun 2024 17:23:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/net/maku/message/api/SmsApiImpl.java | 56 ---------------- .../main/java/net/maku/system/api/SmsApiImpl.java | 75 ++++++++++++++++++++++ 2 files changed, 75 insertions(+), 56 deletions(-) delete mode 100644 maku-boot-module/maku-module-message/src/main/java/net/maku/message/api/SmsApiImpl.java create mode 100644 maku-boot-system/src/main/java/net/maku/system/api/SmsApiImpl.java diff --git a/maku-boot-module/maku-module-message/src/main/java/net/maku/message/api/SmsApiImpl.java b/maku-boot-module/maku-module-message/src/main/java/net/maku/message/api/SmsApiImpl.java deleted file mode 100644 index b98e197..0000000 --- a/maku-boot-module/maku-module-message/src/main/java/net/maku/message/api/SmsApiImpl.java +++ /dev/null @@ -1,56 +0,0 @@ -package net.maku.message.api; - -import lombok.AllArgsConstructor; -import net.maku.api.module.message.SmsApi; -import net.maku.message.cache.SmsSendCache; -import net.maku.message.sms.service.SmsService; -import org.springframework.stereotype.Component; - -import java.util.HashMap; -import java.util.Map; - -/** - * 短信服务Api - * - * @author 阿沐 babamu@126.com - * MAKU - */ -@Component -@AllArgsConstructor -public class SmsApiImpl implements SmsApi { - private final SmsService smsService; - private final SmsSendCache smsSendCache; - - @Override - public boolean send(String mobile, Map params) { - return smsService.send(mobile, params); - } - - @Override - public boolean sendCode(String mobile, String key, String value) { - // 短信参数 - Map params = new HashMap<>(); - params.put(key, value); - - // 发送短信 - boolean flag = smsService.send(mobile, params); - if (flag) { - smsSendCache.saveCode(mobile, value); - } - return flag; - } - - @Override - public boolean verifyCode(String mobile, String code) { - String value = smsSendCache.getCode(mobile); - if (value != null) { - // 删除短信验证码 - smsSendCache.deleteCode(mobile); - - // 效验 - return value.equalsIgnoreCase(code); - } - - return false; - } -} diff --git a/maku-boot-system/src/main/java/net/maku/system/api/SmsApiImpl.java b/maku-boot-system/src/main/java/net/maku/system/api/SmsApiImpl.java new file mode 100644 index 0000000..1af5d1c --- /dev/null +++ b/maku-boot-system/src/main/java/net/maku/system/api/SmsApiImpl.java @@ -0,0 +1,75 @@ +package net.maku.system.api; + +import lombok.AllArgsConstructor; +import net.maku.api.module.system.SmsApi; +import net.maku.sms.service.SmsService; +import net.maku.system.cache.SmsSendCache; +import org.springframework.stereotype.Component; + +import java.util.HashMap; +import java.util.Map; + +/** + * 短信服务Api + * + * @author 阿沐 babamu@126.com + * MAKU + */ +@Component +@AllArgsConstructor +public class SmsApiImpl implements SmsApi { + private final SmsService smsService; + private final SmsSendCache smsSendCache; + + @Override + public boolean send(String mobile, Map params) { + return smsService.send(mobile, params); + } + + @Override + public boolean send(String groupName, String mobile, Map params) { + return smsService.send(groupName, mobile, params); + } + + @Override + public boolean sendCode(String mobile, String key, String value) { + // 短信参数 + Map params = new HashMap<>(); + params.put(key, value); + + // 发送短信 + boolean flag = smsService.send(mobile, params); + if (flag) { + smsSendCache.saveCode(mobile, value); + } + return flag; + } + + @Override + public boolean sendCode(String groupName, String mobile, String key, String value) { + // 短信参数 + Map params = new HashMap<>(); + params.put(key, value); + + // 发送短信 + boolean flag = smsService.send(groupName, mobile, params); + if (flag) { + smsSendCache.saveCode(mobile, value); + } + return flag; + } + + @Override + public boolean verifyCode(String mobile, String code) { + String value = smsSendCache.getCode(mobile); + if (value != null) { + // 删除短信验证码 + smsSendCache.deleteCode(mobile); + + // 效验 + return value.equalsIgnoreCase(code); + } + + return false; + } +}