-问题描述:
在线推送获取的payload有问题
-复现步骤:
1.推送到通知栏
2.点击通知栏内容
3.触发click事件
4.输出msg
前端代码:
plus.push.addEventListener('click', (msg) => {
console.log('addEventListener click: ', JSON.stringify(msg));
});
离线推送输出(正确的):
{
"UUID": "androidPushMsg202729679",
"title": "有人在门前按铃",
"appid": "_UNI_AE15791",
"content": "设备发出警报请前往app查看",
"payload": {
"createTime": 1612318930600,
"devicesCode": "secived",
"title": "有人在门前按铃",
"content": "{\"img\":[\"000022b79dddabdc118204642a0ea830\",\"000022b79dddabdc118204642a0ea830\"],\"content\":\"设备发出警报请前往app查看\"}"
}
}
在线推送输出(有问题的):
{
"__UUID__": "androidPushMsg1025655497",
"title": "有人在门前按铃style",
"appid": "__UNI__AE15791",
"content": "设备发出警报请前往app查看",
"payload": {
"title": "有人在门前按铃style",
"content": "设备发出警报请前往app查看"
}
}
后端在线推送相关代码:
NotificationTemplate template = new NotificationTemplate();
template.setAppId(confJson.getString("appId"));
template.setAppkey(confJson.getString("appKey"));
Style0 style = new Style0();
style.setTitle(title+"style");//在线推送的payload明显是把这个放进去了
style.setText(text);
style.setLogoUrl(confJson.getString("logo"));
style.setRing(true);
style.setVibrate(true);
style.setClearable(true);
style.setChannelLevel(4);
template.setStyle(style);
Notify notify = new Notify();
notify.setTitle(title);
notify.setContent(text);
String intent = "intent:#Intent;action=android.intent.action.oppopush;launchFlags=0x14000000;component=io.dcloud." + confJson.getString("package") + "/io.dcloud.PandoraEntry;S.UP-OL-SU=true;S.title=有人在门前按铃;S.content=有人在门前按铃";
if (null != paramJosn) {
intent = intent + ";S.payload=" + paramJosn.toString();
}
intent = intent + ";end";
notify.setIntent(intent);
notify.setType(GtReq.NotifyInfo.Type._intent);
template.set3rdNotifyInfo(notify);
APNPayload payload = new APNPayload();
payload.setAutoBadge("1");
payload.setContentAvailable(0);
payload.setSound("default");
if (null != paramJosn)
{
for (String key : paramJosn.keySet()) {
payload.addCustomMsg(key, paramJosn.get(key).toString());
}
template.setTransmissionContent(paramJosn.toString());
}
APNPayload.DictionaryAlertMsg alertMsg = new APNPayload.DictionaryAlertMsg();
alertMsg.setTitle(title+"alert");
alertMsg.setBody(text);
payload.setAlertMsg(alertMsg);
MultiMedia multiMedia = new MultiMedia();
multiMedia.setResUrl(confJson.getString("logo"));
multiMedia.setResType(MultiMedia.MediaType.pic);
multiMedia.setOnlyWifi(false);
multiMedia.setResId(MD5.createKey());
payload.addMultiMedia(multiMedia);
template.setAPNInfo(payload);
template.setTransmissionType(1);
template.setTransmissionContent(paramJosn.toString());
return template;
请看style.setTitle(title+"style");这一行,
对照在线推送输出JSON(看看那个我特意标记的style):
{
"__UUID__": "androidPushMsg1025655497",
"title": "有人在门前按铃style",
"appid": "__UNI__AE15791",
"content": "设备发出警报请前往app查看",
"payload": {
"title": "有人在门前按铃style",
"content": "设备发出警报请前往app查看"
}
}
在线推送的payload明显是把这个style的title和body放进去了
payload正确情况下应该放的是payload.addCustomMsg(k,v)或者是intent 的内容
对了,在线推送时触发receive能拿到正确的payload信息,但这个是推送到了就触发的,前端要的是click,点击通知栏推内容送后触发的
plus.push.addEventListener('receive', (msg) => {
console.log('addEventListener receive: ', JSON.stringify(msg));
});
以上代码都是android环境下运行的,ios还没测试过
目前离线推送正常
0 个回复