FCM发送测试消息(控制台和postman)

方法1 在firebase控制台新建通知

image-20211105162032783

  • 点击cloud messaging后点击新建通知

  • 输入标题和内容,点击右边的发送测试消息,注意要在真机接收,模拟器收不到

    image-20211105162250607

  • 然后添加测试令牌,测试令牌可以在app中调用以下代码获取设备的令牌

    token = await FirebaseMessaging.instance.getToken();
    

    image-20211105162452467

  • 点击测试就完成了

方法2 通过postman直接发送

  • 打开postman,url为:

    https://fcm.googleapis.com/fcm/send
    

    配置header:

    Authorization:key=服务器密钥

    Content-Type:application/json

    注意Authorization的值是key = 服务器密钥,如图

    image-20211105162951994

  • 服务器密钥在firebase控制台项目设置中

    image-20211105163120465

  • 然后回到postman中配置body信息

    image-20211105163240743

  • 这里的to就是前面获取的特定设备的token令牌

    Nitification中填写body和type,data中封装自定义信息

    {
    		"to": "eoTre9OAQeiaXYfBTC7JVt:APA91b......",
    		"notification": {
    			"body" : "receive a new message",
    			"title" : ""message title"
    		},
      	 	"data": {
      	 		"type":"chat"
      	 	}
    }
    
  • 点击send,查看response

image-20211105164115293

  • 发送成功!

参考:https://blog.csdn.net/liwenjie0912/article/details/118559806

posted @ 2021-11-05 16:42  R1cardo  阅读(854)  评论(0编辑  收藏  举报