添加功能:自定义发送短信

This commit is contained in:
liuchengqian 2023-10-13 13:46:14 +08:00
parent 03a893f893
commit fd67804eee
3 changed files with 73 additions and 0 deletions

View File

@ -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()

View File

@ -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<String> phoneNumbers = sendSmsBean.getPhoneNumbers();
String templateId = sendSmsBean.getTemplateId();
List<String> 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;
}
}

View File

@ -0,0 +1,36 @@
package com.xkrs.model.bean;
import java.util.List;
public class SendSmsBean {
private List<String> phoneNumbers;
private String templateId;
private List<String> templateParams;
public List<String> getPhoneNumbers() {
return phoneNumbers;
}
public void setPhoneNumbers(List<String> phoneNumbers) {
this.phoneNumbers = phoneNumbers;
}
public String getTemplateId() {
return templateId;
}
public void setTemplateId(String templateId) {
this.templateId = templateId;
}
public List<String> getTemplateParams() {
return templateParams;
}
public void setTemplateParams(List<String> templateParams) {
this.templateParams = templateParams;
}
}