短信渠道支持指定账号推送

master
3y 2 years ago
parent bfd48a9700
commit c0c1bdc699

@ -22,6 +22,11 @@ public class MessageTypeSmsConfig {
*/ */
private Integer weights; private Integer weights;
/**
*
*/
private Integer sendAccount;
/** /**
* script * script
*/ */

@ -24,12 +24,20 @@ public class SmsParam {
*/ */
private Set<String> phones; private Set<String> phones;
/**
* id
* <p>
* idid
* id com.java3y.austin.handler.domain.sms.SmsParam#scriptName
*/
private Integer sendAccountId;
/** /**
* *
*/ */
private String scriptName; private String scriptName;
/** /**
* *
*/ */

@ -24,6 +24,7 @@ import org.springframework.stereotype.Component;
import java.io.File; import java.io.File;
import java.util.Objects; import java.util.Objects;
/** /**
* *
* *

@ -154,7 +154,7 @@ public class PushHandler extends BaseHandler implements Handler {
SendPushParam param = SendPushParam.builder() SendPushParam param = SendPushParam.builder()
.requestId(String.valueOf(IdUtil.getSnowflake().nextId())) .requestId(String.valueOf(IdUtil.getSnowflake().nextId()))
.pushMessage(SendPushParam.PushMessageVO.builder().notification(SendPushParam.PushMessageVO.NotificationVO.builder() .pushMessage(SendPushParam.PushMessageVO.builder().notification(SendPushParam.PushMessageVO.NotificationVO.builder()
.title(pushContentModel.getTitle()).body(pushContentModel.getContent()).clickType("startapp").build()) .title(pushContentModel.getTitle()).body(pushContentModel.getContent()).clickType("startapp").build())
.build()) .build())
.build(); .build();
if (CollUtil.isNotEmpty(cid)) { if (CollUtil.isNotEmpty(cid)) {

@ -7,6 +7,7 @@ import com.alibaba.fastjson.JSONArray;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import com.java3y.austin.common.constant.CommonConstant; import com.java3y.austin.common.constant.CommonConstant;
import com.java3y.austin.common.domain.TaskInfo; import com.java3y.austin.common.domain.TaskInfo;
import com.java3y.austin.common.dto.account.sms.SmsAccount;
import com.java3y.austin.common.dto.model.SmsContentModel; import com.java3y.austin.common.dto.model.SmsContentModel;
import com.java3y.austin.common.enums.ChannelType; import com.java3y.austin.common.enums.ChannelType;
import com.java3y.austin.handler.domain.sms.MessageTypeSmsConfig; import com.java3y.austin.handler.domain.sms.MessageTypeSmsConfig;
@ -18,13 +19,12 @@ import com.java3y.austin.support.dao.SmsRecordDao;
import com.java3y.austin.support.domain.MessageTemplate; import com.java3y.austin.support.domain.MessageTemplate;
import com.java3y.austin.support.domain.SmsRecord; import com.java3y.austin.support.domain.SmsRecord;
import com.java3y.austin.support.service.ConfigService; import com.java3y.austin.support.service.ConfigService;
import com.java3y.austin.support.utils.AccountUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.List; import java.util.*;
import java.util.Map;
import java.util.Random;
/** /**
* *
@ -48,6 +48,14 @@ public class SmsHandler extends BaseHandler implements Handler {
@Autowired @Autowired
private Map<String, SmsScript> smsScripts; private Map<String, SmsScript> smsScripts;
@Autowired
private AccountUtils accountUtils;
/**
*
*/
private static final Integer AUTO_FLOW_RULE = 0;
private static final String FLOW_KEY = "msgTypeSmsConfig"; private static final String FLOW_KEY = "msgTypeSmsConfig";
private static final String FLOW_KEY_PREFIX = "message_type_"; private static final String FLOW_KEY_PREFIX = "message_type_";
@ -63,9 +71,10 @@ public class SmsHandler extends BaseHandler implements Handler {
* 1 * 1
* 2 * 2
*/ */
MessageTypeSmsConfig[] messageTypeSmsConfigs = loadBalance(getMessageTypeSmsConfig(taskInfo.getMsgType())); MessageTypeSmsConfig[] messageTypeSmsConfigs = loadBalance(getMessageTypeSmsConfig(taskInfo));
for (MessageTypeSmsConfig messageTypeSmsConfig : messageTypeSmsConfigs) { for (MessageTypeSmsConfig messageTypeSmsConfig : messageTypeSmsConfigs) {
smsParam.setScriptName(messageTypeSmsConfig.getScriptName()); smsParam.setScriptName(messageTypeSmsConfig.getScriptName());
smsParam.setSendAccountId(messageTypeSmsConfig.getSendAccount());
List<SmsRecord> recordList = smsScripts.get(messageTypeSmsConfig.getScriptName()).send(smsParam); List<SmsRecord> recordList = smsScripts.get(messageTypeSmsConfig.getScriptName()).send(smsParam);
if (CollUtil.isNotEmpty(recordList)) { if (CollUtil.isNotEmpty(recordList)) {
smsRecordDao.saveAll(recordList); smsRecordDao.saveAll(recordList);
@ -115,7 +124,9 @@ public class SmsHandler extends BaseHandler implements Handler {
} }
/** /**
* () *
* <p>
* ()
* <p> * <p>
* *
* keymsgTypeSmsConfig * keymsgTypeSmsConfig
@ -124,20 +135,31 @@ public class SmsHandler extends BaseHandler implements Handler {
* YunPianSmsScript * YunPianSmsScript
* TencentSmsScript * TencentSmsScript
* *
* @param msgType * @param taskInfo
* @return * @return
*/ */
private List<MessageTypeSmsConfig> getMessageTypeSmsConfig(Integer msgType) { private List<MessageTypeSmsConfig> getMessageTypeSmsConfig(TaskInfo taskInfo) {
/**
* 使
*/
if (!taskInfo.getSendAccount().equals(AUTO_FLOW_RULE)) {
SmsAccount account = accountUtils.getAccountById(taskInfo.getSendAccount(), SmsAccount.class);
return Arrays.asList(MessageTypeSmsConfig.builder().sendAccount(taskInfo.getSendAccount()).scriptName(account.getScriptName()).weights(100).build());
}
/**
*
*/
String property = config.getProperty(FLOW_KEY, CommonConstant.EMPTY_VALUE_JSON_ARRAY); String property = config.getProperty(FLOW_KEY, CommonConstant.EMPTY_VALUE_JSON_ARRAY);
JSONArray jsonArray = JSON.parseArray(property); JSONArray jsonArray = JSON.parseArray(property);
for (int i = 0; i < jsonArray.size(); i++) { for (int i = 0; i < jsonArray.size(); i++) {
JSONArray array = jsonArray.getJSONObject(i).getJSONArray(FLOW_KEY_PREFIX + msgType); JSONArray array = jsonArray.getJSONObject(i).getJSONArray(FLOW_KEY_PREFIX + taskInfo.getMsgType());
if (CollUtil.isNotEmpty(array)) { if (CollUtil.isNotEmpty(array)) {
List<MessageTypeSmsConfig> result = JSON.parseArray(JSON.toJSONString(array), MessageTypeSmsConfig.class); return JSON.parseArray(JSON.toJSONString(array), MessageTypeSmsConfig.class);
return result;
} }
} }
return null; return new ArrayList<>();
} }
/** /**

@ -46,7 +46,8 @@ public class TencentSmsScript implements SmsScript {
@Override @Override
public List<SmsRecord> send(SmsParam smsParam) { public List<SmsRecord> send(SmsParam smsParam) {
try { try {
TencentSmsAccount tencentSmsAccount = accountUtils.getSmsAccountByScriptName(smsParam.getScriptName(), TencentSmsAccount.class); TencentSmsAccount tencentSmsAccount = Objects.nonNull(smsParam.getSendAccountId()) ? accountUtils.getAccountById(smsParam.getSendAccountId(), TencentSmsAccount.class)
: accountUtils.getSmsAccountByScriptName(smsParam.getScriptName(), TencentSmsAccount.class);
SmsClient client = init(tencentSmsAccount); SmsClient client = init(tencentSmsAccount);
SendSmsRequest request = assembleSendReq(smsParam, tencentSmsAccount); SendSmsRequest request = assembleSendReq(smsParam, tencentSmsAccount);
SendSmsResponse response = client.SendSms(request); SendSmsResponse response = client.SendSms(request);

@ -38,7 +38,8 @@ public class YunPianSmsScript implements SmsScript {
public List<SmsRecord> send(SmsParam smsParam) { public List<SmsRecord> send(SmsParam smsParam) {
try { try {
YunPianSmsAccount account = accountUtils.getSmsAccountByScriptName(smsParam.getScriptName(), YunPianSmsAccount.class); YunPianSmsAccount account = Objects.nonNull(smsParam.getSendAccountId()) ? accountUtils.getAccountById(smsParam.getSendAccountId(), YunPianSmsAccount.class)
: accountUtils.getSmsAccountByScriptName(smsParam.getScriptName(), YunPianSmsAccount.class);
Map<String, Object> params = assembleParam(smsParam, account); Map<String, Object> params = assembleParam(smsParam, account);
String result = HttpRequest.post(account.getUrl()) String result = HttpRequest.post(account.getUrl())

@ -51,7 +51,7 @@ public class ShieldServiceImpl implements ShieldService {
} }
if (ShieldType.NIGHT_SHIELD_BUT_NEXT_DAY_SEND.getCode().equals(taskInfo.getShieldType())) { if (ShieldType.NIGHT_SHIELD_BUT_NEXT_DAY_SEND.getCode().equals(taskInfo.getShieldType())) {
redisUtils.lPush(NIGHT_SHIELD_BUT_NEXT_DAY_SEND_KEY, JSON.toJSONString(taskInfo, redisUtils.lPush(NIGHT_SHIELD_BUT_NEXT_DAY_SEND_KEY, JSON.toJSONString(taskInfo,
SerializerFeature.WriteClassName), SerializerFeature.WriteClassName),
(DateUtil.offsetDay(new Date(), 1).getTime() / 1000) - DateUtil.currentSeconds()); (DateUtil.offsetDay(new Date(), 1).getTime() / 1000) - DateUtil.currentSeconds());
logUtils.print(AnchorInfo.builder().state(AnchorState.NIGHT_SHIELD_NEXT_SEND.getCode()).businessId(taskInfo.getBusinessId()).ids(taskInfo.getReceiver()).build()); logUtils.print(AnchorInfo.builder().state(AnchorState.NIGHT_SHIELD_NEXT_SEND.getCode()).businessId(taskInfo.getBusinessId()).ids(taskInfo.getReceiver()).build());
} }

@ -21,14 +21,15 @@ public class OssUtils {
public static void main(String[] args) throws UnsupportedEncodingException { public static void main(String[] args) throws UnsupportedEncodingException {
//upload(); //upload();
String fmnBLE4QtkwlErXIAh9pYS029GZk = getFileUrl("FmnBLE4QtkwlErXIAh9pYS029GZk"); String s = getFileUrl("FmnBLE4QtkwlErXIAh9pYS029GZk");
System.out.println(fmnBLE4QtkwlErXIAh9pYS029GZk); System.out.println(s);
} }
private static void upload() { private static void upload() {
//构造一个带指定 Region 对象的配置类 //构造一个带指定 Region 对象的配置类
Configuration cfg = new Configuration(Region.autoRegion()); Configuration cfg = new Configuration(Region.autoRegion());
cfg.resumableUploadAPIVersion = Configuration.ResumableUploadAPIVersion.V2;// 指定分片上传版本 // 指定分片上传版本
cfg.resumableUploadAPIVersion = Configuration.ResumableUploadAPIVersion.V2;
//...其他参数参考类注释 //...其他参数参考类注释
UploadManager uploadManager = new UploadManager(cfg); UploadManager uploadManager = new UploadManager(cfg);

@ -66,7 +66,7 @@ public class ChannelAccountController {
creator = StrUtil.isBlank(creator) ? AustinConstant.DEFAULT_CREATOR : creator; creator = StrUtil.isBlank(creator) ? AustinConstant.DEFAULT_CREATOR : creator;
List<ChannelAccount> channelAccounts = channelAccountService.queryByChannelType(channelType, creator); List<ChannelAccount> channelAccounts = channelAccountService.queryByChannelType(channelType, creator);
return Convert4Amis.getChannelAccountVo(channelAccounts); return Convert4Amis.getChannelAccountVo(channelAccounts, channelType);
} }
/** /**

@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.Objects; import java.util.Objects;
/** /**

@ -203,7 +203,7 @@ public class MessageTemplateController {
file.transferTo(localFile); file.transferTo(localFile);
} catch (Exception e) { } catch (Exception e) {
log.error("MessageTemplateController#upload fail! e:{},params{}", Throwables.getStackTraceAsString(e), JSON.toJSONString(file)); log.error("MessageTemplateController#upload fail! e:{},params{}", Throwables.getStackTraceAsString(e), JSON.toJSONString(file));
throw new CommonException(RespStatusEnum.SERVICE_ERROR); throw new CommonException(RespStatusEnum.SERVICE_ERROR);
} }
return MapUtil.of(new String[][]{{"value", filePath}}); return MapUtil.of(new String[][]{{"value", filePath}});
} }

@ -33,7 +33,7 @@ public class ExceptionHandlerAdvice {
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw); PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw); e.printStackTrace(pw);
BasicResultVO result = BasicResultVO.fail(RespStatusEnum.ERROR_500,"\r\n" + sw + "\r\n"); BasicResultVO result = BasicResultVO.fail(RespStatusEnum.ERROR_500, "\r\n" + sw + "\r\n");
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
return result; return result;
} }

@ -9,6 +9,7 @@ import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.java3y.austin.common.enums.AnchorState; import com.java3y.austin.common.enums.AnchorState;
import com.java3y.austin.common.enums.ChannelType;
import com.java3y.austin.common.enums.SmsStatus; import com.java3y.austin.common.enums.SmsStatus;
import com.java3y.austin.support.domain.ChannelAccount; import com.java3y.austin.support.domain.ChannelAccount;
import com.java3y.austin.support.domain.SmsRecord; import com.java3y.austin.support.domain.SmsRecord;
@ -361,8 +362,12 @@ public class Convert4Amis {
* *
* @return * @return
*/ */
public static List<CommonAmisVo> getChannelAccountVo(List<ChannelAccount> channelAccounts) { public static List<CommonAmisVo> getChannelAccountVo(List<ChannelAccount> channelAccounts, Integer channelType) {
List<CommonAmisVo> result = new ArrayList<>(); List<CommonAmisVo> result = new ArrayList<>();
if (ChannelType.SMS.getCode().equals(channelType)) {
CommonAmisVo commonAmisVo = CommonAmisVo.builder().label("AUTO").value("0").build();
result.add(commonAmisVo);
}
for (ChannelAccount channelAccount : channelAccounts) { for (ChannelAccount channelAccount : channelAccounts) {
CommonAmisVo commonAmisVo = CommonAmisVo.builder().label(channelAccount.getName()).value(String.valueOf(channelAccount.getId())).build(); CommonAmisVo commonAmisVo = CommonAmisVo.builder().label(channelAccount.getName()).value(String.valueOf(channelAccount.getId())).build();
result.add(commonAmisVo); result.add(commonAmisVo);

Loading…
Cancel
Save