From d276a5c6a5d7da29710069055479598ebec8a761 Mon Sep 17 00:00:00 2001 From: yanglin Date: Wed, 27 Nov 2024 20:27:27 +0800 Subject: [PATCH] =?UTF-8?q?REQ-3284:=20=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/v3/msg/TemplateMessage.java | 12 ++++- .../controller/PrivateMessageController.java | 13 +++++- .../todo/manage/event/TodoPushSenderV3.java | 10 +++- .../msg/center/nimpush/NimPushService.java | 46 ++++++++++++++----- .../axzo/msg/center/nimpush/PushContent.java | 6 +++ .../cn/axzo/msg/center/nimpush/PushPeer.java | 15 ++++++ .../payload/AndroidPushPayloadBuilder.java | 26 +++++++++++ .../nimpush/payload/HWPushPayloadBuilder.java | 19 +++++--- .../nimpush/payload/MZPushPayloadBuilder.java | 26 ----------- .../payload/OppoPushPayloadBuilder.java | 21 +++++---- .../nimpush/payload/PGPushPayloadBuilder.java | 24 +++++++--- .../nimpush/payload/PushPayloadBuilder.java | 8 +++- .../nimpush/payload/RYPushPayloadBuilder.java | 13 ++++-- .../payload/VivoPushPayloadBuilder.java | 20 +++++--- .../nimpush/payload/XMPushPayloadBuilder.java | 17 ++++--- .../center/nimpush/payload/intent/Intent.java | 18 ++++++++ .../nimpush/payload/intent/IntentValue.java | 33 +++++++++++++ .../nimpush/payload/intent/JsonIntent.java | 25 ++++++++++ .../nimpush/payload/intent/UriIntent.java | 40 ++++++++++++++++ .../cn/axzo/msg/center/push/PushMessage.java | 2 +- .../response/v3/model/ParsedModelV3.java | 2 +- .../MessageTemplateParamManagerImpl.java | 12 ++++- 22 files changed, 321 insertions(+), 87 deletions(-) create mode 100644 inside-notices/src/main/java/cn/axzo/msg/center/nimpush/PushPeer.java create mode 100644 inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/AndroidPushPayloadBuilder.java delete mode 100644 inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/MZPushPayloadBuilder.java create mode 100644 inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/intent/Intent.java create mode 100644 inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/intent/IntentValue.java create mode 100644 inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/intent/JsonIntent.java create mode 100644 inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/intent/UriIntent.java diff --git a/inside-notices/src/main/java/cn/axzo/msg/center/inside/notices/service/impl/v3/msg/TemplateMessage.java b/inside-notices/src/main/java/cn/axzo/msg/center/inside/notices/service/impl/v3/msg/TemplateMessage.java index ec2c6fc8..478e2e03 100644 --- a/inside-notices/src/main/java/cn/axzo/msg/center/inside/notices/service/impl/v3/msg/TemplateMessage.java +++ b/inside-notices/src/main/java/cn/axzo/msg/center/inside/notices/service/impl/v3/msg/TemplateMessage.java @@ -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); } // ------------------------------- 辅助方法 diff --git a/inside-notices/src/main/java/cn/axzo/msg/center/message/controller/PrivateMessageController.java b/inside-notices/src/main/java/cn/axzo/msg/center/message/controller/PrivateMessageController.java index 50197c67..45b8a9a0 100644 --- a/inside-notices/src/main/java/cn/axzo/msg/center/message/controller/PrivateMessageController.java +++ b/inside-notices/src/main/java/cn/axzo/msg/center/message/controller/PrivateMessageController.java @@ -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) { diff --git a/inside-notices/src/main/java/cn/axzo/msg/center/message/service/todo/manage/event/TodoPushSenderV3.java b/inside-notices/src/main/java/cn/axzo/msg/center/message/service/todo/manage/event/TodoPushSenderV3.java index 741e8616..72b0663a 100644 --- a/inside-notices/src/main/java/cn/axzo/msg/center/message/service/todo/manage/event/TodoPushSenderV3.java +++ b/inside-notices/src/main/java/cn/axzo/msg/center/message/service/todo/manage/event/TodoPushSenderV3.java @@ -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 { 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(); diff --git a/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/NimPushService.java b/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/NimPushService.java index 097a49ca..fa651a95 100644 --- a/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/NimPushService.java +++ b/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/NimPushService.java @@ -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 builderProvider, + @SuppressWarnings("rawtypes") + public NimPushService(ObjectProvider 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> 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; } diff --git a/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/PushContent.java b/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/PushContent.java index 90050b4b..8b294630 100644 --- a/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/PushContent.java +++ b/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/PushContent.java @@ -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() diff --git a/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/PushPeer.java b/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/PushPeer.java new file mode 100644 index 00000000..b8a18185 --- /dev/null +++ b/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/PushPeer.java @@ -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; +} \ No newline at end of file diff --git a/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/AndroidPushPayloadBuilder.java b/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/AndroidPushPayloadBuilder.java new file mode 100644 index 00000000..8d718a63 --- /dev/null +++ b/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/AndroidPushPayloadBuilder.java @@ -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> + implements PushPayloadBuilder { + + @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(); + +} \ No newline at end of file diff --git a/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/HWPushPayloadBuilder.java b/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/HWPushPayloadBuilder.java index f1c7bc6c..03730ced 100644 --- a/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/HWPushPayloadBuilder.java +++ b/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/HWPushPayloadBuilder.java @@ -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 { @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()); diff --git a/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/MZPushPayloadBuilder.java b/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/MZPushPayloadBuilder.java deleted file mode 100644 index 12a09dbf..00000000 --- a/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/MZPushPayloadBuilder.java +++ /dev/null @@ -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); - } - -} \ No newline at end of file diff --git a/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/OppoPushPayloadBuilder.java b/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/OppoPushPayloadBuilder.java index b4c5fa4d..804d6a9c 100644 --- a/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/OppoPushPayloadBuilder.java +++ b/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/OppoPushPayloadBuilder.java @@ -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 { 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); } diff --git a/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/PGPushPayloadBuilder.java b/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/PGPushPayloadBuilder.java index ba87545f..06701899 100644 --- a/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/PGPushPayloadBuilder.java +++ b/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/PGPushPayloadBuilder.java @@ -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 { @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); } -} +} \ No newline at end of file diff --git a/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/PushPayloadBuilder.java b/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/PushPayloadBuilder.java index 53b00c49..eda6ecb3 100644 --- a/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/PushPayloadBuilder.java +++ b/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/PushPayloadBuilder.java @@ -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> { - void build(PushContent content, JSONObject payload); + T createIntent(PushContent content, PushPeer peer); + + void build(PushContent content, T intent, JSONObject payload); } \ No newline at end of file diff --git a/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/RYPushPayloadBuilder.java b/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/RYPushPayloadBuilder.java index f9022285..a2977001 100644 --- a/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/RYPushPayloadBuilder.java +++ b/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/RYPushPayloadBuilder.java @@ -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 { @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(); diff --git a/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/VivoPushPayloadBuilder.java b/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/VivoPushPayloadBuilder.java index bebf18fb..f8139458 100644 --- a/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/VivoPushPayloadBuilder.java +++ b/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/VivoPushPayloadBuilder.java @@ -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 { + + @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); } diff --git a/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/XMPushPayloadBuilder.java b/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/XMPushPayloadBuilder.java index f50b55a2..fbad46fc 100644 --- a/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/XMPushPayloadBuilder.java +++ b/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/XMPushPayloadBuilder.java @@ -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 { 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()); - } } } \ No newline at end of file diff --git a/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/intent/Intent.java b/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/intent/Intent.java new file mode 100644 index 00000000..58f5a386 --- /dev/null +++ b/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/intent/Intent.java @@ -0,0 +1,18 @@ +package cn.axzo.msg.center.nimpush.payload.intent; + +/** + * @author yanglin + */ +public interface Intent { + + void setValue(String key, IntentValue value); + + T build(); + + // !! helper + + static void setRouter(Intent intent, IntentValue value) { + intent.setValue("router", value); + } + +} \ No newline at end of file diff --git a/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/intent/IntentValue.java b/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/intent/IntentValue.java new file mode 100644 index 00000000..a3dbdc60 --- /dev/null +++ b/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/intent/IntentValue.java @@ -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 consumer) { + if (value == null) return; + consumer.accept(String.valueOf(value)); + } + +} \ No newline at end of file diff --git a/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/intent/JsonIntent.java b/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/intent/JsonIntent.java new file mode 100644 index 00000000..751ca7db --- /dev/null +++ b/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/intent/JsonIntent.java @@ -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 { + + 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; + } + +} \ No newline at end of file diff --git a/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/intent/UriIntent.java b/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/intent/UriIntent.java new file mode 100644 index 00000000..c587e074 --- /dev/null +++ b/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/intent/UriIntent.java @@ -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 { + + private static final String STRING_INTENT_PREFIX = + "intent:\\/\\/cn.axzo.codelabpush\\/deeplink?#Intent;scheme=pushschema;launchFlags=0x4000000;"; + + private final LinkedHashMap 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 entry : values.entrySet()) { + entry.getValue().consume(stringValue -> + buf.append("S.") + .append(entry.getKey()) + .append("=") + .append(stringValue) + .append(";")); + } + buf.append("end"); + return buf.toString(); + } + +} \ No newline at end of file diff --git a/msg-center-api/src/main/java/cn/axzo/msg/center/push/PushMessage.java b/msg-center-api/src/main/java/cn/axzo/msg/center/push/PushMessage.java index 3d778cbb..6b74108d 100644 --- a/msg-center-api/src/main/java/cn/axzo/msg/center/push/PushMessage.java +++ b/msg-center-api/src/main/java/cn/axzo/msg/center/push/PushMessage.java @@ -15,7 +15,7 @@ public interface PushMessage { String getPushTitle(); @JsonIgnore @JSONField(serialize = false) - String getContent(); + String getPushContent(); @Nullable @JsonIgnore @JSONField(serialize = false) diff --git a/msg-center-api/src/main/java/cn/axzo/msg/center/service/pending/response/v3/model/ParsedModelV3.java b/msg-center-api/src/main/java/cn/axzo/msg/center/service/pending/response/v3/model/ParsedModelV3.java index e5f40752..a84b72cf 100644 --- a/msg-center-api/src/main/java/cn/axzo/msg/center/service/pending/response/v3/model/ParsedModelV3.java +++ b/msg-center-api/src/main/java/cn/axzo/msg/center/service/pending/response/v3/model/ParsedModelV3.java @@ -124,7 +124,7 @@ public class ParsedModelV3 implements MessageButtonProvider, Pus } @Override @JsonIgnore @JSONField(serialize = false) - public String getContent() { + public String getPushContent() { if (template == null) return null; return template.getContent(); } diff --git a/msg-notices/msg-notices-manager/src/main/java/cn/axzo/msg/center/notices/manager/MessageTemplateParamManagerImpl.java b/msg-notices/msg-notices-manager/src/main/java/cn/axzo/msg/center/notices/manager/MessageTemplateParamManagerImpl.java index 66463c0f..b16037c8 100644 --- a/msg-notices/msg-notices-manager/src/main/java/cn/axzo/msg/center/notices/manager/MessageTemplateParamManagerImpl.java +++ b/msg-notices/msg-notices-manager/src/main/java/cn/axzo/msg/center/notices/manager/MessageTemplateParamManagerImpl.java @@ -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 templateParams = mnsMessageTemplateParamDao.getAllMessageTemplateParams(); if(CollectionUtils.isEmpty(templateParams)) { @@ -59,7 +68,6 @@ public class MessageTemplateParamManagerImpl implements MessageTemplateParamMana // 构建缓存 buildCache(k, sortedValue); }); - } @Override