如何从旧版 FCM API 迁移到 HTTP v1 以实现 flutter

问题描述 投票:0回答:1

我尝试按照文档进行操作,但无法使其工作我不知道新版本中的授权如何工作我尝试下载新的私钥,但不知道如何使用它使用该授权方法向特定用户发送通知

这个我的代码

      void sendPushMessage(String token, String body, String title) async {
    await http.post(Uri.parse('https://fcm.googleapis.com/fcm/send'),
        headers: <String, String>{
          'Content-Type': 'application/json',
          'Authorization':
              'private key'
        },
        body: jsonEncode(<String, dynamic>{
          'Priority': 'high',
          'data': <String, dynamic>{
            'click_action': 'FLUTTER_NOTIFICATION_CLICK',
            'status': 'done',
            'title': title,
            "sound": "test.wav",
          },
          'notification': <String, dynamic>{
            'title': title,
            'body': body,
            "sound": "test.wav",
            'android_channel_id': ''
          },
          'to': token
        }));
  }

如何升级到这个

       void sendPushMessage(String token, String body, String title) async {
    await http.post(Uri.parse('https://fcm.googleapis.com/fcm/send'),
        headers: <String, String>{
          'Content-Type': 'application/json',
          'Authorization':
              'how do I get this key'
        },
        body: jsonEncode(<String, dynamic>{
    "message": {
        "token": "token",
        "notification": {
            "body": "This is an FCM notification message!",
            "title": "FCM Message",
            "sound": "sound.mp3"
        }
    }
}));
  }
flutter firebase push-notification firebase-cloud-messaging
1个回答
0
投票

Click on Private key image here

转到您的项目,然后进行设置
然后选择云消息,您将看到您的服务器密钥

© www.soinside.com 2019 - 2024. All rights reserved.