How can I send push notification from PHP website to iOS and Android?

被刻印的时光 ゝ 提交于 2020-11-29 23:47:35

问题


How I can send push notification from PHP website to iOS devices and Android devices?

Is there any tutorial for that?


回答1:


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

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



来源:https://stackoverflow.com/questions/63632358/how-can-i-send-push-notification-from-php-website-to-ios-and-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!