1.搭建步骤

  1. pom文件

    1. <dependency>
    2. <groupId>com.alibaba.cloud</groupId>
    3. <artifactId>spring-cloud-starter-alicloud-sms</artifactId>
    4. </dependency>
  2. 配置

image.png

  1. spring:
  2. cloud:
  3. alicloud:
  4. access-key: LTAI4FvkNRE42kM3YojUEw7S
  5. secret-key: 310QnlYjkMJEt4vofTBeD8fhLpXi6n
  1. 测试代码 ```java

    @Autowired private ISmsService smsService;

    @RequestMapping(“testSendSms”) public void sendSms(){

    1. SendSmsRequest request = new SendSmsRequest();
    2. // Required:the mobile number
    3. request.setPhoneNumbers("18751669318");
    4. // Required:SMS-SignName-could be found in sms console
    5. request.setSignName("思政课学习平台");
    6. // Required:Template-could be found in sms console
    7. request.setTemplateCode("SMS_181540327");
    8. // 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
    9. request.setTemplateParam("{\"code\":\"" + "11111"+ "\"}");
    10. SendSmsResponse sendSmsResponse ;
    11. try {
    12. sendSmsResponse = smsService.sendSmsRequest(request);
    13. }
    14. catch (ClientException e) {
    15. e.printStackTrace();
    16. sendSmsResponse = new SendSmsResponse();
    17. }

    }

  1. <a name="tupfY"></a>
  2. # 2.阿里短信使用
  3. 1.开通<br />2.名词解释<br />①短信签名:发送方名称<br />②短信模板:返送短信的格式<br />③具体:
  4. ```yaml
  5. 【阿里云】您正在申请手机注册,验证码为:${code},5分钟内有效!

3.具体步骤
①打开控制台
image.png
②点击添加签名
③点击添加模版
image.png