REQ-3284: 推送
This commit is contained in:
parent
746bcf7768
commit
24274bf091
@ -12,12 +12,14 @@ 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.push.PushData;
|
||||
import cn.axzo.msg.center.service.enums.PushTerminalEnum;
|
||||
import cn.axzo.msg.center.service.pending.response.v3.model.ParsedModelV3;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -62,6 +64,10 @@ public class TodoPushSenderV3 implements ApplicationListener<NewTodoEvent> {
|
||||
pushRequest.setOuId(todo.getOuId());
|
||||
pushRequest.setPayload(payload);
|
||||
pushRequest.setPush(true);
|
||||
PushData pushData = parsedModelV3.getPushData();
|
||||
if (pushData != null && StringUtils.isNotBlank(pushData.getVoiceFile())) {
|
||||
pushRequest.setSound(pushData.getVoiceFile());
|
||||
}
|
||||
ApiResult<List<MessageCustomResp>> pushResponse = null;
|
||||
try {
|
||||
pushResponse = messageApi.sendCustomMessage(pushRequest);
|
||||
|
||||
@ -39,8 +39,9 @@ public class NimPushService {
|
||||
if (pushData == null || !pushData.isSwitchOn()) return null;
|
||||
PushMessageContent content = new PushMessageContent();
|
||||
content.setTitle(message.getPushTitle());
|
||||
content.setSubtitle(message.getPushSubtitle());
|
||||
content.setContent(message.getContent());
|
||||
content.setCustomSoundFile(pushData.getVoiceFile());
|
||||
content.setAppType(appType);
|
||||
content.setMessageTye(CodeDefinition
|
||||
.findByCode(PushMessageTye.class, pushData.getType())
|
||||
.orElse(null));
|
||||
@ -83,6 +84,7 @@ public class NimPushService {
|
||||
private JSONObject buildPayload(PushMessageContent content) {
|
||||
JSONObject payload = new JSONObject();
|
||||
payload.put("pushTitle", content.getTitle());
|
||||
payload.put("random", System.currentTimeMillis());
|
||||
PushPayloadBuilder[] builders = payloadBuilderProvider.getIfAvailable();
|
||||
if (builders != null) {
|
||||
for (PushPayloadBuilder builder : builders)
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
package cn.axzo.msg.center.nimpush;
|
||||
|
||||
import cn.axzo.im.center.common.enums.AppTypeEnum;
|
||||
import cn.axzo.msg.center.inside.notices.config.PushProps.ChannelConfig;
|
||||
import cn.axzo.msg.center.inside.notices.config.PushProps.ChannelIds;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -17,9 +20,9 @@ public class PushMessageContent {
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 副标题
|
||||
* 推送内容
|
||||
*/
|
||||
private String subtitle;
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* android点击push的跳转链接
|
||||
@ -31,6 +34,11 @@ public class PushMessageContent {
|
||||
*/
|
||||
private String iosPushUrl;
|
||||
|
||||
/**
|
||||
* 端信息
|
||||
*/
|
||||
private AppTypeEnum appType;
|
||||
|
||||
/**
|
||||
* push消息类型. SYSTEM: 系统消息, OP: 运营消息
|
||||
*/
|
||||
@ -41,6 +49,10 @@ public class PushMessageContent {
|
||||
*/
|
||||
private String customSoundFile;
|
||||
|
||||
public boolean hasCustomSoundFile() {
|
||||
return StringUtils.isNotBlank(customSoundFile);
|
||||
}
|
||||
|
||||
public boolean hasAndroidPushUrl() {
|
||||
return StringUtils.isNotBlank(androidPushUrl);
|
||||
}
|
||||
@ -49,4 +61,12 @@ public class PushMessageContent {
|
||||
return StringUtils.isNotBlank(iosPushUrl);
|
||||
}
|
||||
|
||||
public String determineChannelId(ChannelConfig channelConfig) {
|
||||
ChannelIds channelIds = appType == AppTypeEnum.CM
|
||||
? channelConfig.getWorkerIds()
|
||||
: channelConfig.getManagerIds();
|
||||
return messageTye == PushMessageTye.OP
|
||||
? channelIds.getOpMessageChannelId()
|
||||
: channelIds.getWorkMessageChannelId();
|
||||
}
|
||||
}
|
||||
@ -14,17 +14,22 @@ public class HWPushPayloadBuilder implements PushPayloadBuilder {
|
||||
|
||||
@Override
|
||||
public void build(PushMessageContent message, JSONObject payload) {
|
||||
if (!message.hasAndroidPushUrl()) return;
|
||||
// 点击事件的内容
|
||||
JSONObject clickAction = new JSONObject();
|
||||
clickAction.put("type", 1);
|
||||
clickAction.put("intent", message.getAndroidPushUrl());
|
||||
clickAction.put("url", message.getAndroidPushUrl());
|
||||
|
||||
// 通知的内容
|
||||
JSONObject notification = new JSONObject();
|
||||
notification.put("click_action", clickAction);
|
||||
JSONObject hwField = new JSONObject();
|
||||
|
||||
payload.put("hwField", notification);
|
||||
hwField.put("style", 1);
|
||||
if (message.hasAndroidPushUrl())
|
||||
hwField.put("click_action", clickAction);
|
||||
if (message.hasCustomSoundFile())
|
||||
hwField.put("sound", message.getCustomSoundFile());
|
||||
|
||||
payload.put("hwField", hwField);
|
||||
}
|
||||
|
||||
}
|
||||
@ -14,6 +14,21 @@ public class PGPushPayloadBuilder implements PushPayloadBuilder {
|
||||
|
||||
@Override
|
||||
public void build(PushMessageContent message, JSONObject payload) {
|
||||
JSONObject userInfo = new JSONObject();
|
||||
userInfo.put("router", message.getIosPushUrl());
|
||||
|
||||
JSONObject alert = new JSONObject();
|
||||
alert.put("title", message.getTitle());
|
||||
alert.put("body", message.getContent());
|
||||
if (message.hasIosPushUrl())
|
||||
alert.put("userInfo", userInfo);
|
||||
|
||||
JSONObject apsField = new JSONObject();
|
||||
apsField.put("alert", alert);
|
||||
if (message.hasCustomSoundFile())
|
||||
apsField.put("sound", message.getCustomSoundFile());
|
||||
|
||||
payload.put("apsField", apsField);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -6,6 +6,8 @@ import com.alibaba.fastjson.JSONObject;
|
||||
/**
|
||||
* <a href="https://doc.yunxin.163.com/messaging/server-apis/DQyNjc5NjE?platform=server#apns%E6%8E%A8%E9%80%81%E6%B6%88%E6%81%AF">云信推送</a>
|
||||
* <a href="https://doc.yunxin.163.com/messaging/guide/TY4MzU5MDc?platform=android#%E8%AE%BE%E7%BD%AE%E6%8E%A8%E9%80%81%E9%80%9A%E7%9F%A5%E6%A0%8F%E8%B7%B3%E8%BD%AC%E6%96%B9%E5%BC%8F">各端推送配置</a>
|
||||
* <p/>
|
||||
* 文字, 链接、声音
|
||||
*
|
||||
* @author yanglin
|
||||
*/
|
||||
|
||||
@ -14,18 +14,18 @@ public class RYPushPayloadBuilder implements PushPayloadBuilder {
|
||||
|
||||
@Override
|
||||
public void build(PushMessageContent message, JSONObject payload) {
|
||||
if (!message.hasAndroidPushUrl()) return;
|
||||
|
||||
// 点击事件的内容
|
||||
JSONObject clickAction = new JSONObject();
|
||||
clickAction.put("type", 1);
|
||||
clickAction.put("intent", message.getAndroidPushUrl());
|
||||
clickAction.put("url", message.getAndroidPushUrl());
|
||||
|
||||
// 通知的内容
|
||||
JSONObject notification = new JSONObject();
|
||||
notification.put("clickAction", clickAction);
|
||||
JSONObject honorField = new JSONObject();
|
||||
if (message.hasAndroidPushUrl())
|
||||
honorField.put("clickAction", clickAction);
|
||||
|
||||
payload.put("honorField", notification);
|
||||
payload.put("honorField", honorField);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,7 +1,9 @@
|
||||
package cn.axzo.msg.center.nimpush.payload;
|
||||
|
||||
import cn.axzo.msg.center.inside.notices.config.PushProps;
|
||||
import cn.axzo.msg.center.nimpush.PushMessageContent;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
@ -10,10 +12,19 @@ import org.springframework.stereotype.Component;
|
||||
* @author yanglin
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class XMPushPayloadBuilder implements PushPayloadBuilder {
|
||||
|
||||
private final PushProps pushProps;
|
||||
|
||||
@Override
|
||||
public void build(PushMessageContent message, JSONObject payload) {
|
||||
PushProps.ChannelConfig xmCfg = pushProps.getXiaomiChannelConfig();
|
||||
payload.put("channel_id", message.determineChannelId(xmCfg));
|
||||
if (message.hasCustomSoundFile())
|
||||
payload.put("sound", message.getCustomSoundFile());
|
||||
if (message.hasAndroidPushUrl())
|
||||
payload.put("intent_uri", message.getAndroidPushUrl());
|
||||
}
|
||||
|
||||
}
|
||||
@ -11,7 +11,7 @@ public interface PushMessage {
|
||||
|
||||
String getPushTitle();
|
||||
|
||||
String getPushSubtitle();
|
||||
String getContent();
|
||||
|
||||
@Nullable
|
||||
UrlConfig getPushUrl();
|
||||
|
||||
@ -122,7 +122,7 @@ public class ParsedModelV3 implements MessageButtonProvider<ParsedButtonV3>, Pus
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPushSubtitle() {
|
||||
public String getContent() {
|
||||
return template.getContent();
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user