web应用中未收到Firebase云消息通知

web应用中未收到Firebase云消息通知,firebase,push-notification,google-cloud-functions,firebase-cloud-messaging,Firebase,Push Notification,Google Cloud Functions,Firebase Cloud Messaging,我使用FCM进行通知。从Firebase数据库创建数据时触发FCM。我收到了第一条信息。在此之后,不会收到其他连续消息。我在本地环境中运行这个。问题是由于以下消息“未配置计费帐户。无法访问外部网络且配额受到严重限制。请配置计费帐户以删除这些限制”或任何其他问题造成的。我是否需要为接收信息制定一个计费计划。在测试环境中工作,这就是不转到计费计划的原因。如果问题与计费计划无关,则有人可以指出代码的任何其他问题 Firebase函数日志 6:22:52.133 PM sendFollowerNotif

我使用FCM进行通知。从Firebase数据库创建数据时触发FCM。我收到了第一条信息。在此之后,不会收到其他连续消息。我在本地环境中运行这个。问题是由于以下消息“未配置计费帐户。无法访问外部网络且配额受到严重限制。请配置计费帐户以删除这些限制”或任何其他问题造成的。我是否需要为接收信息制定一个计费计划。在测试环境中工作,这就是不转到计费计划的原因。如果问题与计费计划无关,则有人可以指出代码的任何其他问题

Firebase函数日志

6:22:52.133 PM
sendFollowerNotification
Function execution started
6:22:52.133 PM
sendFollowerNotification
Billing account not configured. External network is not accessible and quotas are severely limited. Configure billing account to remove these restrictions
6:22:52.143 PM
sendFollowerNotification
Function execution took 10 ms, finished with status: 'ok'
6:22:52.401 PM
sendFollowerNotification
1 messages were sent successfully
节点js代码

exports.sendFollowerNotification = functions.database.ref('/notification/message/{gId}/{pId}')
        .onCreate(async (change, context) => {
    
          //console.log('Group id:', context.params.gId," Push ID:",context.params.pId, "Change",change);
          
          const notificationData =  change.val();
          var topic = notificationData.topic;
          var title = notificationData.title;
          var body = notificationData.body;
          var registrationTokens = notificationData.tokens;
    
          const message = {
            notification: {
              title: title,
              body: body
            },
            tokens: registrationTokens,
          };
    
          admin.messaging().sendMulticast(message)
          .then((response) => {
            // Response is a message ID string.
            console.log(response.successCount + ' messages were sent successfully');
          })
          .catch((error) => {
            console.log('Error sending message:', error);
          });
          
        });

我想这也许能回答你的问题:

由于计划于2020年8月17日对其基础架构进行更新,Firebase的云功能将依赖于一些额外的付费谷歌服务:云构建、容器注册和云存储。这些架构更新将适用于部署到Node.js 10运行时的功能。除现有定价外,还将对这些服务的使用进行计费

在新架构中,云构建支持功能的部署。您将只为构建函数的运行时容器所需的计算时间付费

另一方面,服务本身是免费的:

Firebase Cloud Messaging(FCM)在您的服务器和设备之间提供了一个可靠且电池效率高的连接,允许您在iOS、Android和web上免费发送和接收消息和通知


鉴于您正在CFs中使用节点,平台要求您提供一个计费帐户。

该消息并不表示有错误。这只是一个警告,让您知道,如果您的项目不在付款计划中,则出站网络将不起作用。FCM消息不属于此类别-它应该可以工作

问题在于,您的代码没有返回在所有异步工作完成后解决的承诺。现在,它什么也不返回,函数在消息发送前立即终止。请阅读并理解有关此的信息

至少,您需要返回承诺链,让云功能知道消息何时发送,并且可以安全终止

          return admin.messaging().sendMulticast(message)
          .then((response) => {
            // Response is a message ID string.
            console.log(response.successCount + ' messages were sent successfully');
          })
          .catch((error) => {
            console.log('Error sending message:', error);
          });
注意上面的return关键字


如果消息仍然没有被发送,那么这里还有一些我们看不到的问题。您可能没有正确处理设备令牌。

这实际上根本不是问题所在。如果是这样的话,那么就会出现实际的错误,而不仅仅是警告。看来账单警告并不是没有收到通知的真正原因。不管怎样,谢谢你的回复。非常感谢,很抱歉没有及时回复你。它工作得很好。