快速开始

1 引入基础jar包

1
2
3
4
<dependency>
<groupId>net.guerlab.sms</groupId>
<artifactId>guerlab-sms-server-starter</artifactId>
</dependency>

2 引入厂商实现包并进行厂商参数配置

以阿里云为例

2.1 引入jar

1
2
3
4
<dependency>
<groupId>net.guerlab.sms</groupId>
<artifactId>guerlab-sms-aliyun-starter</artifactId>
</dependency>

3.2 参数配置

在application.yml中添加配置

1
2
3
4
5
6
7
8
9
10
11
sms:
aliyun:
enable: true ##启用阿里云的短信业务客户端
weight: 1 ##权重
access-key-id: ##AccessKeyId
access-key-secret: ##AccessKeySecret
endpoint: cn-hangzhou ##endpoint,默认为cn-hangzhou
sign-name: ##短信签名
templates:
VerificationCode: SMS_00000000 ##验证码业务所使用的短信模板ID
test: SMS_00000001 ##自定义业务所使用的短信模板ID

3 业务调用

3.1 短信通知

1
2
3
4
5
6
7
8
9
10
11
Map<String, String> params = new HashMap<>();
params.put("code", "123");

NoticeData noticeData = new NoticeData();
noticeData.setType("test");
noticeData.setParams(params);

noticeService.send(noticeData, "电话号码"); //给一个号码同步发送
noticeService.send(noticeData, new String()["电话号码1", "电话号码2"]); //给多个号码同步发送
noticeService.asyncSend(noticeData, "电话号码"); //给一个号码异步发送
noticeService.asyncSend(noticeData, new String()["电话号码1", "电话号码2"]); //给多个号码异步发送

3.2 验证码

1
2
3
4
5
String phone = "电话号码";

verificationCodeService.send(phone); //发送验证码

verificationCodeService.verify(phone, code, identificationCode) //进行验证码验证,其中code为验证码,identificationCode为识别码,识别码非必填