F君
F君
  • 发布:2025-03-10 16:26
  • 更新:2025-03-10 16:26
  • 阅读:53

【报Bug】createPushMessage自定义消息字段,App内无法获取,但是通过firebase接口发送的自定义字段能够获取到

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Mac

PC开发环境操作系统版本号: macOs Sonoma 14.1

HBuilderX类型: 正式

HBuilderX版本号: 4.15

手机系统: Android

手机系统版本号: Android 15

手机厂商: 三星

手机机型: S23

页面类型: nvue

vue版本: vue2

打包方式: 云端

项目创建方式: 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: '.../testData/BZ-LJC/test/2.png'  
    },  

    data: {   
        "my_key": "new key",  
        "my_another_key": "key 2"  
    }  
};  

使用以上代码就可以将自定义字段(notification中的imageUrl和data对象)都能在App中FirebaseMessagingService 的onMessageReceived中获取到。

请帮忙反馈以上问题原因?是没有实现相关字段透传还是什么问题呢

2025-03-10 16:26 负责人:无 分享
已邀请:

要回复问题请先登录注册