From 0b580d2fe2394fd1af4e9907cee809a938554b21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E6=B2=90?= Date: Sat, 20 Aug 2022 17:21:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=B8=83=E7=89=9B=E4=BA=91?= =?UTF-8?q?=E7=9F=AD=E4=BF=A1=E5=B9=B3=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fast-boot-module/fast-boot-message/pom.xml | 61 ++++++++++++---------- .../net/maku/message/sms/QiniuSmsStrategy.java | 40 ++++++++++++++ pom.xml | 16 ++++-- 3 files changed, 84 insertions(+), 33 deletions(-) create mode 100644 fast-boot-module/fast-boot-message/src/main/java/net/maku/message/sms/QiniuSmsStrategy.java diff --git a/fast-boot-module/fast-boot-message/pom.xml b/fast-boot-module/fast-boot-message/pom.xml index 0f4aef8..de65482 100644 --- a/fast-boot-module/fast-boot-message/pom.xml +++ b/fast-boot-module/fast-boot-message/pom.xml @@ -1,31 +1,36 @@ - - - net.maku - fast-boot-module - ${revision} - - 4.0.0 - fast-boot-message - jar + + + net.maku + fast-boot-module + ${revision} + + 4.0.0 + fast-boot-message + jar - - - net.maku - fast-framework - ${revision} - - - com.aliyun - dysmsapi20170525 - - - com.squareup.okhttp3 - okhttp - - - com.tencentcloudapi - tencentcloud-sdk-java - - + + + net.maku + fast-framework + ${revision} + + + com.aliyun + dysmsapi20170525 + + + com.squareup.okhttp3 + okhttp + + + com.tencentcloudapi + tencentcloud-sdk-java + + + com.qiniu + qiniu-java-sdk + + \ No newline at end of file diff --git a/fast-boot-module/fast-boot-message/src/main/java/net/maku/message/sms/QiniuSmsStrategy.java b/fast-boot-module/fast-boot-message/src/main/java/net/maku/message/sms/QiniuSmsStrategy.java new file mode 100644 index 0000000..736fdc6 --- /dev/null +++ b/fast-boot-module/fast-boot-message/src/main/java/net/maku/message/sms/QiniuSmsStrategy.java @@ -0,0 +1,40 @@ +package net.maku.message.sms; + +import com.qiniu.http.Response; +import com.qiniu.sms.SmsManager; +import com.qiniu.util.Auth; +import net.maku.framework.common.exception.FastException; +import net.maku.message.sms.config.SmsConfig; + +import java.util.Map; + +/** + * 七牛云短信 + * + * @author 阿沐 babamu@126.com + */ +public class QiniuSmsStrategy implements SmsStrategy { + private final SmsConfig smsConfig; + private final SmsManager smsManager; + + public QiniuSmsStrategy(SmsConfig smsConfig) { + this.smsConfig = smsConfig; + + Auth auth = Auth.create(smsConfig.getAccessKey(), smsConfig.getSecretKey()); + smsManager = new SmsManager(auth); + } + + @Override + public void send(String mobile, Map params) { + try { + Response response = smsManager.sendSingleMessage(smsConfig.getTemplateId(), mobile, params); + + // 是否发送成功 + if (!response.isOK()) { + throw new FastException(response.error); + } + } catch (Exception e) { + throw new FastException("短信发送失败:", e); + } + } +} diff --git a/pom.xml b/pom.xml index 1268caa..51d00f6 100644 --- a/pom.xml +++ b/pom.xml @@ -17,11 +17,11 @@ - fast-boot-new - fast-boot-system - fast-boot-module - fast-boot-api - fast-framework + fast-boot-new + fast-boot-system + fast-boot-module + fast-boot-api + fast-framework fast-server @@ -42,6 +42,7 @@ 3.8.0 2.0.18 3.1.574 + 7.11.0 @@ -131,6 +132,11 @@ tencentcloud-sdk-java ${tencentcloud.sdk.version} + + com.qiniu + qiniu-java-sdk + ${qiniu.version} +