1.搭建步骤
pom文件
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alicloud-sms</artifactId>
</dependency>
配置
spring:
cloud:
alicloud:
access-key: LTAI4FvkNRE42kM3YojUEw7S
secret-key: 310QnlYjkMJEt4vofTBeD8fhLpXi6n
测试代码 ```java
@Autowired private ISmsService smsService;
@RequestMapping(“testSendSms”) public void sendSms(){
SendSmsRequest request = new SendSmsRequest();
// Required:the mobile number
request.setPhoneNumbers("18751669318");
// Required:SMS-SignName-could be found in sms console
request.setSignName("思政课学习平台");
// Required:Template-could be found in sms console
request.setTemplateCode("SMS_181540327");
// Required:The param of sms template.For exmaple, if the template is "Hello,your verification code is ${code}". The param should be like following value
request.setTemplateParam("{\"code\":\"" + "11111"+ "\"}");
SendSmsResponse sendSmsResponse ;
try {
sendSmsResponse = smsService.sendSmsRequest(request);
}
catch (ClientException e) {
e.printStackTrace();
sendSmsResponse = new SendSmsResponse();
}
}
<a name="tupfY"></a>
# 2.阿里短信使用
1.开通<br />2.名词解释<br />①短信签名:发送方名称<br />②短信模板:返送短信的格式<br />③具体:
```yaml
【阿里云】您正在申请手机注册,验证码为:${code},5分钟内有效!
3.具体步骤
①打开控制台
②点击添加签名
③点击添加模版