REQ-2453: push的时候添加小米和oppo的渠道id

This commit is contained in:
yanglin 2024-06-24 14:52:29 +08:00
parent 3f35de7ee2
commit 000f10bc27
6 changed files with 164 additions and 30 deletions

View File

@ -19,7 +19,7 @@ import static java.util.stream.Collectors.toList;
@Data
@RefreshScope
@Configuration
@ConfigurationProperties(prefix = "message.im")
@ConfigurationProperties(prefix = "im")
public class ImMessageProps {
private String controllerToken = "123442";

View File

@ -0,0 +1,75 @@
package cn.axzo.msg.center.inside.notices.config;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Configuration;
/**
* @author yanglin
*/
@Data
@RefreshScope
@Configuration
@ConfigurationProperties(prefix = "upush.channels")
public class PushProps {
/**
* oppo渠道配置
*/
private ChannelConfig oppoChannelConfig = new ChannelConfig(
// 管理端
new ChannelIds("67a686e9", "38a2db69"),
// 工人端
new ChannelIds("203be53b", "3163b193"));
/**
* 小米渠道配置
*/
private ChannelConfig xiaomiChannelConfig = new ChannelConfig(
// 管理端
new ChannelIds("122345", "122346"),
// 工人端
new ChannelIds("122431", "122432"));
/**
* 不同app的渠道配置
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public static class ChannelConfig {
/**
* 管理端配置
*/
private ChannelIds managerIds;
/**
* 工人端配置
*/
private ChannelIds workerIds;
}
/**
* 不同渠道的channelId配置
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public static class ChannelIds {
/**
* 个人工作信息渠道
*/
private String workMessageChannelId;
/**
* 推广信息运营信息渠道
*/
private String opMessageChannelId;
}
}

View File

@ -1,17 +1,18 @@
package cn.axzo.msg.center.inside.notices.service.impl;
import cn.axzo.msg.center.inside.notices.service.IYouMengMessageService;
import cn.axzo.msg.center.inside.notices.service.umeng.UpushService;
import cn.axzo.framework.jackson.utility.JSON;
import cn.axzo.msg.center.api.request.MsgBody4Guest;
import cn.axzo.msg.center.api.response.Message;
import cn.hutool.json.JSONUtil;
import cn.axzo.msg.center.inside.notices.service.IYouMengMessageService;
import cn.axzo.msg.center.inside.notices.service.umeng.UpushService;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.HashMap;
/**
* 友盟发送app系统消息
@ -39,13 +40,20 @@ public class IYouMengMessageServiceImpl implements IYouMengMessageService {
msg.setAudio(extraData.getString("audio"));
msg.setMsgId(extraData.getLong("msgId"));
msg.setType(extraData.getInteger("type"));
HashMap<String, Object> sendObjects = new HashMap<>();
sendObjects.put("msg", msg);
sendObjects.put("msgFromClient", msgFromClient);
sendObjects.put("extraData", extraData);
boolean success = false;
try {
log.info("youmeng push msg= [{}]", JSONUtil.toJsonStr(msg));
upushService.sendAndroidCustomizedcast(msg, msgFromClient, extraData);
msg.setRouter(extraData.getString("ir"));
upushService.sendIOSCustomizedcast(msg, msgFromClient, extraData);
success = true;
} catch (Exception e) {
log.error("推送消息发送失败:{}", e.getMessage());
} finally {
log.info("send youmeng push, success={}, sendObjects={}", success, JSON.toJSONString(sendObjects));
}
}

View File

@ -3,18 +3,23 @@ package cn.axzo.msg.center.inside.notices.service.umeng;
import cn.axzo.msg.center.api.request.MsgBody4Guest;
import cn.axzo.msg.center.api.response.Message;
import cn.axzo.msg.center.inside.notices.config.PushProps;
import cn.axzo.msg.center.inside.notices.config.PushProps.ChannelConfig;
import cn.axzo.msg.center.inside.notices.config.PushProps.ChannelIds;
import cn.axzo.msg.center.inside.notices.service.umeng.android.AndroidCustomizedcast;
import cn.axzo.msg.center.inside.notices.service.umeng.ios.IOSCustomizedcast;
import cn.hutool.core.util.NumberUtil;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
/**
* 友盟推送服务
@ -42,9 +47,10 @@ public class UpushService {
private String cmIosAppkey;
@Value("${upush.cm.ios.secret}")
private String cmIosSecret;
@Value("${upush.profile}")
private String profile;
@Autowired
private PushProps pushProps;
private String timestamp = null;
private PushClient client = new PushClient();
@ -97,7 +103,7 @@ public class UpushService {
throws Exception {
AndroidCustomizedcast customizedcast;
if (Objects.nonNull(msgFromClient.getAppClient()) && "cmp".equals(msgFromClient.getAppClient())) {
if (msgFromClient.isForCmp()) {
customizedcast = new AndroidCustomizedcast(cmpAndroidAppkey, cmpAndroidSecret);
} else {
if (message.getToId().startsWith("cmp")) {
@ -170,12 +176,29 @@ public class UpushService {
customizedcast.setChannelProperties(UmengNotification.ChannelProperties.builder()
.huaweiChannelCategory(HUAWEI_CHANNEL_CATEGORY.get(msgFromClient.getPushType()))
.huaweiChannelImportance(HUAWEI_CHANNEL_IMPORTANCE.get(msgFromClient.getPushType()))
.oppoChannelId(determineChannelId(pushProps.getOppoChannelConfig(), msgFromClient))
.xiaomiChannelId(determineChannelId(pushProps.getXiaomiChannelConfig(), msgFromClient))
.vivoCategory(VIVO_CATEGORY.get(msgFromClient.getPushType()))
.build());
}
client.send(customizedcast);
}
private String determineChannelId(ChannelConfig cfg, MsgBody4Guest request) {
Function<ChannelIds, String> channelSelector = channelIds -> {
if (request.isWorkMessage()) {
return channelIds.getWorkMessageChannelId();
} else if (request.isOpMessage()) {
return channelIds.getOpMessageChannelId();
}
return null;
};
if (request.isForCmp()) {
return channelSelector.apply(cfg.getManagerIds());
} else {
return channelSelector.apply(cfg.getWorkerIds());
}
}
public void sendIOSCustomizedcast(Message message, MsgBody4Guest msgFromClient, com.alibaba.fastjson.JSONObject extraData)
throws Exception {

View File

@ -12,7 +12,6 @@ import cn.axzo.msg.center.inside.notices.service.impl.TodoSearchService;
import cn.axzo.msg.center.inside.notices.service.impl.v3.MessageRecordServiceV3;
import cn.axzo.msg.center.message.domain.param.PendingMessagePushParam;
import cn.axzo.msg.center.message.service.group.GroupTemplateService;
import cn.axzo.msg.center.message.service.impl.oldmsg.OldMsgStatCache;
import cn.axzo.msg.center.message.service.impl.person.PersonService;
import cn.axzo.msg.center.message.service.todo.manage.TodoManager;
import cn.axzo.msg.center.message.xxl.MigrateOldMsgHotDataJob;
@ -20,20 +19,30 @@ import cn.axzo.msg.center.notices.manager.api.MessageTemplateManager;
import cn.axzo.msg.center.notices.manager.api.dto.request.plat.CreateTemplateRequestDto;
import cn.axzo.msg.center.notices.service.api.PlatService;
import cn.axzo.trade.web.annotation.EnableResponseAdvice;
import com.alibaba.cloud.nacos.NacosConfigManager;
import com.alibaba.cloud.nacos.parser.NacosDataParserHandler;
import com.google.common.collect.Sets;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.bootstrap.config.BootstrapPropertySource;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.PropertySource;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.SafeConstructor;
import org.yaml.snakeyaml.nodes.Tag;
import org.yaml.snakeyaml.representer.Representer;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;
import static java.util.stream.Collectors.toMap;
/**
* @author syl
@ -49,13 +58,12 @@ public class PrivateMessageController {
private final TodoSearchService todoSearchService;
private final TodoManager todoManager;
private final GroupTemplateService groupTemplateService;
private final OldMsgStatCache oldMsgStatCache;
private final NacosConfigManager nacosConfigManager;
private final MigrateOldMsgHotDataJob migrateOldMsgHotDataJob;
private final PersonService personService;
private final IMService imService;
private final MessageTemplateManager messageTemplateManager;
private final PlatService platService;
private final ConfigurableEnvironment configurableEnvironment;
@PostMapping("/sendPendingMessage")
@EnableResponseAdvice(enable = false)
@ -93,12 +101,6 @@ public class PrivateMessageController {
return groupTemplateService.collectTemplateCodes(groupNodeCode);
}
@PostMapping("/reloadOldMsgStat")
@EnableResponseAdvice(enable = false)
public Object reloadOldMsgStat(@RequestParam("personId") Long personId) throws Exception {
return oldMsgStatCache.reloadBackground(Sets.newHashSet(personId));
}
@PostMapping("/getPersonIdByPhone")
@EnableResponseAdvice(enable = false)
public Object getPersonIdByPhone(@RequestParam("phone") String phone) {
@ -117,15 +119,17 @@ public class PrivateMessageController {
@PostMapping("/readNacosConfig")
@EnableResponseAdvice(enable = false)
public Object readNacosConfig() throws Exception {
String value = nacosConfigManager.getConfigService()
.getConfig("msg-center.yaml", "DEFAULT_GROUP", 5000);
List<PropertySource<?>> sources = NacosDataParserHandler.getInstance()
.parseNacosData("msg-center.yaml", value, "yaml");
if (sources == null) return null;
return sources.stream()
.map(PropertySource::getSource)
.findFirst()
.orElse(null);
DumperOptions options = new DumperOptions();
options.setPrettyFlow(true);
options.setSplitLines(true);
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
Map<String, ?> map = configurableEnvironment.getPropertySources().stream()
.filter(source -> source instanceof BootstrapPropertySource)
.collect(toMap(PropertySource::getName, PropertySource::getSource));
YAMLFactory yamlFactory = new YAMLFactory()
.disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER)
.disable(YAMLGenerator.Feature.LITERAL_BLOCK_STYLE);
return new ObjectMapper(yamlFactory).writeValueAsString(map);
}
@PostMapping("/migrateOldMsgHotData")

View File

@ -2,12 +2,15 @@
package cn.axzo.msg.center.api.request;
import com.alibaba.fastjson.JSON;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import java.util.Objects;
/**
* @author 王煜皓
* @date 2020/10/14 11:52
@ -62,7 +65,28 @@ public class MsgBody4Guest {
private Long ouId;
/**
* push类型system系统消息op(运营消息)
* push类型: system(系统消息)op(运营消息)
*/
private String pushType;
public boolean isWorkMessage() {
return "system".equals(pushType);
}
public boolean isOpMessage() {
return "op".equals(pushType);
}
public boolean isForCmp() {
return "cmp".equals(appClient);
}
public boolean isForCm() {
return "cm".equals(appClient);
}
@Override
public String toString() {
return JSON.toJSONString(this);
}
}