我有一个APPA。对于该APP A,我有2个Firebase项目C,D。从App A信息中,所有数据都存储在C数据库中。我正在从C数据库获取设备令牌,并在后端将设备令牌发送到数据库D。和存储在数据库D中。我已经实现了所有代码以在数据库D中发送通知。现在我没有收到到应用A的通知。
向APP A发送通知的代码。
exports.notifications= functions.https.onRequest((req,res) =>{
var senderauthid = req.body.SenderAuthID;
var senderautoid1 = req.body.SenderAutoID;
var receiveramount = req.body.Amount;
var receiverauthid = req.body.ReceiverAuthID;
var receiverFCMToken = req.body.FcmToken;//
我在这里从APP A获取令牌
console.log("receiverfcm",receiverFCMToken);
console.log("receiverauthid",receiverauthid);
console.log("senderautoid1",senderautoid1);
const db = admin.firestore();
var cityRef = db.collection('deyaPayUsers').doc(receiverauthid);
var setWithOptions = cityRef.set({
FCMToken: receiverFCMToken
}, { merge: true }); // Here Iam storing the FCM token in Database D.
var senderdetails = db.collection('deyaPayUsers').doc(senderauthid);
var sendergetinfo = db.runTransaction(drt =>{
return drt.get(senderdetails)
.then(doc => {
var senderphonenumber = doc.data().PhoneNumber;//Sender phonenumber
const receiverdetails = db.collection('deyaPayUsers').doc(receiverauthid);//receiver details
var msg = senderphonenumber + " "+ "requested you to pay $" +receiveramount;
let payload = { //This is for sending notification message
notification: {
title: "Message",
body: msg,
sound: "default",
},
'data':{// these is the data it calls in the messagereceived method
'Amount':String(receiveramount),
'SenderID':senderauthid,
'ReceiverId':receiverauthid,
'SenderPhoneNumber':String(senderphonenumber),
'SenderAutoId':senderautoid1,
//'SenderName':Sendertotalname,
'code':"100",
}
};//payload
console.log(payload);
return admin.messaging().sendToDevice(receiverFCMToken, payload).then((response)=> { // This method is used for returning the notification to a specific device
console.log(receiverFCMToken);
console.info("Successfully sent notification")
return res.status(200).json({Token : "Successfully sent notification"});
}).catch(function(error) {
console.warn("Error sending notification " , error)
});//end of notification
//});
//});//receiverdoc
});
});
在日志中,它显示成功发送通知。但是应用程序A没有收到通知。请提供任何解决方案。