add 增加 demo 短信演示案例

This commit is contained in:
疯狂的狮子li 2022-05-06 18:07:43 +08:00
parent e57d11d55a
commit 416088a2de
2 changed files with 69 additions and 0 deletions

View File

@ -23,6 +23,22 @@
<artifactId>ruoyi-common</artifactId>
</dependency>
<dependency>
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi-sms</artifactId>
</dependency>
<!-- 短信 用哪个导入哪个依赖 -->
<!-- <dependency>-->
<!-- <groupId>com.aliyun</groupId>-->
<!-- <artifactId>dysmsapi20170525</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>com.tencentcloudapi</groupId>
<artifactId>tencentcloud-sdk-java</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,53 @@
package com.ruoyi.demo.controller;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.sms.core.SmsTemplate;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.Map;
/**
* 短信演示案例
*
* @author Lion Li
* @version 4.2.0
*/
@Validated
@Api(value = "短信演示案例", tags = {"短信演示案例"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/demo/sms")
public class SmsController {
private final SmsTemplate smsTemplate;
@ApiOperation("发送短信Aliyun")
@GetMapping("/sendAliyun")
public R<Object> sendSimpleMessage(@ApiParam("电话号") String phones,
@ApiParam("模板ID") String templateId) {
Map<String, String> map = new HashMap<>(1);
map.put("code", "1234");
Object send = smsTemplate.send(phones, templateId, map);
return R.ok(send);
}
@ApiOperation("发送短信Tencent")
@GetMapping("/sendTencent")
public R<Object> sendMessageWithAttachment(@ApiParam("电话号") String phones,
@ApiParam("模板ID") String templateId) {
Map<String, String> map = new HashMap<>(1);
// map.put("2", "测试测试");
map.put("1", "1234");
Object send = smsTemplate.send(phones, templateId, map);
return R.ok(send);
}
}