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; + } +}