|
@@ -0,0 +1,37 @@
|
|
|
|
+package com.rongwei.controller;
|
|
|
|
+
|
|
|
|
+import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
|
|
|
|
+import com.rongwei.bscommon.sys.service.AliyunSmsService;
|
|
|
|
+import com.rongwei.bsentity.Dto.SendMessageDto;
|
|
|
|
+import com.rongwei.rwcommon.base.R;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
+
|
|
|
|
+@RestController
|
|
|
|
+@RequestMapping("/send/message")
|
|
|
|
+@Slf4j
|
|
|
|
+public class SendMessageController {
|
|
|
|
+ @Autowired
|
|
|
|
+ private AliyunSmsService aliyunSmsService;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 通用短信接口
|
|
|
|
+ *
|
|
|
|
+ * @param dto 通用发短信DTO
|
|
|
|
+ * @return 发送结果
|
|
|
|
+ * @throws Exception 抛出异常
|
|
|
|
+ */
|
|
|
|
+ @PostMapping("/text")
|
|
|
|
+ public R sendTextMessage(@RequestBody SendMessageDto dto) throws Exception {
|
|
|
|
+ log.info("开始发送短信");
|
|
|
|
+ SendSmsResponse res = aliyunSmsService.sendSms(dto.getTemplateId(), dto.getParam(), dto.getPhone());
|
|
|
|
+ if (res.statusCode != 200) {
|
|
|
|
+ return R.errorWithMsg("发送短信失败");
|
|
|
|
+ }
|
|
|
|
+ return R.okWithMsg("发送短信成功");
|
|
|
|
+ }
|
|
|
|
+}
|