.NET Core Web API 推送到 Apple/Android 推送通知服务器

zla*_*yaa 6 android push-notification apple-push-notifications signalr asp.net-core

我在 .NET Core Web API 中有聊天服务,当客户端在线时通过 Signal R 处理聊天消息。

另外,我有移动客户端(android/apple),我需要处理客户端处于离线模式时发送的消息。我知道客户是否离线/在线。因此,当客户端离线时,我想向苹果/安卓推送通知服务器发送消息,以便它可以通知设备有关新消息的信息。

我必须使用哪些选项将 net core Web API 连接到 android/apple 推送通知服务器?从 .net 服务向移动客户端发送客户端推送通知的任何经验?

小智 1

您需要使用以下参数向https://fcm.googleapis.com/fcm/send发出\xc2\xa0POST 请求\n标头

\n\n
    \n
  • 授权: key=YOUR_SERVER_KEY
  • \n
  • 内容类型: Application/JSON
  • \n
\n\n

身体:

\n\n
{\n "to" : "YOUR_FCM_TOKEN_WILL_BE_HERE",\n "collapse_key" : "type_a",\n "notification" : {\n     "body" : "First Notification",\n     "title": "Collapsing A"\n },\n "data" : {\n     "body" : "First Notification",\n     "title": "Collapsing A",\n     "key_1" : "Data for key one",\n     "key_2" : "Hellowww"\n }\n
Run Code Online (Sandbox Code Playgroud)\n\n

您可以从 获取您的服务器令牌Firebase Console。此外,您还需要设置 APN才能在 iOS 上运行。\n您可以在此处找到更多信息

\n