Come posso inviare una notifica push dal sito Web PHP a iOS e Android?

Aug 28 2020

Come posso inviare notifiche push dal sito Web PHP a dispositivi iOS e dispositivi Android?

C'è qualche tutorial per questo?

Risposte

1 MuhammadZubair Aug 28 2020 at 11:12

Puoi utilizzare diversi servizi predefiniti per le notifiche push come Firebase Messaging, One Signal, ecc. Per l'integrazione di Firebase cloud Messaging con PHP, visita questo link . Dopo la configurazione, invia questa richiesta POST con il token utente

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

o Invia una notifica push utilizzando l'argomento

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

Per One Signal, visitare questo collegamento per ulteriori informazioni. Inoltre, in alternativa, puoi utilizzare i web socket, se non desideri servizi premade.