REQ-3284: 推送

This commit is contained in:
yanglin 2024-11-27 20:27:27 +08:00
parent 9676faf898
commit d276a5c6a5
22 changed files with 321 additions and 87 deletions

View File

@ -1,6 +1,7 @@
package cn.axzo.msg.center.inside.notices.service.impl.v3.msg;
import cn.axzo.framework.jackson.utility.JSON;
import cn.axzo.im.center.api.feign.MessageApi;
import cn.axzo.im.center.api.vo.req.SendTemplateMessageParam;
import cn.axzo.im.center.api.vo.req.SendTemplateMessageParam.ReceivePerson;
import cn.axzo.im.center.common.enums.AppTypeEnum;
@ -8,12 +9,14 @@ import cn.axzo.msg.center.api.enums.MsgStateV3Enum;
import cn.axzo.msg.center.api.request.v4.MessageSendBasicInfoV4;
import cn.axzo.msg.center.api.request.v4.MessageSendRequestV4;
import cn.axzo.msg.center.common.enums.TableIsDeleteEnum;
import cn.axzo.msg.center.common.utils.BizAssertions;
import cn.axzo.msg.center.common.utils.PlaceholderResolver;
import cn.axzo.msg.center.domain.entity.MessageRecordV3;
import cn.axzo.msg.center.message.domain.dto.TemplateModelV3;
import cn.axzo.msg.center.message.domain.vo.GeneralMessagePushVO;
import cn.axzo.msg.center.message.service.impl.v3.ModelV3Parser;
import cn.axzo.msg.center.nimpush.NimPushService;
import cn.axzo.msg.center.nimpush.PushPeer;
import cn.axzo.msg.center.service.dto.PersonV3DTO;
import cn.axzo.msg.center.service.enums.Channel;
import cn.axzo.msg.center.service.enums.OrganizationTypeEnum;
@ -168,7 +171,14 @@ public class TemplateMessage {
ModelV3Parser modelV3Parser = beanFactory.getBean(ModelV3Parser.class);
ParsedModelV3 parsedModelV3 = modelV3Parser.parseModelNoRequestContext(templateModel, sample);
NimPushService nimPushService = beanFactory.getBean(NimPushService.class);
return nimPushService.buildPayloadString(parsedModelV3, appType);
MessageApi messageApi = beanFactory.getBean(MessageApi.class);
String imSenderAccount = BizAssertions.assertResponse(
messageApi.findTemplateRobotImAccount(getTemplateCode()));
PushPeer peer = new PushPeer();
peer.setSenderImAccount(imSenderAccount);
peer.setOuId(sample.getReceiverOuId());
peer.setWorkspaceId(sample.getReceiverWorkspaceId());
return nimPushService.buildPayloadString(parsedModelV3, peer, appType);
}
// ------------------------------- 辅助方法

View File

@ -2,6 +2,7 @@ package cn.axzo.msg.center.message.controller;
import cn.axzo.msg.center.api.MNSNoticesApi;
import cn.axzo.msg.center.api.MessageAPIV3;
import cn.axzo.msg.center.api.MessageAPIV4;
import cn.axzo.msg.center.api.mq.PresetButtonPressedMessage;
import cn.axzo.msg.center.api.request.AddMnsChannelRequest;
import cn.axzo.msg.center.api.request.MnsSendCodeV2Req;
@ -13,6 +14,7 @@ import cn.axzo.msg.center.api.request.v3.SearchPendingMessageReq;
import cn.axzo.msg.center.api.request.v3.SearchTodoLogReq;
import cn.axzo.msg.center.api.request.v3.SetImSendPriorityRequest;
import cn.axzo.msg.center.api.request.v3.UpdateMnsChannelTemplateRequest;
import cn.axzo.msg.center.api.request.v4.MessageSendRequestV4;
import cn.axzo.msg.center.dal.MNSMessageTemplateDao;
import cn.axzo.msg.center.domain.entity.MNSMessageTemplate;
import cn.axzo.msg.center.im.service.IMService;
@ -65,6 +67,7 @@ public class PrivateMessageController {
private final MessageRecordServiceV3 messageRecordServiceV3;
private final MessageAPIV3 messageAPIV3;
private final MessageAPIV4 messageAPIV4;
private final TodoSearchService todoSearchService;
private final TodoManager todoManager;
private final GroupTemplateService groupTemplateService;
@ -91,12 +94,18 @@ public class PrivateMessageController {
return todoManager.revokeByTemplateCode(request);
}
@PostMapping("/sendByEventMapping")
@PostMapping("/sendByEventMappingV3")
@EnableResponseAdvice(enable = false)
public Object sendByEventMapping(@RequestBody @Valid MessageSendReqV3 request) {
public Object sendByEventMappingV3(@RequestBody @Valid MessageSendReqV3 request) {
return messageAPIV3.send(request);
}
@PostMapping("/sendByEventMappingV4")
@EnableResponseAdvice(enable = false)
public Object sendByEventMappingV4(@RequestBody @Valid MessageSendRequestV4 request) {
return messageAPIV4.send(request);
}
@PostMapping("/searchImRecord")
@EnableResponseAdvice(enable = false)
public Object searchImRecord(@RequestBody @Valid SearchMessageReqV3 req) {

View File

@ -5,6 +5,7 @@ import cn.axzo.im.center.api.feign.MessageApi;
import cn.axzo.im.center.api.vo.req.CustomMessageInfo;
import cn.axzo.im.center.api.vo.resp.MessageCustomResp;
import cn.axzo.im.center.common.enums.AppTypeEnum;
import cn.axzo.msg.center.common.utils.BizAssertions;
import cn.axzo.msg.center.domain.entity.Todo;
import cn.axzo.msg.center.inside.notices.config.PendingMessageBizConfig;
import cn.axzo.msg.center.inside.notices.service.impl.v3.msg.TerminalAppMapping;
@ -12,6 +13,7 @@ import cn.axzo.msg.center.message.service.impl.v3.ModelV3Parser;
import cn.axzo.msg.center.nimpush.NimPushService;
import cn.axzo.msg.center.nimpush.PushChannel;
import cn.axzo.msg.center.nimpush.PushExecutorConfig;
import cn.axzo.msg.center.nimpush.PushPeer;
import cn.axzo.msg.center.push.PushData;
import cn.axzo.msg.center.service.enums.PushTerminalEnum;
import cn.axzo.msg.center.service.pending.response.v3.model.ParsedModelV3;
@ -54,10 +56,16 @@ public class TodoPushSenderV3 implements ApplicationListener<NewTodoEvent> {
ParsedModelV3 parsedModelV3 = modelV3Parser
.parseModelNoRequestContext(
event.getTemplateModel(), event.getTodos().get(0));
String imSenderAccount = BizAssertions.assertResponse(messageApi.getCustomMessageSendImAccount());
for (Todo todo : event.getTodos()) {
executor.submit(() -> {
for (AppTypeEnum appType : appTypes) {
String payload = nimPushService.buildPayloadString(parsedModelV3, appType);
PushPeer peer = new PushPeer();
peer.setSenderImAccount(imSenderAccount);
peer.setOuId(todo.getOuId());
peer.setWorkspaceId(todo.getOrgId());
String payload = nimPushService.buildPayloadString(
parsedModelV3, peer, appType);
if (StringUtils.isBlank(payload))
continue;
CustomMessageInfo pushRequest = new CustomMessageInfo();

View File

@ -1,8 +1,11 @@
package cn.axzo.msg.center.nimpush;
import cn.axzo.im.center.common.enums.AppTypeEnum;
import cn.axzo.msg.center.common.utils.BizAssertions;
import cn.axzo.msg.center.inside.notices.config.PendingMessageBizConfig;
import cn.axzo.msg.center.nimpush.payload.PushPayloadBuilder;
import cn.axzo.msg.center.nimpush.payload.intent.Intent;
import cn.axzo.msg.center.nimpush.payload.intent.IntentValue;
import cn.axzo.msg.center.push.PushData;
import cn.axzo.msg.center.push.PushMessage;
import cn.axzo.msg.center.service.domain.UrlConfig;
@ -15,6 +18,7 @@ import org.springframework.beans.factory.ObjectProvider;
import org.springframework.stereotype.Service;
import javax.annotation.Nullable;
import java.util.function.Consumer;
/**
* @author yanglin
@ -22,28 +26,33 @@ import javax.annotation.Nullable;
@Service
public class NimPushService {
private final PushPayloadBuilder[] payloadBuilders;
private final PushPayloadBuilder<?>[] payloadBuilders;
private final PendingMessageBizConfig cfg;
public NimPushService(ObjectProvider<PushPayloadBuilder[]> builderProvider,
@SuppressWarnings("rawtypes")
public NimPushService(ObjectProvider<PushPayloadBuilder[]> payloadBuilders,
PendingMessageBizConfig cfg) {
this.payloadBuilders = builderProvider.getIfAvailable();
this.payloadBuilders = payloadBuilders.getIfAvailable();
this.cfg = cfg;
}
public String buildPayloadString(PushMessage message, AppTypeEnum appType) {
JSONObject payload = buildPayload(message, appType);
public String buildPayloadString(PushMessage message,
PushPeer peer,
AppTypeEnum appType) {
JSONObject payload = buildPayload(message, peer, appType);
return payload == null ? null : payload.toJSONString();
}
@Nullable
public JSONObject buildPayload(PushMessage message, AppTypeEnum appType) {
public JSONObject buildPayload(PushMessage message,
PushPeer peer,
AppTypeEnum appType) {
if (cfg.getPushChannel() != PushChannel.NIM) return null;
PushData pushData = message.getPushData();
if (pushData == null || !pushData.isSwitchOn()) return null;
PushContent content = new PushContent();
content.setTitle(message.getPushTitle());
content.setContent(message.getContent());
content.setContent(message.getPushContent());
content.setCustomSoundFile(pushData.getVoiceFile());
content.setAppType(appType);
content.setMessageTye(CodeDefinition
@ -51,7 +60,7 @@ public class NimPushService {
.orElse(null));
content.setCustomSoundFile(pushData.getVoiceFile());
populateUrl(content, message.getPushUrl(), appType);
return buildPayload(content);
return buildPayload(content, peer);
}
private void populateUrl(PushContent content,
@ -85,12 +94,25 @@ public class NimPushService {
});
}
private JSONObject buildPayload(PushContent content) {
@SuppressWarnings({"rawtypes", "unchecked"})
private JSONObject buildPayload(PushContent content, PushPeer peer) {
Consumer<Intent<?>> intentPopulator = intent -> {
intent.setValue("sessionType", IntentValue.SESSION_TYPE);
intent.setValue("type", IntentValue.TYPE);
intent.setValue("sessionId", IntentValue.create(peer.getSenderImAccount()));
if (peer.getOuId() != null && peer.getOuId() != 0L)
intent.setValue("ouId", IntentValue.create(peer.getOuId()));
if (peer.getWorkspaceId() != null && peer.getWorkspaceId() != 0L)
intent.setValue("workspaceId", IntentValue.create(peer.getWorkspaceId()));
};
JSONObject payload = new JSONObject();
payload.put("pushTitle", content.getTitle());
payload.put("random", System.currentTimeMillis());
for (PushPayloadBuilder builder : payloadBuilders)
builder.build(content, payload);
for (PushPayloadBuilder builder : payloadBuilders) {
Intent intent = builder.createIntent(content, peer);
BizAssertions.assertNotNull(intent, "intent can't be null");
intentPopulator.accept(intent);
builder.build(content, intent, payload);
}
return payload;
}

View File

@ -61,6 +61,12 @@ public class PushContent {
return StringUtils.isNotBlank(iosPushUrl);
}
public String determineAndroidCategory() {
return messageTye == PushMessageTye.OP
? "MARKETING"
: "IM";
}
public String determineChannelId(ChannelConfig channelConfig) {
ChannelIds channelIds = appType == AppTypeEnum.CM
? channelConfig.getWorkerIds()

View File

@ -0,0 +1,15 @@
package cn.axzo.msg.center.nimpush;
import lombok.Getter;
import lombok.Setter;
/**
* @author yanglin
*/
@Setter
@Getter
public class PushPeer {
private Long ouId;
private Long workspaceId;
private String senderImAccount;
}

View File

@ -0,0 +1,26 @@
package cn.axzo.msg.center.nimpush.payload;
import cn.axzo.msg.center.common.utils.BizAssertions;
import cn.axzo.msg.center.nimpush.PushContent;
import cn.axzo.msg.center.nimpush.PushPeer;
import cn.axzo.msg.center.nimpush.payload.intent.Intent;
import cn.axzo.msg.center.nimpush.payload.intent.IntentValue;
/**
* @author yanglin
*/
abstract class AndroidPushPayloadBuilder<T extends Intent<?>>
implements PushPayloadBuilder<T> {
@Override
public final T createIntent(PushContent content, PushPeer peer) {
T intent = createIntent();
BizAssertions.assertNotNull(intent, "intent can't be null");
if (content.hasAndroidPushUrl())
Intent.setRouter(intent, IntentValue.create(content.getAndroidPushUrl()));
return intent;
}
abstract T createIntent();
}

View File

@ -1,6 +1,7 @@
package cn.axzo.msg.center.nimpush.payload;
import cn.axzo.msg.center.nimpush.PushContent;
import cn.axzo.msg.center.nimpush.payload.intent.UriIntent;
import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Component;
@ -10,22 +11,26 @@ import org.springframework.stereotype.Component;
* @author yanglin
*/
@Component
public class HWPushPayloadBuilder implements PushPayloadBuilder {
class HWPushPayloadBuilder extends AndroidPushPayloadBuilder<UriIntent> {
@Override
public void build(PushContent content, JSONObject payload) {
UriIntent createIntent() {
return new UriIntent();
}
@Override
public void build(PushContent content, UriIntent intent, JSONObject payload) {
// 点击事件的内容
JSONObject clickAction = new JSONObject();
clickAction.put("type", 3);
//clickAction.put("intent", message.getAndroidPushUrl());
//clickAction.put("url", message.getAndroidPushUrl());
clickAction.put("type", 1);
clickAction.put("intent", intent.build());
// 通知的内容
JSONObject hwField = new JSONObject();
JSONObject androidConfig = new JSONObject();
androidConfig.put("category", "IM");
androidConfig.put("category", content.determineAndroidCategory());
JSONObject hwField = new JSONObject();
hwField.put("androidConfig", androidConfig);
hwField.put("style", 1);
hwField.put("big_title", content.getTitle());

View File

@ -1,26 +0,0 @@
package cn.axzo.msg.center.nimpush.payload;
import cn.axzo.msg.center.nimpush.PushContent;
import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Component;
/**
* 魅族
*
* @author yanglin
*/
@Component
public class MZPushPayloadBuilder implements PushPayloadBuilder {
@Override
public void build(PushContent content, JSONObject payload) {
if (!content.hasAndroidPushUrl()) return;
JSONObject clickTypeInfo = new JSONObject();
clickTypeInfo.put("clickType", 2);
clickTypeInfo.put("url", content.getAndroidPushUrl());
payload.put("clickTypeInfo", clickTypeInfo);
}
}

View File

@ -2,6 +2,7 @@ package cn.axzo.msg.center.nimpush.payload;
import cn.axzo.msg.center.inside.notices.config.PushProps;
import cn.axzo.msg.center.nimpush.PushContent;
import cn.axzo.msg.center.nimpush.payload.intent.JsonIntent;
import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
@ -11,21 +12,25 @@ import org.springframework.stereotype.Component;
*/
@Component
@RequiredArgsConstructor
public class OppoPushPayloadBuilder implements PushPayloadBuilder {
class OppoPushPayloadBuilder extends AndroidPushPayloadBuilder<JsonIntent> {
private final PushProps pushProps;
@Override
public void build(PushContent content, JSONObject payload) {
public JsonIntent createIntent() {
return new JsonIntent();
}
@Override
public void build(PushContent content, JsonIntent intent, JSONObject payload) {
PushProps.ChannelConfig xmCfg = pushProps.getOppoChannelConfig();
JSONObject oppoField = new JSONObject();
oppoField.put("style", 1);
oppoField.put("network_type", 0);
oppoField.put("channel_id", content.determineChannelId(xmCfg));
if (content.hasAndroidPushUrl()) {
oppoField.put("click_action_type", 2);
oppoField.put("click_action_url", content.getAndroidPushUrl());
}
oppoField.put("category", content.determineAndroidCategory());
oppoField.put("notify_level", 2);
oppoField.put("click_action_type", 1);
oppoField.put("click_action_activity", "com.oppo.codelabpush.intent.action.test");
oppoField.put("action_parameters", intent.build().toJSONString());
payload.put("oppoField", oppoField);
}

View File

@ -1,6 +1,10 @@
package cn.axzo.msg.center.nimpush.payload;
import cn.axzo.msg.center.nimpush.PushContent;
import cn.axzo.msg.center.nimpush.PushPeer;
import cn.axzo.msg.center.nimpush.payload.intent.Intent;
import cn.axzo.msg.center.nimpush.payload.intent.IntentValue;
import cn.axzo.msg.center.nimpush.payload.intent.JsonIntent;
import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Component;
@ -10,19 +14,25 @@ import org.springframework.stereotype.Component;
* @author yanglin
*/
@Component
public class PGPushPayloadBuilder implements PushPayloadBuilder {
class PGPushPayloadBuilder implements PushPayloadBuilder<JsonIntent> {
@Override
public void build(PushContent content, JSONObject payload) {
public JsonIntent createIntent(PushContent content, PushPeer peer) {
JsonIntent intent = new JsonIntent();
if (content.hasIosPushUrl())
Intent.setRouter(intent, IntentValue.create(content.getIosPushUrl()));
return intent;
}
@Override
public void build(PushContent content, JsonIntent intent, JSONObject payload) {
JSONObject userInfo = new JSONObject();
// router为自定义的字段
userInfo.put("router", content.getIosPushUrl());
userInfo.putAll(intent.build());
JSONObject alert = new JSONObject();
alert.put("title", content.getTitle());
alert.put("body", content.getContent());
if (content.hasIosPushUrl())
alert.put("userInfo", userInfo);
alert.put("userInfo", userInfo);
JSONObject apsField = new JSONObject();
apsField.put("alert", alert);
@ -32,4 +42,4 @@ public class PGPushPayloadBuilder implements PushPayloadBuilder {
payload.put("apsField", apsField);
}
}
}

View File

@ -1,6 +1,8 @@
package cn.axzo.msg.center.nimpush.payload;
import cn.axzo.msg.center.nimpush.PushContent;
import cn.axzo.msg.center.nimpush.PushPeer;
import cn.axzo.msg.center.nimpush.payload.intent.Intent;
import com.alibaba.fastjson.JSONObject;
/**
@ -11,8 +13,10 @@ import com.alibaba.fastjson.JSONObject;
*
* @author yanglin
*/
public interface PushPayloadBuilder {
public interface PushPayloadBuilder<T extends Intent<?>> {
void build(PushContent content, JSONObject payload);
T createIntent(PushContent content, PushPeer peer);
void build(PushContent content, T intent, JSONObject payload);
}

View File

@ -1,6 +1,7 @@
package cn.axzo.msg.center.nimpush.payload;
import cn.axzo.msg.center.nimpush.PushContent;
import cn.axzo.msg.center.nimpush.payload.intent.UriIntent;
import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Component;
@ -10,15 +11,19 @@ import org.springframework.stereotype.Component;
* @author yanglin
*/
@Component
public class RYPushPayloadBuilder implements PushPayloadBuilder {
class RYPushPayloadBuilder extends AndroidPushPayloadBuilder<UriIntent> {
@Override
public void build(PushContent content, JSONObject payload) {
public UriIntent createIntent() {
return new UriIntent();
}
@Override
public void build(PushContent content, UriIntent intent, JSONObject payload) {
// 点击事件的内容
JSONObject clickAction = new JSONObject();
clickAction.put("type", 1);
//clickAction.put("intent", message.getAndroidPushUrl());
clickAction.put("url", content.getAndroidPushUrl());
clickAction.put("intent", intent.build());
// 通知的内容
JSONObject notification = new JSONObject();

View File

@ -2,6 +2,7 @@ package cn.axzo.msg.center.nimpush.payload;
import cn.axzo.msg.center.nimpush.PushContent;
import cn.axzo.msg.center.nimpush.PushMessageTye;
import cn.axzo.msg.center.nimpush.payload.intent.UriIntent;
import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Component;
@ -11,21 +12,26 @@ import org.springframework.stereotype.Component;
* @author yanglin
*/
@Component
public class VivoPushPayloadBuilder implements PushPayloadBuilder {
class VivoPushPayloadBuilder extends AndroidPushPayloadBuilder<UriIntent> {
@Override
public UriIntent createIntent() {
return new UriIntent();
}
/**
* 没找到自定义声音相关的字段
*/
@Override
public void build(PushContent content, JSONObject payload) {
public void build(PushContent content, UriIntent intent, JSONObject payload) {
JSONObject vivoField = new JSONObject();
vivoField.put("content", content.getContent());
vivoField.put("classification",
content.getMessageTye() == PushMessageTye.OP ? "0" : "1");
if (content.hasAndroidPushUrl()) {
vivoField.put("skipType", "3");
vivoField.put("skipContent", content.getAndroidPushUrl());
}
content.getMessageTye() == PushMessageTye.OP ? 0 : 1);
vivoField.put("skipType", 4);
vivoField.put("networkType", -1);
vivoField.put("category", content.determineAndroidCategory());
vivoField.put("skipContent", intent.build());
payload.put("vivoField", vivoField);
}

View File

@ -2,6 +2,7 @@ package cn.axzo.msg.center.nimpush.payload;
import cn.axzo.msg.center.inside.notices.config.PushProps;
import cn.axzo.msg.center.nimpush.PushContent;
import cn.axzo.msg.center.nimpush.payload.intent.UriIntent;
import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
@ -13,20 +14,24 @@ import org.springframework.stereotype.Component;
*/
@Component
@RequiredArgsConstructor
public class XMPushPayloadBuilder implements PushPayloadBuilder {
class XMPushPayloadBuilder extends AndroidPushPayloadBuilder<UriIntent> {
private final PushProps pushProps;
@Override
public void build(PushContent content, JSONObject payload) {
public UriIntent createIntent() {
return new UriIntent();
}
@Override
public void build(PushContent content, UriIntent intent, JSONObject payload) {
PushProps.ChannelConfig xmCfg = pushProps.getXiaomiChannelConfig();
payload.put("channel_id", content.determineChannelId(xmCfg));
payload.put("notify_foreground", "1");
payload.put("notify_effect", "2");
payload.put("intent_uri", intent.build());
if (content.hasCustomSoundFile())
payload.put("sound", content.getCustomSoundFile());
if (content.hasAndroidPushUrl()) {
//payload.put("intent_uri", message.getAndroidPushUrl());
payload.put("web_uri", content.getAndroidPushUrl());
}
}
}

View File

@ -0,0 +1,18 @@
package cn.axzo.msg.center.nimpush.payload.intent;
/**
* @author yanglin
*/
public interface Intent<T> {
void setValue(String key, IntentValue value);
T build();
// !! helper
static void setRouter(Intent<?> intent, IntentValue value) {
intent.setValue("router", value);
}
}

View File

@ -0,0 +1,33 @@
package cn.axzo.msg.center.nimpush.payload.intent;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import java.util.function.Consumer;
/**
* @author yanglin
*/
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public class IntentValue {
private final Object value;
private static final IntentValue NULL = new IntentValue(null);
public static final IntentValue SESSION_TYPE = new IntentValue("0");
public static final IntentValue TYPE = new IntentValue("server");
public static IntentValue create(Object value) {
if (value == null) return NULL;
return new IntentValue(value);
}
/**
* 和app约定好了, intent里面都使用string类型的值
*/
public void consume(Consumer<String> consumer) {
if (value == null) return;
consumer.accept(String.valueOf(value));
}
}

View File

@ -0,0 +1,25 @@
package cn.axzo.msg.center.nimpush.payload.intent;
import cn.axzo.msg.center.common.utils.BizAssertions;
import com.alibaba.fastjson.JSONObject;
/**
* @author yanglin
*/
public class JsonIntent implements Intent<JSONObject> {
private final JSONObject values = new JSONObject();
@Override
public void setValue(String key, IntentValue value) {
BizAssertions.assertNotBlank(key, "key is required");
BizAssertions.assertNotNull(value, "value is required");
value.consume(stringValue -> values.put(key, stringValue));
}
@Override
public JSONObject build() {
return values;
}
}

View File

@ -0,0 +1,40 @@
package cn.axzo.msg.center.nimpush.payload.intent;
import cn.axzo.msg.center.common.utils.BizAssertions;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* @author yanglin
*/
public class UriIntent implements Intent<String> {
private static final String STRING_INTENT_PREFIX =
"intent:\\/\\/cn.axzo.codelabpush\\/deeplink?#Intent;scheme=pushschema;launchFlags=0x4000000;";
private final LinkedHashMap<String, IntentValue> values = new LinkedHashMap<>();
@Override
public void setValue(String key, IntentValue value) {
BizAssertions.assertNotBlank(key, "key is required");
BizAssertions.assertNotNull(value, "value is required");
values.put(key, value);
}
@Override
public String build() {
StringBuilder buf = new StringBuilder(STRING_INTENT_PREFIX);
for (Map.Entry<String, IntentValue> entry : values.entrySet()) {
entry.getValue().consume(stringValue ->
buf.append("S.")
.append(entry.getKey())
.append("=")
.append(stringValue)
.append(";"));
}
buf.append("end");
return buf.toString();
}
}

View File

@ -15,7 +15,7 @@ public interface PushMessage {
String getPushTitle();
@JsonIgnore @JSONField(serialize = false)
String getContent();
String getPushContent();
@Nullable
@JsonIgnore @JSONField(serialize = false)

View File

@ -124,7 +124,7 @@ public class ParsedModelV3 implements MessageButtonProvider<ParsedButtonV3>, Pus
}
@Override @JsonIgnore @JSONField(serialize = false)
public String getContent() {
public String getPushContent() {
if (template == null) return null;
return template.getContent();
}

View File

@ -19,7 +19,12 @@ import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import static cn.axzo.msg.center.notices.common.constans.CacheConstants.*;
import static cn.axzo.msg.center.notices.common.constans.CacheConstants.MESSAGE_TEMPLATE;
import static cn.axzo.msg.center.notices.common.constans.CacheConstants.MNS;
import static cn.axzo.msg.center.notices.common.constans.CacheConstants.NULL_VALUE_CACHE_SECONDS;
import static cn.axzo.msg.center.notices.common.constans.CacheConstants.PARAM;
import static cn.axzo.msg.center.notices.common.constans.CacheConstants.REDIS_NULL_VALUE;
import static cn.axzo.msg.center.notices.common.constans.CacheConstants.TEMPLATE_PARAM_CACHE_SECONDS;
/**
* 消息模板参数 Manager
@ -40,6 +45,10 @@ public class MessageTemplateParamManagerImpl implements MessageTemplateParamMana
@PostConstruct
public void init() {
new Thread(this::initImpl).start();
}
private void initImpl() {
List<MNSMessageTemplateParam> templateParams = mnsMessageTemplateParamDao.getAllMessageTemplateParams();
if(CollectionUtils.isEmpty(templateParams)) {
@ -59,7 +68,6 @@ public class MessageTemplateParamManagerImpl implements MessageTemplateParamMana
// 构建缓存
buildCache(k, sortedValue);
});
}
@Override