且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2022-11-26 14:21:13

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

You can use several premade services for push notifications like Firebase Messaging, One Signal, etc. For Firebase cloud Messaging Integration with PHP, please visit this Link. After setting up, Just Send this POST request with the user token

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"
      }
    }
  }
}

或使用主题发送推送通知

or Send a Push Notification using topic

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"
      }
    }
  }
}

对于 One Signal,请访问此链接了解更多信息.此外,如果您不想要预制服务,也可以使用网络套接字.

For One Signal, Visit this Link for more information. Also, alternatively, you can use web sockets, if you don't want premade services.