From b22257d6788c8e9c81622de7ba8b88ab0f46200c Mon Sep 17 00:00:00 2001 From: yanglin Date: Mon, 16 Dec 2024 15:07:00 +0800 Subject: [PATCH] =?UTF-8?q?REQ-3201:=20=E8=BF=90=E8=90=A5push?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/MessagePushApiImpl.java | 11 - .../service/impl/v3/msg/TemplateMessage.java | 260 ------------------ .../message/migrate/OuIdMigrateService.java | 6 - .../message/service/card/CardSupport.java | 16 +- .../impl/PendingMessageNewServiceImpl.java | 2 - .../todo/manage/event/TodoPushSenderNim.java | 19 +- .../msg/center/nimpush/NimPushService.java | 87 ++---- .../axzo/msg/center/nimpush/PushContent.java | 65 ----- .../msg/center/nimpush/PushMessageTye.java | 24 -- .../payload/AndroidPushPayloadBuilder.java | 29 -- .../nimpush/payload/HWPushPayloadBuilder.java | 43 --- .../payload/OppoPushPayloadBuilder.java | 38 --- .../nimpush/payload/PGPushPayloadBuilder.java | 45 --- .../nimpush/payload/PushPayloadBuilder.java | 22 -- .../nimpush/payload/RYPushPayloadBuilder.java | 43 --- .../payload/VivoPushPayloadBuilder.java | 39 --- .../nimpush/payload/XMPushPayloadBuilder.java | 35 --- .../center/nimpush/payload/intent/Intent.java | 26 -- .../nimpush/payload/intent/IntentValue.java | 52 ---- .../nimpush/payload/intent/JsonIntent.java | 25 -- .../nimpush/payload/intent/UriIntent.java | 40 --- .../axzo/msg/center/api/MessagePushApi.java | 7 - .../center/nimpush/NimPushServiceTest.java | 22 -- 23 files changed, 24 insertions(+), 932 deletions(-) delete mode 100644 inside-notices/src/main/java/cn/axzo/msg/center/inside/notices/service/impl/v3/msg/TemplateMessage.java delete mode 100644 inside-notices/src/main/java/cn/axzo/msg/center/nimpush/PushContent.java delete mode 100644 inside-notices/src/main/java/cn/axzo/msg/center/nimpush/PushMessageTye.java delete 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/HWPushPayloadBuilder.java delete mode 100644 inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/OppoPushPayloadBuilder.java delete mode 100644 inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/PGPushPayloadBuilder.java delete mode 100644 inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/PushPayloadBuilder.java delete mode 100644 inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/RYPushPayloadBuilder.java delete mode 100644 inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/VivoPushPayloadBuilder.java delete mode 100644 inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/XMPushPayloadBuilder.java delete mode 100644 inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/intent/Intent.java delete mode 100644 inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/intent/IntentValue.java delete mode 100644 inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/intent/JsonIntent.java delete mode 100644 inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/intent/UriIntent.java delete mode 100644 start/src/test/java/cn/axzo/msg/center/nimpush/NimPushServiceTest.java diff --git a/inside-notices/src/main/java/cn/axzo/msg/center/inside/notices/service/impl/MessagePushApiImpl.java b/inside-notices/src/main/java/cn/axzo/msg/center/inside/notices/service/impl/MessagePushApiImpl.java index ae50b910..84b313bd 100644 --- a/inside-notices/src/main/java/cn/axzo/msg/center/inside/notices/service/impl/MessagePushApiImpl.java +++ b/inside-notices/src/main/java/cn/axzo/msg/center/inside/notices/service/impl/MessagePushApiImpl.java @@ -2,10 +2,8 @@ package cn.axzo.msg.center.inside.notices.service.impl; import cn.axzo.msg.center.api.MessagePushApi; -import cn.axzo.msg.center.api.request.BuildNimPayloadRequest; import cn.axzo.msg.center.api.request.MsgBody4Guest; import cn.axzo.msg.center.inside.notices.service.IYouMengMessageService; -import cn.axzo.msg.center.nimpush.NimPushService; import cn.azxo.framework.common.model.CommonResponse; import com.alibaba.fastjson.JSONObject; import lombok.extern.slf4j.Slf4j; @@ -22,8 +20,6 @@ public class MessagePushApiImpl implements MessagePushApi { @Autowired private IYouMengMessageService youMengMessageService; - @Autowired - private NimPushService nimPushService; @Override public CommonResponse sendPushMessage(MsgBody4Guest msgBody) { @@ -32,11 +28,4 @@ public class MessagePushApiImpl implements MessagePushApi { return CommonResponse.success(); } - @Override - public CommonResponse buildNimPayload(BuildNimPayloadRequest request) { - log.info("buildNimPayload, request={}", request); - String payload = nimPushService.buildPayloadString(request, request.getPushPeer()); - return CommonResponse.success(payload); - } - } 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 deleted file mode 100644 index bfc77e94..00000000 --- a/inside-notices/src/main/java/cn/axzo/msg/center/inside/notices/service/impl/v3/msg/TemplateMessage.java +++ /dev/null @@ -1,260 +0,0 @@ -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.ApiChannel; -import cn.axzo.im.center.api.vo.PersonAccountAttribute; -import cn.axzo.im.center.api.vo.req.ExcludePushPayload; -import cn.axzo.im.center.api.vo.req.SendTemplateMessageParam; -import cn.axzo.im.center.common.enums.AppTypeEnum; -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.card.CardSupport; -import cn.axzo.msg.center.message.service.impl.v3.ModelV3Parser; -import cn.axzo.msg.center.message.service.impl.v3.UrlParser; -import cn.axzo.msg.center.nimpush.NimPushService; -import cn.axzo.msg.center.nimpush.PushChannel; -import cn.axzo.msg.center.nimpush.device.PushDeviceSnapshots; -import cn.axzo.msg.center.nimpush.payload.intent.Intent; -import cn.axzo.msg.center.push.PushData; -import cn.axzo.msg.center.service.domain.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; -import cn.axzo.msg.center.service.pending.response.v3.model.ParsedModelV3; -import cn.axzo.msg.center.utils.UUIDUtil; -import com.alibaba.fastjson.JSONObject; -import lombok.Data; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; -import org.springframework.context.ApplicationContext; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import static java.util.stream.Collectors.toList; -import static java.util.stream.Collectors.toSet; - -/** - * @author yanglin - */ -@Slf4j -@RequiredArgsConstructor -public class TemplateMessage { - - private final MessageSendRequestV4 req; - private final String batchNo; - @Getter - private final Channel channel; - @Getter - private final TemplateModelV3 templateModel; - private final ApplicationContext beanFactory; - - private List records; - private String title; - private String content; - - String getTemplateCode() { - return templateModel.getTemplateCode(); - } - - Collection getMessageIds() { - return getMessageRecords().stream() - .map(MessageRecordV3::getId) - .collect(toSet()); - } - - Collection getReceiverPersonIds() { - return getMessageRecords().stream() - .map(MessageRecordV3::getReceiverPersonId) - .collect(toList()); - } - - List getMessageRecords() { - if (records != null) { - return records; - } - records = new ArrayList<>(); - MessageSendBasicInfoV4 sendBasicInfo = req.getSendBasicInfo(); - for (PersonV3DTO receiver : sendBasicInfo.distinctReceivers()) { - PersonV3DTO sender = sendBasicInfo.getSender(); - MessageRecordV3 message = new MessageRecordV3(); - records.add(message); - message.setBatchNo(batchNo); - message.setIdentityCode(UUIDUtil.uuidString()); - message.setSenderPersonId(sender == null ? null : sender.getId()); - message.setSenderOuId(sendBasicInfo.getSenderOuId()); - message.setSenderWorkspaceId(sendBasicInfo.getSenderWorkspaceId()); - message.setReceiverPersonId(receiver.getId()); - message.setReceiverOuId(sendBasicInfo.determineReceiversOuId()); - message.setReceiverWorkspaceId(sendBasicInfo.determineReceiversWorkspaceId()); - message.setBizEventMappingCode(req.getEventMappingCode()); - message.setTemplateCode(getTemplateCode()); - message.setTitle(parseTitle()); - message.setContent(parseContent()); - OrganizationTypeEnum orgType = sendBasicInfo.getReceiversOrgType(); - if (orgType == null) { - orgType = OrganizationTypeEnum.UNKNOWN; - } - message.setReceiverOrgType(orgType.stringCode()); - message.setSubtitle(sendBasicInfo.getSubtitle()); - message.setState(MsgStateV3Enum.UNSENT); - message.setBizCode(sendBasicInfo.determineBizCode()); - message.setRouterParams(sendBasicInfo.determineRouterParams()); - message.setBizExtParams(sendBasicInfo.determineBizExtParams()); - message.setMsgExtInfo(getMsgExtInfo()); - message.setFailCause(null); - message.setCreateAt(new Date()); - message.setUpdateAt(new Date()); - message.setIsDelete(TableIsDeleteEnum.NORMAL.value); - // 这里不设置发送时间, 有发送结果的时候再设置, 比较准确 - } - return records; - } - - SendTemplateMessageParam buildImRequest(MessageTemplateParserV3 templateParser, - PushDeviceSnapshots deviceSnapshots, - AppTypeEnum appType) { - MessageRecordV3 sample = getMessageRecords().get(0); - GeneralMessagePushVO sendVo = templateParser.parse(sample, templateModel); - - MessageSendBasicInfoV4 sendBasicInfo = req.getSendBasicInfo(); - SendTemplateMessageParam imRequest = new SendTemplateMessageParam(); - imRequest.setBizId(String.format("%s:%s", CardSupport.getBizIdPrefix(getTemplateCode()), sendBasicInfo.determineBizCode())); - imRequest.setSendPriority(templateModel.getTemplate().determineImSendPriority()); - imRequest.setMsgHeader(parseTitle()); - imRequest.setMsgContent(parseContent()); - imRequest.setMsgTemplateId(getTemplateCode()); - imRequest.setMsgTemplateContent(JSON.toJSONString(sendVo)); - imRequest.setExcludePushPayloads(new ArrayList<>()); - // 接收人 - ArrayList receivers = new ArrayList<>(); - Set cmUnique = new HashSet<>(); - Set cmpUnique = new HashSet<>(); - - PushData pushData = templateModel.getTemplate().parsePushData(); - boolean pushable = pushData.determinePushable(log, getTemplateCode()); - - // 扩展信息 - for (PersonV3DTO receiver : sendBasicInfo.receivers()) { - PersonV3DTO.ReceiveModel imReceiveModel = receiver.getImReceiveModel(); - Long ouId = imReceiveModel == null ? sendBasicInfo.determineReceiversOuId() : imReceiveModel.getOuId(); - if (appType == AppTypeEnum.CM && !cmUnique.add(receiver.getId())) { - continue; - } - if (appType == AppTypeEnum.CMP && !cmpUnique.add(new OuAndPerson(ouId, receiver.getId()))) { - continue; - } - - boolean excludePayload = pushable && - !deviceSnapshots.getDevice(receiver.getId()) - .shouldPush(appType, PushChannel.NIM); - if (excludePayload) { - ExcludePushPayload excludePush = new ExcludePushPayload(); - excludePush.setPersonId(receiver.getId() + ""); - excludePush.setAppType(appType); - imRequest.getExcludePushPayloads().add(excludePush); - } - - PersonAccountAttribute receiverAccount = new PersonAccountAttribute(); - receiverAccount.setPersonId(receiver.getId() + ""); - receiverAccount.setOuId(ouId); - receiverAccount.setAppType(appType); - receivers.add(receiverAccount); - if (appType == AppTypeEnum.CM) - cmUnique.add(receiver.getId()); - else if (appType == AppTypeEnum.CMP) - cmpUnique.add(new OuAndPerson(ouId, receiver.getId())); - } - imRequest.setReceivePersons(receivers); - JSONObject ext = new JSONObject(); - ext.put("minAppVersion", templateModel.getTemplate().getMinAppVersion()); - if (sample.getReceiverWorkspaceId() != null) { - ext.put("workspaceId", String.valueOf(sample.getReceiverWorkspaceId())); - } - if (sample.getReceiverOuId() != null) { - ext.put("ouId", String.valueOf(sample.getReceiverOuId())); - } - imRequest.setExt(ext); - if (pushable) { - imRequest.setPayload(buildPayload(sample, appType)); - if (StringUtils.isNotBlank(pushData.getVoiceFile())) - ext.put(Intent.INTENT_SOUND, pushData.getVoiceFile()); - } - return imRequest; - } - - private String buildPayload(MessageRecordV3 sample, AppTypeEnum appType) { - ModelV3Parser modelV3Parser = beanFactory.getBean(ModelV3Parser.class); - ParsedModelV3 parsedModelV3 = modelV3Parser.parseModel(templateModel, - sample.getBizExtParams(), new UrlParser(sample.getRouterParams())); - NimPushService nimPushService = beanFactory.getBean(NimPushService.class); - 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()); - peer.setAppType(appType); - peer.setApiChannel(ApiChannel.COMMON_MESSAGE); - return nimPushService.buildPayloadString(parsedModelV3, peer); - } - - // ------------------------------- 辅助方法 - - String parseTitle() { - if (title == null) { - title = PlaceholderResolver.tryResolve( - templateModel.getTemplate().getTitle(), req.getSendBasicInfo().getBizExtParams()); - } - return title; - } - - String parseContent() { - if (content == null) { - content = PlaceholderResolver.tryResolve( - templateModel.getTemplate().getContent(), req.getSendBasicInfo().getBizExtParams()); - } - return content; - } - - /** - * 预留 - */ - JSONObject getMsgExtInfo() { - return new JSONObject(); - } - - @Data - private static class OuAndPerson { - private final Long ouId; - private final Long personId; - } - - @Override - public String toString() { - HashMap values = new HashMap<>(); - values.put("batchNo", batchNo); - values.put("bizEventMappingCode", req.getEventMappingCode()); - values.put("bizCode", req.getSendBasicInfo().getBizCode()); - values.put("templateCode", templateModel.getTemplate().getCode()); - values.put("messageIds", getMessageIds()); - values.put("receiverPersonIds", getReceiverPersonIds()); - return JSON.toJSONString(values); - } -} \ No newline at end of file diff --git a/inside-notices/src/main/java/cn/axzo/msg/center/message/migrate/OuIdMigrateService.java b/inside-notices/src/main/java/cn/axzo/msg/center/message/migrate/OuIdMigrateService.java index 1eab458f..91ce0e5a 100644 --- a/inside-notices/src/main/java/cn/axzo/msg/center/message/migrate/OuIdMigrateService.java +++ b/inside-notices/src/main/java/cn/axzo/msg/center/message/migrate/OuIdMigrateService.java @@ -1,9 +1,6 @@ package cn.axzo.msg.center.message.migrate; -import cn.axzo.apollo.api.ApolloWorkerTaskOrderApi; import cn.axzo.framework.domain.web.result.ApiResult; -import cn.axzo.maokai.api.client.CooperateShipQueryApi; -import cn.axzo.maokai.api.client.OrganizationalNodeUserApi; import cn.axzo.maokai.api.client.OrganizationalTeamOuRelationApi; import cn.axzo.maokai.api.vo.response.OrganizationalTeamOuRelationResp; import cn.axzo.msg.center.common.utils.BizAssertions; @@ -65,9 +62,6 @@ public class OuIdMigrateService { private final PendingMessageRecordDao pendingMessageRecordDao; private final OrganizationalTeamOuRelationApi organizationalTeamOuRelationApi; private final TeamServiceApi teamServiceApi; - private final CooperateShipQueryApi cooperateShipQueryApi; - private final ApolloWorkerTaskOrderApi apolloWorkerTaskOrderApi; - private final OrganizationalNodeUserApi organizationalNodeUserApi; @Value("${message.pending.ouMigrateBatchSize:100}") private final Long migrateBatchSize; diff --git a/inside-notices/src/main/java/cn/axzo/msg/center/message/service/card/CardSupport.java b/inside-notices/src/main/java/cn/axzo/msg/center/message/service/card/CardSupport.java index 129dd21b..e60c5cae 100644 --- a/inside-notices/src/main/java/cn/axzo/msg/center/message/service/card/CardSupport.java +++ b/inside-notices/src/main/java/cn/axzo/msg/center/message/service/card/CardSupport.java @@ -1,7 +1,6 @@ package cn.axzo.msg.center.message.service.card; import cn.axzo.framework.jackson.utility.JSON; -import cn.axzo.im.center.api.vo.ApiChannel; import cn.axzo.im.center.api.vo.req.SendTemplateMessageParam; import cn.axzo.im.center.common.enums.AppTypeEnum; import cn.axzo.im.center.common.enums.YesOrNo; @@ -17,9 +16,7 @@ import cn.axzo.msg.center.message.service.impl.v3.ModelV3Service; import cn.axzo.msg.center.message.service.impl.v3.UrlParser; import cn.axzo.msg.center.nimpush.NimPushService; import cn.axzo.msg.center.nimpush.device.PushDeviceSnapshots; -import cn.axzo.msg.center.nimpush.payload.intent.Intent; import cn.axzo.msg.center.push.PushData; -import cn.axzo.msg.center.service.domain.PushPeer; import cn.axzo.msg.center.service.domain.card.AppVersionConfig; import cn.axzo.msg.center.service.dto.PeerPerson; import cn.axzo.msg.center.service.enums.MessageChannel; @@ -104,15 +101,6 @@ public class CardSupport { PushDeviceSnapshots deviceSnapshots, String imSenderAccount) { ParsedTemplateV3 template = sendModel.getTemplate(); - Supplier payloadBuilder = () -> { - PushPeer peer = new PushPeer(); - peer.setSenderImAccount(imSenderAccount); - peer.setOuId(group.getGroupKey().getOuId()); - peer.setWorkspaceId(group.getGroupKey().getWorkspaceId()); - peer.setAppType(group.getGroupKey().getAppType()); - peer.setApiChannel(ApiChannel.COMMON_MESSAGE); - return nimPushService.buildPayloadString(sendModel.getParsedModel(), peer); - }; Supplier extBuilder = () -> { JSONObject ext = new JSONObject(); ext.put("minAppVersion", determineMinAppVersion( @@ -137,10 +125,10 @@ public class CardSupport { imRequest.setExt(extBuilder.get()); imRequest.setUpdatable(sendModel.getCardTemplate().isUpdatable()); if (pushData.determinePushable(log, template.getCode())) { - imRequest.setPayload(payloadBuilder.get()); + imRequest.setPushContent(nimPushService.buildPushContent(sendModel.getParsedModel(), false)); imRequest.setExcludePushPayloads(group.buildNimPushExcludes(deviceSnapshots)); if (StringUtils.isNotBlank(pushData.getVoiceFile())) - imRequest.getExt().put(Intent.INTENT_SOUND, pushData.getVoiceFile()); + imRequest.getExt().put("sound", pushData.getVoiceFile()); } return imRequest; } diff --git a/inside-notices/src/main/java/cn/axzo/msg/center/message/service/impl/PendingMessageNewServiceImpl.java b/inside-notices/src/main/java/cn/axzo/msg/center/message/service/impl/PendingMessageNewServiceImpl.java index b10961a1..f23367a1 100644 --- a/inside-notices/src/main/java/cn/axzo/msg/center/message/service/impl/PendingMessageNewServiceImpl.java +++ b/inside-notices/src/main/java/cn/axzo/msg/center/message/service/impl/PendingMessageNewServiceImpl.java @@ -9,7 +9,6 @@ import cn.axzo.msg.center.dal.MessageGroupNodeDao; import cn.axzo.msg.center.domain.entity.MessageGroupNode; import cn.axzo.msg.center.domain.persistence.BaseEntityExt; import cn.axzo.msg.center.inside.notices.config.PendingMessageBizConfig; -import cn.axzo.msg.center.message.service.impl.v3.ModelV3Parser; import cn.axzo.msg.center.service.enums.AppTerminalTypeEnum; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -43,7 +42,6 @@ public class PendingMessageNewServiceImpl { private final OrganizationalTeamOuRelationApi organizationalTeamOuRelationApi; private final PendingMessageBizConfig pendingMessageBizConfig; private final MessageGroupNodeDao messageGroupNodeDao; - private final ModelV3Parser modelV3Parser; public Map getTerminalConfigInfo() { Map> appType2NodeIds = pendingMessageBizConfig.getMsgGroupConfig(); diff --git a/inside-notices/src/main/java/cn/axzo/msg/center/message/service/todo/manage/event/TodoPushSenderNim.java b/inside-notices/src/main/java/cn/axzo/msg/center/message/service/todo/manage/event/TodoPushSenderNim.java index 78bd84af..9fa79c93 100644 --- a/inside-notices/src/main/java/cn/axzo/msg/center/message/service/todo/manage/event/TodoPushSenderNim.java +++ b/inside-notices/src/main/java/cn/axzo/msg/center/message/service/todo/manage/event/TodoPushSenderNim.java @@ -2,11 +2,10 @@ package cn.axzo.msg.center.message.service.todo.manage.event; import cn.axzo.framework.domain.web.result.ApiResult; import cn.axzo.im.center.api.feign.MessageApi; -import cn.axzo.im.center.api.vo.ApiChannel; import cn.axzo.im.center.api.vo.req.CustomMessageInfo; +import cn.axzo.im.center.api.vo.req.PushContent; 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.MessageEntity; import cn.axzo.msg.center.domain.entity.MessageTemplateV3; import cn.axzo.msg.center.domain.entity.Todo; @@ -21,7 +20,6 @@ import cn.axzo.msg.center.nimpush.device.PushDevice; import cn.axzo.msg.center.nimpush.device.PushDeviceService; import cn.axzo.msg.center.nimpush.device.PushDeviceSnapshots; import cn.axzo.msg.center.push.PushData; -import cn.axzo.msg.center.service.domain.PushPeer; import cn.axzo.msg.center.service.enums.PushTerminalEnum; import cn.axzo.msg.center.service.pending.response.v3.model.ParsedModelV3; import com.alibaba.fastjson.JSON; @@ -69,7 +67,6 @@ public class TodoPushSenderNim implements ApplicationListener { if (pushData != null && !pushData.determinePushable(log, parsedModelV3.getTemplateCode())) { return; } - String imSenderAccount = BizAssertions.assertResponse(messageApi.getCustomMessageSendImAccount()); PushDeviceSnapshots deviceSnapshots = pushDeviceService.createDeviceSnapshots(); for (Todo todo : event.getTodos()) { executor.submit(() -> { @@ -78,21 +75,15 @@ public class TodoPushSenderNim implements ApplicationListener { if (!pushDevice.shouldPush(appType, PushChannel.NIM)) continue; - PushPeer peer = new PushPeer(); - peer.setSenderImAccount(imSenderAccount); - peer.setOuId(todo.getOuId()); - peer.setWorkspaceId(todo.getOrgId()); - peer.setAppType(appType); - peer.setApiChannel(ApiChannel.CUSTOM_MESSAGE); - String payload = nimPushService.buildPayloadString(parsedModelV3, peer); - if (StringUtils.isBlank(payload)) + PushContent pushContent = nimPushService.buildPushContent(parsedModelV3, true); + if (pushContent == null) continue; CustomMessageInfo pushRequest = new CustomMessageInfo(); pushRequest.setAppTypeList(Collections.singletonList(appType)); pushRequest.setToPersonId(todo.getExecutorPersonId() + ""); pushRequest.setOuId(todo.getOuId()); - pushRequest.setPayload(payload); - pushRequest.setPush(true); + pushRequest.setPayload("{}"); + pushRequest.setPushContent(pushContent); if (pushData != null && StringUtils.isNotBlank(pushData.getVoiceFile())) { pushRequest.setSound(pushData.getVoiceFile()); } 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 cf39e5c6..6d2968d2 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,115 +1,62 @@ package cn.axzo.msg.center.nimpush; -import cn.axzo.im.center.api.vo.ApiChannel; -import cn.axzo.im.center.common.enums.AppTypeEnum; -import cn.axzo.msg.center.common.utils.BizAssertions; -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.basics.common.constant.enums.CodeDefinition; +import cn.axzo.im.center.api.vo.req.PushContent; +import cn.axzo.im.center.api.vo.req.PushMessageTye; import cn.axzo.msg.center.push.PushData; import cn.axzo.msg.center.push.PushMessage; -import cn.axzo.msg.center.service.domain.PushPeer; import cn.axzo.msg.center.service.domain.UrlConfig; import cn.axzo.msg.center.service.domain.UrlConfigVisitor; import cn.axzo.msg.center.service.domain.UrlConfigWalker; import cn.axzo.msg.center.service.domain.url.AppUrl; -import cn.axzo.msg.center.service.enums.CodeDefinition; -import com.alibaba.fastjson.JSONObject; -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.ObjectProvider; import org.springframework.stereotype.Service; -import java.util.function.Consumer; - /** * @author yanglin */ @Service public class NimPushService { - private final PushPayloadBuilder[] payloadBuilders; - - @SuppressWarnings("rawtypes") - public NimPushService(ObjectProvider payloadBuilders) { - this.payloadBuilders = payloadBuilders.getIfAvailable(); - } - - public String buildPayloadString(PushMessage message, PushPeer peer) { - JSONObject payload = buildPayload(message, peer); - return payload == null ? null : payload.toJSONString(); - } - - private JSONObject buildPayload(PushMessage message, PushPeer peer) { + public PushContent buildPushContent(PushMessage message, boolean buildPushUrl) { PushData pushData = message.getPushData(); if (pushData == null || !pushData.isSwitchOn()) return null; PushContent content = new PushContent(); content.setTitle(message.getPushTitle()); content.setContent(message.getPushContent()); - content.setCustomSoundFile(pushData.getVoiceFile()); - content.setAppType(peer.getAppType()); content.setMessageTye(CodeDefinition .findByCode(PushMessageTye.class, pushData.getType()) .orElse(null)); content.setCustomSoundFile(pushData.getVoiceFile()); - if (peer.getApiChannel() == ApiChannel.CUSTOM_MESSAGE) - populateUrl(content, message.getPushUrl(), peer.getAppType()); - return buildPayload(content, peer); + if (buildPushUrl) + populateUrl(content, message.getPushUrl()); + return content; } - @SuppressWarnings({"rawtypes", "unchecked"}) - private JSONObject buildPayload(PushContent content, PushPeer peer) { - Consumer> intentPopulator = intent -> { - intent.setValue(Intent.INTENT_TYPE, - peer.getApiChannel() == ApiChannel.CUSTOM_MESSAGE - ? IntentValue.TYPE_SERVER - : IntentValue.TYPE_IM); - intent.setValue(Intent.INTENT_SESSION_TYPE, IntentValue.CONSTANT_SESSION_TYPE); - intent.setValue(Intent.INTENT_SESSION_ID, IntentValue.create(peer.getSenderImAccount())); - if (peer.getOuId() != null && peer.getOuId() != 0L) - intent.setValue(Intent.INTENT_OU_ID, IntentValue.create(peer.getOuId())); - if (peer.getWorkspaceId() != null && peer.getWorkspaceId() != 0L) - intent.setValue(Intent.INTENT_WORKSPACE_ID, IntentValue.create(peer.getWorkspaceId())); - if (StringUtils.isNotBlank(content.getCustomSoundFile())) - intent.setValue(Intent.INTENT_SOUND, IntentValue.create(content.getCustomSoundFile())); - }; - JSONObject payload = new JSONObject(); - payload.put("pushTitle", content.getTitle()); - 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; - } - - private void populateUrl(PushContent content, - UrlConfig url, - AppTypeEnum appType) { - if (url == null || appType == null) return; + private void populateUrl(PushContent content, UrlConfig url) { + if (url == null) return; UrlConfigWalker.walkDown(url, new UrlConfigVisitor() { @Override public void visitAppManagerAndroid(AppUrl android) { - if (android.hasUrl() && appType == AppTypeEnum.CMP) - content.setAndroidPushUrl(android.getUrl()); + if (android.hasUrl()) + content.setMangerAndroidPushUrl(android.getUrl()); } @Override public void visitAppManagerIos(AppUrl ios) { - if (ios.hasUrl() && appType == AppTypeEnum.CMP) - content.setIosPushUrl(ios.getUrl()); + if (ios.hasUrl()) + content.setManagerIosPushUrl(ios.getUrl()); } @Override public void visitAppWorkerAndroid(AppUrl android) { - if (android.hasUrl() && appType == AppTypeEnum.CM) - content.setAndroidPushUrl(android.getUrl()); + if (android.hasUrl()) + content.setWorkerAndroidPushUrl(android.getUrl()); } @Override public void visitAppWorkerIos(AppUrl ios) { - if (ios.hasUrl() && appType == AppTypeEnum.CM) - content.setIosPushUrl(ios.getUrl()); + if (ios.hasUrl()) + content.setWorkerIosPushUrl(ios.getUrl()); } }); } 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 deleted file mode 100644 index 20af7800..00000000 --- a/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/PushContent.java +++ /dev/null @@ -1,65 +0,0 @@ -package cn.axzo.msg.center.nimpush; - -import cn.axzo.im.center.common.enums.AppTypeEnum; -import cn.axzo.msg.center.inside.notices.config.push.PushProps.ChannelConfig; -import cn.axzo.msg.center.inside.notices.config.push.PushProps.ChannelIds; -import lombok.Getter; -import lombok.Setter; - -/** - * @author yanglin - */ -@Setter -@Getter -public class PushContent { - - /** - * 主标题 - */ - private String title; - - /** - * 推送内容 - */ - private String content; - - /** - * android点击push的跳转链接 - */ - private String androidPushUrl; - - /** - * ios点击push的跳转链接 - */ - private String iosPushUrl; - - /** - * 端信息 - */ - private AppTypeEnum appType; - - /** - * push消息类型. SYSTEM: 系统消息, OP: 运营消息 - */ - private PushMessageTye messageTye; - - /** - * 自定义提示音 - */ - private String customSoundFile; - - public String determineAndroidCategory() { - return messageTye == PushMessageTye.OP - ? "MARKETING" - : "IM"; - } - - public String determineChannelId(ChannelConfig channelConfig) { - ChannelIds channelIds = appType == AppTypeEnum.CM - ? channelConfig.getWorkerIds() - : channelConfig.getManagerIds(); - return messageTye == PushMessageTye.OP - ? channelIds.getOpMessageChannelId() - : channelIds.getWorkMessageChannelId(); - } -} \ No newline at end of file diff --git a/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/PushMessageTye.java b/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/PushMessageTye.java deleted file mode 100644 index 00d732df..00000000 --- a/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/PushMessageTye.java +++ /dev/null @@ -1,24 +0,0 @@ -package cn.axzo.msg.center.nimpush; - -import cn.axzo.msg.center.service.enums.CodeDefinition; -import lombok.RequiredArgsConstructor; - -/** - * @author yanglin - */ -@RequiredArgsConstructor -public enum PushMessageTye implements CodeDefinition { - - SYSTEM("system", "系统消息"), - OP("op", "运营消息"), - ; - - private final String code; - private final String description; - - @Override - public String getCode() { - return code; - } - -} \ 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 deleted file mode 100644 index e70446fb..00000000 --- a/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/AndroidPushPayloadBuilder.java +++ /dev/null @@ -1,29 +0,0 @@ -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.payload.intent.Intent; -import cn.axzo.msg.center.nimpush.payload.intent.IntentValue; -import cn.axzo.msg.center.service.domain.PushPeer; -import org.apache.commons.lang3.StringUtils; - -/** - * @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 (StringUtils.isNotBlank(content.getAndroidPushUrl())) - Intent.setRouter(intent, IntentValue - .create(content.getAndroidPushUrl()) - .urlEncode()); - 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 deleted file mode 100644 index 65b0b51d..00000000 --- a/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/HWPushPayloadBuilder.java +++ /dev/null @@ -1,43 +0,0 @@ -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; - -/** - * 华为 - * - * @author yanglin - */ -@Component -class HWPushPayloadBuilder extends AndroidPushPayloadBuilder { - - @Override - 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", intent.build()); - - // 通知的内容 - - JSONObject androidConfig = new JSONObject(); - androidConfig.put("category", content.determineAndroidCategory()); - - JSONObject hwField = new JSONObject(); - hwField.put("android", androidConfig); - hwField.put("style", 1); - hwField.put("big_title", content.getTitle()); - hwField.put("big_body", content.getContent()); - hwField.put("click_action", clickAction); - - payload.put("hwField", hwField); - } - -} \ 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 deleted file mode 100644 index 0733e0be..00000000 --- a/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/OppoPushPayloadBuilder.java +++ /dev/null @@ -1,38 +0,0 @@ -package cn.axzo.msg.center.nimpush.payload; - -import cn.axzo.msg.center.inside.notices.config.push.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; - -/** - * @author yanglin - */ -@Component -@RequiredArgsConstructor -class OppoPushPayloadBuilder extends AndroidPushPayloadBuilder { - - private final PushProps pushProps; - - @Override - 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("channel_id", content.determineChannelId(xmCfg)); - 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); - } - -} \ No newline at end of file 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 deleted file mode 100644 index b81a7a67..00000000 --- a/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/PGPushPayloadBuilder.java +++ /dev/null @@ -1,45 +0,0 @@ -package cn.axzo.msg.center.nimpush.payload; - -import cn.axzo.msg.center.nimpush.PushContent; -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 cn.axzo.msg.center.service.domain.PushPeer; -import com.alibaba.fastjson.JSONObject; -import org.apache.commons.lang3.StringUtils; -import org.springframework.stereotype.Component; - -/** - * 苹果 - * - * @author yanglin - */ -@Component -class PGPushPayloadBuilder implements PushPayloadBuilder { - - @Override - public JsonIntent createIntent(PushContent content, PushPeer peer) { - JsonIntent intent = new JsonIntent(); - if (StringUtils.isNotBlank(content.getIosPushUrl())) - Intent.setRouter(intent, IntentValue - .create(content.getIosPushUrl())); - return intent; - } - - @Override - public void build(PushContent content, JsonIntent intent, JSONObject payload) { - JSONObject userInfo = new JSONObject(); - userInfo.putAll(intent.build()); - - JSONObject alert = new JSONObject(); - alert.put("title", content.getTitle()); - alert.put("body", content.getContent()); - alert.put("userInfo", userInfo); - - JSONObject apsField = new JSONObject(); - apsField.put("alert", alert); - - 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 deleted file mode 100644 index 2f709454..00000000 --- a/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/PushPayloadBuilder.java +++ /dev/null @@ -1,22 +0,0 @@ -package cn.axzo.msg.center.nimpush.payload; - -import cn.axzo.msg.center.nimpush.PushContent; -import cn.axzo.msg.center.nimpush.payload.intent.Intent; -import cn.axzo.msg.center.service.domain.PushPeer; -import com.alibaba.fastjson.JSONObject; - -/** - * 云信推送 - * 各端推送配置 - *

- * 文字, 链接、声音 - * - * @author yanglin - */ -public interface PushPayloadBuilder> { - - 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 deleted file mode 100644 index 16984db9..00000000 --- a/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/RYPushPayloadBuilder.java +++ /dev/null @@ -1,43 +0,0 @@ -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; - -/** - * 荣耀 - * - * @author yanglin - */ -@Component -class RYPushPayloadBuilder extends AndroidPushPayloadBuilder { - - @Override - 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", intent.build()); - - // 通知的内容 - JSONObject notification = new JSONObject(); - notification.put("title", content.getTitle()); - notification.put("body", content.getContent()); - notification.put("clickAction", clickAction); - notification.put("importance", - content.getMessageTye() == PushMessageTye.OP ? "LOW" : "NORMAL"); - - JSONObject honorField = new JSONObject(); - honorField.put("notification", notification); - - payload.put("honorField", honorField); - } - -} \ No newline at end of file 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 deleted file mode 100644 index f8139458..00000000 --- a/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/VivoPushPayloadBuilder.java +++ /dev/null @@ -1,39 +0,0 @@ -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; - -/** - * VIVO - * - * @author yanglin - */ -@Component -class VivoPushPayloadBuilder extends AndroidPushPayloadBuilder { - - @Override - public UriIntent createIntent() { - return new UriIntent(); - } - - /** - * 没找到自定义声音相关的字段 - */ - @Override - 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); - vivoField.put("skipType", 4); - vivoField.put("networkType", -1); - vivoField.put("category", content.determineAndroidCategory()); - vivoField.put("skipContent", intent.build()); - - payload.put("vivoField", vivoField); - } - -} \ No newline at end of file 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 deleted file mode 100644 index f1b8b1d9..00000000 --- a/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/XMPushPayloadBuilder.java +++ /dev/null @@ -1,35 +0,0 @@ -package cn.axzo.msg.center.nimpush.payload; - -import cn.axzo.msg.center.inside.notices.config.push.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; - -/** - * 小米 - * - * @author yanglin - */ -@Component -@RequiredArgsConstructor -class XMPushPayloadBuilder extends AndroidPushPayloadBuilder { - - private final PushProps pushProps; - - @Override - 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()); - } - -} \ 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 deleted file mode 100644 index 75d7b562..00000000 --- a/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/intent/Intent.java +++ /dev/null @@ -1,26 +0,0 @@ -package cn.axzo.msg.center.nimpush.payload.intent; - -/** - * @author yanglin - */ -public interface Intent { - - String INTENT_ROUTER = "router"; - String INTENT_SOUND = "sound"; - String INTENT_TYPE = "type"; - String INTENT_SESSION_TYPE = "sessionType"; - String INTENT_SESSION_ID = "sessionId"; - String INTENT_WORKSPACE_ID = "workspaceId"; - String INTENT_OU_ID = "ouId"; - - void setValue(String key, IntentValue value); - - T build(); - - // !! helper - - static void setRouter(Intent intent, IntentValue router) { - intent.setValue(INTENT_ROUTER, router); - } - -} \ 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 deleted file mode 100644 index 336880d1..00000000 --- a/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/intent/IntentValue.java +++ /dev/null @@ -1,52 +0,0 @@ -package cn.axzo.msg.center.nimpush.payload.intent; - -import cn.axzo.basics.common.exception.ServiceException; -import lombok.AccessLevel; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; - -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; -import java.util.function.Consumer; - -/** - * @author yanglin - */ -@Slf4j -@RequiredArgsConstructor(access = AccessLevel.PRIVATE) -public class IntentValue { - - private final Object value; - - private static final IntentValue NULL = new IntentValue(null); - public static final IntentValue CONSTANT_SESSION_TYPE = new IntentValue("0"); - public static final IntentValue TYPE_SERVER = new IntentValue("server"); - public static final IntentValue TYPE_IM = new IntentValue("im"); - - 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)); - } - - public IntentValue urlEncode() { - if (value == null) return NULL; - try { - if (value instanceof String) - return create(URLEncoder.encode((String) value, "UTF-8")); - else - throw new ServiceException("only string can be url encoded"); - } catch (UnsupportedEncodingException e) { - log.warn("url encode failed, intent value: {}", value, e); - throw new ServiceException(String.format("url encode failed, intent value: %s", value), e); - } - } - -} \ 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 deleted file mode 100644 index 751ca7db..00000000 --- a/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/intent/JsonIntent.java +++ /dev/null @@ -1,25 +0,0 @@ -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 deleted file mode 100644 index 6909edce..00000000 --- a/inside-notices/src/main/java/cn/axzo/msg/center/nimpush/payload/intent/UriIntent.java +++ /dev/null @@ -1,40 +0,0 @@ -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 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(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/api/MessagePushApi.java b/msg-center-api/src/main/java/cn/axzo/msg/center/api/MessagePushApi.java index 9471d865..3f52c68c 100644 --- a/msg-center-api/src/main/java/cn/axzo/msg/center/api/MessagePushApi.java +++ b/msg-center-api/src/main/java/cn/axzo/msg/center/api/MessagePushApi.java @@ -1,6 +1,5 @@ package cn.axzo.msg.center.api; -import cn.axzo.msg.center.api.request.BuildNimPayloadRequest; import cn.axzo.msg.center.api.request.MsgBody4Guest; import cn.azxo.framework.common.model.CommonResponse; import org.springframework.cloud.openfeign.FeignClient; @@ -24,10 +23,4 @@ public interface MessagePushApi { @PostMapping("umeng/pushMsg") CommonResponse sendPushMessage(@RequestBody MsgBody4Guest msgBody); - /** - * 构建云信push payload - */ - @PostMapping("push/nim/buildNimPayload") - CommonResponse buildNimPayload(@RequestBody BuildNimPayloadRequest request); - } diff --git a/start/src/test/java/cn/axzo/msg/center/nimpush/NimPushServiceTest.java b/start/src/test/java/cn/axzo/msg/center/nimpush/NimPushServiceTest.java deleted file mode 100644 index 8353d8cb..00000000 --- a/start/src/test/java/cn/axzo/msg/center/nimpush/NimPushServiceTest.java +++ /dev/null @@ -1,22 +0,0 @@ -package cn.axzo.msg.center.nimpush; - -import cn.axzo.msg.center.MsgCenterApplication; -import lombok.RequiredArgsConstructor; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; - -/** - * @author yanglin - */ -@SpringBootTest(classes = MsgCenterApplication.class) -@RequiredArgsConstructor(onConstructor_ = @Autowired) -class NimPushServiceTest { - - private final NimPushService nimPushService; - - @Test - void exec() { - } - -} \ No newline at end of file