Created
September 29, 2020 04:33
-
-
Save raihan-uddin/d328c5feff76fdea23e8e8206eb42c9c to your computer and use it in GitHub Desktop.
PHP FIREBASE PUSH NOTIFICATION
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function sendPushNotification($to = '', $data = array()){ | |
$apiKey = ''; | |
$fields = ['to' => $to, 'notification' => $data]; | |
$headers = ['Authorization: key='.$apiKey, 'Content-Type: application/json']; | |
$url = 'https://fcm.googleapis.com/fcm.send'; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_POST, true); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_PROXY_SSL_VERIFYPEER, false); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields)); | |
$result = curl_exec($ch); | |
curl_close(); | |
return json_decode($result, true); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment