新增七牛云短信平台

This commit is contained in:
阿沐 2022-08-20 17:21:59 +08:00
parent cc5f8cd58d
commit 0b580d2fe2
3 changed files with 84 additions and 33 deletions

View File

@ -1,31 +1,36 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>net.maku</groupId>
<artifactId>fast-boot-module</artifactId>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>fast-boot-message</artifactId>
<packaging>jar</packaging>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>net.maku</groupId>
<artifactId>fast-boot-module</artifactId>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>fast-boot-message</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>net.maku</groupId>
<artifactId>fast-framework</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>dysmsapi20170525</artifactId>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</dependency>
<dependency>
<groupId>com.tencentcloudapi</groupId>
<artifactId>tencentcloud-sdk-java</artifactId>
</dependency>
</dependencies>
<dependencies>
<dependency>
<groupId>net.maku</groupId>
<artifactId>fast-framework</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>dysmsapi20170525</artifactId>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</dependency>
<dependency>
<groupId>com.tencentcloudapi</groupId>
<artifactId>tencentcloud-sdk-java</artifactId>
</dependency>
<dependency>
<groupId>com.qiniu</groupId>
<artifactId>qiniu-java-sdk</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -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<String, String> 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);
}
}
}

16
pom.xml
View File

@ -17,11 +17,11 @@
</parent>
<modules>
<module>fast-boot-new</module>
<module>fast-boot-system</module>
<module>fast-boot-module</module>
<module>fast-boot-api</module>
<module>fast-framework</module>
<module>fast-boot-new</module>
<module>fast-boot-system</module>
<module>fast-boot-module</module>
<module>fast-boot-api</module>
<module>fast-framework</module>
<module>fast-server</module>
</modules>
@ -42,6 +42,7 @@
<aliyun.oss.version>3.8.0</aliyun.oss.version>
<aliyun.dysmsapi.version>2.0.18</aliyun.dysmsapi.version>
<tencentcloud.sdk.version>3.1.574</tencentcloud.sdk.version>
<qiniu.version>7.11.0</qiniu.version>
</properties>
<dependencies>
@ -131,6 +132,11 @@
<artifactId>tencentcloud-sdk-java</artifactId>
<version>${tencentcloud.sdk.version}</version>
</dependency>
<dependency>
<groupId>com.qiniu</groupId>
<artifactId>qiniu-java-sdk</artifactId>
<version>${qiniu.version}</version>
</dependency>
</dependencies>
</dependencyManagement>