From fd67804eee7b9ca47f3ece279bb3e424a6c064ac Mon Sep 17 00:00:00 2001 From: liuchengqian Date: Fri, 13 Oct 2023 13:46:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8A=9F=E8=83=BD=EF=BC=9A?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E5=8F=91=E9=80=81=E7=9F=AD=E4=BF=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xkrs/common/config/WebSecurityConfig.java | 1 + .../com/xkrs/controller/SMSController.java | 36 +++++++++++++++++++ .../java/com/xkrs/model/bean/SendSmsBean.java | 36 +++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 src/main/java/com/xkrs/controller/SMSController.java create mode 100644 src/main/java/com/xkrs/model/bean/SendSmsBean.java diff --git a/src/main/java/com/xkrs/common/config/WebSecurityConfig.java b/src/main/java/com/xkrs/common/config/WebSecurityConfig.java index 6d3c8a1..581742e 100644 --- a/src/main/java/com/xkrs/common/config/WebSecurityConfig.java +++ b/src/main/java/com/xkrs/common/config/WebSecurityConfig.java @@ -58,6 +58,7 @@ class WebSecurityConfig extends WebSecurityConfigurerAdapter { .antMatchers(HttpMethod.GET, "/api/adm/getCountyList").permitAll()//根据市编号获取区县列表 .antMatchers(HttpMethod.GET, "/api/adm/getStreetList").permitAll()//根据区县编号获取街道列表 .antMatchers(HttpMethod.GET, "/queryVectorBoundary").permitAll()//获取城市矢量边界 + .antMatchers(HttpMethod.POST, "/sendSmsToUser").permitAll()//给用户发送短信 // 所有其它请求需要身份认证 .anyRequest().authenticated() .and() diff --git a/src/main/java/com/xkrs/controller/SMSController.java b/src/main/java/com/xkrs/controller/SMSController.java new file mode 100644 index 0000000..686f16d --- /dev/null +++ b/src/main/java/com/xkrs/controller/SMSController.java @@ -0,0 +1,36 @@ +package com.xkrs.controller; + +import com.xkrs.model.bean.SendSmsBean; +import com.xkrs.utilsnew.SMSUtils; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +public class SMSController { + + /** + * 给用户发送短信 + */ + @PostMapping("/sendSmsToUser") + public String sendSmsToUser(@RequestBody SendSmsBean sendSmsBean) { + List phoneNumbers = sendSmsBean.getPhoneNumbers(); + String templateId = sendSmsBean.getTemplateId(); + List templateParams = sendSmsBean.getTemplateParams(); + + String[] phoneNumberArray = new String[phoneNumbers.size()]; + for (int i = 0; i < phoneNumbers.size(); i++) { + String phoneNumber = phoneNumbers.get(i); + if (phoneNumber.startsWith("86")) { + phoneNumberArray[i] = phoneNumber; + } else { + phoneNumberArray[i] = "86" + phoneNumber; + } + } + int sendSmsToUser = SMSUtils.sendSmsToUser(phoneNumberArray, templateId, templateParams.toArray(new String[templateParams.size()])); + return "发送完毕" + sendSmsToUser; + } + +} diff --git a/src/main/java/com/xkrs/model/bean/SendSmsBean.java b/src/main/java/com/xkrs/model/bean/SendSmsBean.java new file mode 100644 index 0000000..acaf0e3 --- /dev/null +++ b/src/main/java/com/xkrs/model/bean/SendSmsBean.java @@ -0,0 +1,36 @@ +package com.xkrs.model.bean; + +import java.util.List; + +public class SendSmsBean { + + private List phoneNumbers; + + private String templateId; + + private List templateParams; + + public List getPhoneNumbers() { + return phoneNumbers; + } + + public void setPhoneNumbers(List phoneNumbers) { + this.phoneNumbers = phoneNumbers; + } + + public String getTemplateId() { + return templateId; + } + + public void setTemplateId(String templateId) { + this.templateId = templateId; + } + + public List getTemplateParams() { + return templateParams; + } + + public void setTemplateParams(List templateParams) { + this.templateParams = templateParams; + } +}