|
|
@ -4,11 +4,14 @@ import com.mashibing.api.pojo.SingleSendRequest;
|
|
|
|
import com.mashibing.api.pojo.SingleSendResponse;
|
|
|
|
import com.mashibing.api.pojo.SingleSendResponse;
|
|
|
|
import com.mashibing.api.service.SmsService;
|
|
|
|
import com.mashibing.api.service.SmsService;
|
|
|
|
import com.mashibing.api.service.sendCheck.SendCheckContext;
|
|
|
|
import com.mashibing.api.service.sendCheck.SendCheckContext;
|
|
|
|
|
|
|
|
import com.mashibing.common.constant.RabbitMQConstant;
|
|
|
|
import com.mashibing.common.pojo.JsonResult;
|
|
|
|
import com.mashibing.common.pojo.JsonResult;
|
|
|
|
import com.mashibing.common.pojo.StandardSubmit;
|
|
|
|
import com.mashibing.common.pojo.StandardSubmit;
|
|
|
|
import com.mashibing.common.utils.JsonResultUtil;
|
|
|
|
import com.mashibing.common.utils.JsonResultUtil;
|
|
|
|
import com.mashibing.common.utils.SnowFlakeUtil;
|
|
|
|
import com.mashibing.common.utils.SnowFlakeUtil;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
|
|
import org.springframework.amqp.rabbit.connection.CorrelationData;
|
|
|
|
|
|
|
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
|
|
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
|
|
@ -41,9 +44,12 @@ public class SMSController {
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
SmsService smsService;
|
|
|
|
SmsService smsService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
RabbitTemplate rabbitTemplate;
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("singleSend")
|
|
|
|
@PostMapping("singleSend")
|
|
|
|
public JsonResult singleSend(@RequestBody @Validated SingleSendRequest request, HttpServletRequest httpServletRequest) {
|
|
|
|
public JsonResult singleSend(@RequestBody @Validated SingleSendRequest request, HttpServletRequest httpServletRequest) {
|
|
|
|
//获取真实ip
|
|
|
|
// 获取真实ip
|
|
|
|
String realIp = smsService.getRealIP(httpServletRequest);
|
|
|
|
String realIp = smsService.getRealIP(httpServletRequest);
|
|
|
|
|
|
|
|
|
|
|
|
log.info("获取到客户端真实IP: {}", realIp);
|
|
|
|
log.info("获取到客户端真实IP: {}", realIp);
|
|
|
@ -53,17 +59,19 @@ public class SMSController {
|
|
|
|
standardSubmit.setRealIp(realIp);
|
|
|
|
standardSubmit.setRealIp(realIp);
|
|
|
|
BeanUtils.copyProperties(request, standardSubmit);
|
|
|
|
BeanUtils.copyProperties(request, standardSubmit);
|
|
|
|
|
|
|
|
|
|
|
|
//责任链校验
|
|
|
|
// 责任链校验
|
|
|
|
sendCheckContext.check(standardSubmit);
|
|
|
|
sendCheckContext.check(standardSubmit);
|
|
|
|
|
|
|
|
|
|
|
|
//雪花算法生成唯一id
|
|
|
|
// 雪花算法生成唯一id
|
|
|
|
standardSubmit.setSequenceId(snowFlakeUtil.nextId());
|
|
|
|
standardSubmit.setSequenceId(snowFlakeUtil.nextId());
|
|
|
|
|
|
|
|
|
|
|
|
//TODO 发送到MQ
|
|
|
|
// 发送到MQ
|
|
|
|
|
|
|
|
rabbitTemplate.convertAndSend(RabbitMQConstant.SMS_PRE_SEND, standardSubmit,
|
|
|
|
|
|
|
|
new CorrelationData(String.valueOf(standardSubmit.getSequenceId())));
|
|
|
|
|
|
|
|
|
|
|
|
SingleSendResponse singleSendResponse = new SingleSendResponse();
|
|
|
|
SingleSendResponse singleSendResponse = new SingleSendResponse();
|
|
|
|
singleSendResponse.setCode(0);
|
|
|
|
singleSendResponse.setCode(0);
|
|
|
|
singleSendResponse.setMsg("发送中。。。");
|
|
|
|
singleSendResponse.setMsg("接收成功");
|
|
|
|
singleSendResponse.setCount(1);
|
|
|
|
singleSendResponse.setCount(1);
|
|
|
|
return JsonResultUtil.ok(singleSendResponse);
|
|
|
|
return JsonResultUtil.ok(singleSendResponse);
|
|
|
|
}
|
|
|
|
}
|
|
|
|