createPushMessage自定义消息字段在uni-app中App内无法获取但是通过firebase接口发送的自定义字段能够获取到
createPushMessage自定义消息字段在uni-app中App内无法获取但是通过firebase接口发送的自定义字段能够获取到
开发环境 | 版本号 | 项目创建方式 |
---|---|---|
Mac | macOs Sonoma 14.1 | HBuilderX |
操作步骤:
curl --location 'xxxuni/push/new' \
--header 'Content-Type: application/json' \
--header 'Cookie: acw_tc=ac11000117393482524063327ee1d6bb200c63bd8a647219df95ea0abab144; aliyungf_tc=024f713a238d6143b389a77ca4e37ca0862fbf37bad763fe92ba7c16ce3dfd75' \
--data '{
"push_clientid": [
"xxx"
],
"payload": {
"messageCode": "3fb047ec50f7afeca2a0c41673a9732d",
"imageUrl": "../test/2.png",
"notification": {
"test": "xxxxx"
},
"push_message": {
"notification": {
"title": "请填写通知标题",
"body": "请填写通知内容",
"click_type": "url",
"url": "https//:xxx"
}
}
}'
预期结果:
- 能获取到对应自定义消息字段
实际结果:
- 没能在App中FirebaseMessagingService 的onMessageReceived中获取到。
bug描述:
const uniPush = uniCloud.getPushManager({
appId: "__UNI__1081090"
})
exports.main = async (event) => {
let obj = JSON.parse(event.body)
const res = await uniPush.sendMessage({
...obj,
"push_clientid": push_clientid, // 设备id,支持多个以数组的形式指定多个设备,如["cid-1","cid-2"],数组长度不大于1000
"title": obj.title, // 标题
"content": obj.content, // 内容
"payload": obj.payload, // 数据
"force_notification": true, // 服务端推送 需要加这一句
"request_id": request_id, //请求唯一标识号,10-32位之间;如果request_id重复,会导致消息丢失
"options": obj.options, //消息分类,没申请可以不传这个参数
})
return res;
};
以上内容为我们的云函数实现,下面是我们尝试过的数据结构,
"push_clientid": [
"..."
],
"payload": {
"messageCode": "3fb047ec50f7afeca2a0c41673a9732d",
"imageUrl": "...est/2.png",
...
}
"notification": {
"test": "xxxxx"
},
"data": {
"my_key": "new key",
"my_another_key": "key 2"
}
尝试过各种数据结构,App内无法获取,然后我们尝试直接调用firebase api
const admin = require('firebase-admin');
const serviceAccount = require('./serverkey.json');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
});
const messaging = admin.messaging();
var message = {
token: '...',
notification: {
title: '通知',
body: '内容',
imageUrl: '../test/2.png'
},
data: {
"my_key": "new key",
"my_another_key": "key 2"
}
};
更多关于createPushMessage自定义消息字段在uni-app中App内无法获取但是通过firebase接口发送的自定义字段能够获取到的实战教程也可以访问 https://www.itying.com/category-93-b0.html
1 回复
更多关于createPushMessage自定义消息字段在uni-app中App内无法获取但是通过firebase接口发送的自定义字段能够获取到的实战教程也可以访问 https://www.itying.com/category-93-b0.html
根据你的描述,问题出在uni-app推送消息的自定义字段无法在App端获取,而直接调用Firebase API可以。以下是关键点分析:
-
uni-app推送服务在Android平台使用的是厂商通道和Firebase混合推送机制,自定义字段需要特别注意格式。
-
正确的payload结构应该是:
{
"push_clientid": ["xxx"],
"title": "标题",
"content": "内容",
"payload": {
"data": {
"customKey1": "value1",
"customKey2": "value2"
}
},
"force_notification": true
}