【问题标题】:How can I send push notification from PHP website to iOS and Android?如何从 PHP 网站向 iOS 和 Android 发送推送通知?
【发布时间】:2020-12-17 07:17:14
【问题描述】:

如何从 PHP 网站向 iOS 设备和 Android 设备发送推送通知?

有教程吗?

【问题讨论】:

  • 你可以使用firebase和它的web api从网站发送通知。

标签: php android ios push


【解决方案1】:

您可以使用多种预制服务来推送通知,例如 Firebase 消息传递、One Signal 等。有关与 PHP 的 Firebase 云消息传递集成,请访问this Link。设置完成后,只需使用用户令牌发送此 POST 请求

POST https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send HTTP/1.1

Content-Type: application/json
Authorization: Bearer ya29.ElqKBGN2Ri_Uz...PbJ_uNasm

{
  "message": {
    "token" : <token of destination app>,
    "notification": {
      "title": "FCM Message",
      "body": "This is a message from FCM"
    },
    "webpush": {
      "headers": {
        "Urgency": "high"
      },
      "notification": {
        "body": "This is a message from FCM to web",
        "requireInteraction": "true",
        "badge": "/badge-icon.png"
      }
    }
  }
}

或使用主题发送推送通知

https://fcm.googleapis.com//v1/projects/<YOUR-PROJECT-ID>/messages:send
Content-Type: application/json
Authorization: bearer <YOUR-ACCESS-TOKEN>

{
  "message": {
    "topic": "matchday"
    "notification": {
      "title": "Background Message Title",
      "body": "Background message body"
    },
    "webpush": {
      "fcm_options": {
        "link": "https://dummypage.com"
      }
    }
  }
}

对于一个信号,请访问此Link 了解更多信息。此外,如果您不想要预制服务,也可以使用 Web 套接字。

【讨论】:

    猜你喜欢
    • 2016-12-18
    • 2015-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-28
    • 2015-11-23
    相关资源
    最近更新 更多