问题描述
如何从 PHP 网站向 iOS 设备和 Android 设备发送推送通知?
How I can send push notification from PHP website to iOS devices and Android devices?
有相关教程吗?
推荐答案
您可以使用多种预制服务来推送通知,例如 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.
这篇关于如何从 PHP 网站向 iOS 和 Android 发送推送通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!