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

master
3y 2 years ago
parent bfd48a9700
commit c0c1bdc699

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

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

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

@ -154,7 +154,7 @@ public class PushHandler extends BaseHandler implements Handler {
SendPushParam param = SendPushParam.builder()
.requestId(String.valueOf(IdUtil.getSnowflake().nextId()))
.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();
if (CollUtil.isNotEmpty(cid)) {

@ -7,6 +7,7 @@ import com.alibaba.fastjson.JSONArray;
import com.google.common.base.Throwables;
import com.java3y.austin.common.constant.CommonConstant;
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.enums.ChannelType;
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.SmsRecord;
import com.java3y.austin.support.service.ConfigService;
import com.java3y.austin.support.utils.AccountUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.*;
/**
*
@ -48,6 +48,14 @@ public class SmsHandler extends BaseHandler implements Handler {
@Autowired
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_PREFIX = "message_type_";
@ -63,9 +71,10 @@ public class SmsHandler extends BaseHandler implements Handler {
* 1
* 2
*/
MessageTypeSmsConfig[] messageTypeSmsConfigs = loadBalance(getMessageTypeSmsConfig(taskInfo.getMsgType()));
MessageTypeSmsConfig[] messageTypeSmsConfigs = loadBalance(getMessageTypeSmsConfig(taskInfo));
for (MessageTypeSmsConfig messageTypeSmsConfig : messageTypeSmsConfigs) {
smsParam.setScriptName(messageTypeSmsConfig.getScriptName());
smsParam.setSendAccountId(messageTypeSmsConfig.getSendAccount());
List<SmsRecord> recordList = smsScripts.get(messageTypeSmsConfig.getScriptName()).send(smsParam);
if (CollUtil.isNotEmpty(recordList)) {
smsRecordDao.saveAll(recordList);
@ -115,7 +124,9 @@ public class SmsHandler extends BaseHandler implements Handler {
}
/**
* ()
*
* <p>
* ()
* <p>
*
* keymsgTypeSmsConfig
@ -124,20 +135,31 @@ public class SmsHandler extends BaseHandler implements Handler {
* YunPianSmsScript
* TencentSmsScript
*
* @param msgType
* @param taskInfo
* @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);
JSONArray jsonArray = JSON.parseArray(property);
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)) {
List<MessageTypeSmsConfig> result = JSON.parseArray(JSON.toJSONString(array), MessageTypeSmsConfig.class);
return result;
return JSON.parseArray(JSON.toJSONString(array), MessageTypeSmsConfig.class);
}
}
return null;
return new ArrayList<>();
}
/**

@ -46,7 +46,8 @@ public class TencentSmsScript implements SmsScript {
@Override
public List<SmsRecord> send(SmsParam smsParam) {
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);
SendSmsRequest request = assembleSendReq(smsParam, tencentSmsAccount);
SendSmsResponse response = client.SendSms(request);

@ -38,7 +38,8 @@ public class YunPianSmsScript implements SmsScript {
public List<SmsRecord> send(SmsParam smsParam) {
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);
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())) {
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());
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 {
//upload();
String fmnBLE4QtkwlErXIAh9pYS029GZk = getFileUrl("FmnBLE4QtkwlErXIAh9pYS029GZk");
System.out.println(fmnBLE4QtkwlErXIAh9pYS029GZk);
String s = getFileUrl("FmnBLE4QtkwlErXIAh9pYS029GZk");
System.out.println(s);
}
private static void upload() {
//构造一个带指定 Region 对象的配置类
Configuration cfg = new Configuration(Region.autoRegion());
cfg.resumableUploadAPIVersion = Configuration.ResumableUploadAPIVersion.V2;// 指定分片上传版本
// 指定分片上传版本
cfg.resumableUploadAPIVersion = Configuration.ResumableUploadAPIVersion.V2;
//...其他参数参考类注释
UploadManager uploadManager = new UploadManager(cfg);

@ -66,7 +66,7 @@ public class ChannelAccountController {
creator = StrUtil.isBlank(creator) ? AustinConstant.DEFAULT_CREATOR : 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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Objects;
/**

@ -203,7 +203,7 @@ public class MessageTemplateController {
file.transferTo(localFile);
} catch (Exception e) {
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}});
}

@ -33,7 +33,7 @@ public class ExceptionHandlerAdvice {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
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);
return result;
}

@ -9,6 +9,7 @@ import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
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.support.domain.ChannelAccount;
import com.java3y.austin.support.domain.SmsRecord;
@ -361,8 +362,12 @@ public class Convert4Amis {
*
* @return
*/
public static List<CommonAmisVo> getChannelAccountVo(List<ChannelAccount> channelAccounts) {
public static List<CommonAmisVo> getChannelAccountVo(List<ChannelAccount> channelAccounts, Integer channelType) {
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) {
CommonAmisVo commonAmisVo = CommonAmisVo.builder().label(channelAccount.getName()).value(String.valueOf(channelAccount.getId())).build();
result.add(commonAmisVo);

Loading…
Cancel
Save