新增手机发短信接口

This commit is contained in:
wanggeng 2021-11-08 21:55:00 +08:00
parent fef33aa356
commit 99f2ee2088
4 changed files with 110 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package ink.wgink.module.sms.controller.resources.sms;
import ink.wgink.annotation.CheckRequestBodyAnnotation;
import ink.wgink.common.base.DefaultBaseController;
import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.module.sms.pojo.vos.sms.SmsPhoneSendVO;
import ink.wgink.module.sms.pojo.vos.sms.SmsSendVO;
import ink.wgink.module.sms.service.sms.ISmsService;
import ink.wgink.pojo.result.ErrorResult;
@ -44,4 +45,16 @@ public class SmsResourceController extends DefaultBaseController {
return new SuccessResult();
}
@ApiOperation(value = "发送短信", notes = "通过手机号直接发送短信接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "access_token", value = "access_token", paramType = "query", required = true),
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@PostMapping("send/phones")
@CheckRequestBodyAnnotation
public SuccessResult sendByPhones(@RequestBody SmsPhoneSendVO smsPhoneSendVO) throws Exception {
smsService.sendByPhones(smsPhoneSendVO);
return new SuccessResult();
}
}

View File

@ -0,0 +1,75 @@
package ink.wgink.module.sms.pojo.vos.sms;
import ink.wgink.annotation.CheckEmptyAnnotation;
import ink.wgink.annotation.CheckListAnnotation;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.List;
/**
* @ClassName: SmsVO
* @Description: 短信
* @Author: WenG
* @Date: 2020-03-14 16:01
* @Version: 1.0
**/
@ApiModel
public class SmsPhoneSendVO {
@ApiModelProperty(name = "phones", value = "手机列表", required = true)
@CheckListAnnotation(name = "手机列表")
private List<String> phones;
@ApiModelProperty(name = "content", value = "发送内容", required = true)
@CheckEmptyAnnotation(name = "发送内容")
private String content;
@ApiModelProperty(name = "sendUserId", value = "发送人用户ID", required = true)
@CheckEmptyAnnotation(name = "发送人用户ID")
private String sendUserId;
@ApiModelProperty(name = "sendUserUsername", value = "发送人用户名", required = true)
@CheckEmptyAnnotation(name = "发送人用户名")
private String sendUserUsername;
@ApiModelProperty(name = "sendUserName", value = "发送人昵称", required = true)
@CheckEmptyAnnotation(name = "发送人昵称")
private String sendUserName;
public List<String> getPhones() {
return phones;
}
public void setPhones(List<String> phones) {
this.phones = phones;
}
public String getContent() {
return content == null ? "" : content.trim();
}
public void setContent(String content) {
this.content = content;
}
public String getSendUserId() {
return sendUserId == null ? "" : sendUserId.trim();
}
public void setSendUserId(String sendUserId) {
this.sendUserId = sendUserId;
}
public String getSendUserUsername() {
return sendUserUsername == null ? "" : sendUserUsername.trim();
}
public void setSendUserUsername(String sendUserUsername) {
this.sendUserUsername = sendUserUsername;
}
public String getSendUserName() {
return sendUserName == null ? "" : sendUserName.trim();
}
public void setSendUserName(String sendUserName) {
this.sendUserName = sendUserName;
}
}

View File

@ -3,6 +3,7 @@ package ink.wgink.module.sms.service.sms;
import ink.wgink.interfaces.sms.ISmsBaseService;
import ink.wgink.module.sms.pojo.dtos.sms.SmsDTO;
import ink.wgink.module.sms.pojo.pos.sms.SmsPO;
import ink.wgink.module.sms.pojo.vos.sms.SmsPhoneSendVO;
import ink.wgink.module.sms.pojo.vos.sms.SmsSendVO;
import ink.wgink.module.sms.pojo.vos.sms.SmsVO;
import ink.wgink.pojo.ListPage;
@ -110,6 +111,13 @@ public interface ISmsService extends ISmsBaseService {
*/
void send(SmsSendVO smsSendVO);
/**
* 新增短信
*
* @param smsPhoneSendVO
*/
void sendByPhones(SmsPhoneSendVO smsPhoneSendVO);
/**
* 发送短信列表
*
@ -134,4 +142,5 @@ public interface ISmsService extends ISmsBaseService {
* @return
*/
List<SmsPO> listPOByStartTimeAndEndTime(String startTime, String endTime);
}

View File

@ -11,6 +11,7 @@ import ink.wgink.module.sms.factory.sms.SmsSendFactory;
import ink.wgink.module.sms.manager.VerifyCodeManager;
import ink.wgink.module.sms.pojo.dtos.sms.SmsDTO;
import ink.wgink.module.sms.pojo.pos.sms.SmsPO;
import ink.wgink.module.sms.pojo.vos.sms.SmsPhoneSendVO;
import ink.wgink.module.sms.pojo.vos.sms.SmsSendVO;
import ink.wgink.module.sms.pojo.vos.sms.SmsVO;
import ink.wgink.module.sms.service.sms.ISmsService;
@ -170,6 +171,18 @@ public class SmsServiceImpl extends DefaultBaseService implements ISmsService {
}, 3, TimeUnit.SECONDS);
}
@Override
public void sendByPhones(SmsPhoneSendVO smsPhoneSendVO) {
for (String phone : smsPhoneSendVO.getPhones()) {
if (!RegexUtil.isPhone(phone)) {
throw new ParamsException(phone + " 不是手机号");
}
}
scheduledExecutorService.schedule(() -> {
sendContentByUserIdAndPhoneAndUserName(smsPhoneSendVO.getSendUserId(), smsPhoneSendVO.getSendUserUsername(), smsPhoneSendVO.getSendUserName(), smsPhoneSendVO.getContent());
}, 3, TimeUnit.SECONDS);
}
@Override
public List<SmsPO> listPO(Map<String, Object> params) {
return smsDao.listPO(params);