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: '.../testData/BZ-LJC/test/2.png'
},
data: {
"my_key": "new key",
"my_another_key": "key 2"
}
};
使用以上代码就可以将自定义字段(notification中的imageUrl和data对象)都能在App中FirebaseMessagingService 的onMessageReceived中获取到。
请帮忙反馈以上问题原因?是没有实现相关字段透传还是什么问题呢
0 个回复