1#API access key from Google API's Console
2 define( 'API_ACCESS_KEY', 'YOUR-SERVER-API-ACCESS-KEY-GOES-HERE' );
3 $registrationIds = $_GET['id'];
4
5#prep the bundle
6 $msg = array
7 (
8 'body' => 'Body Of Notification',
9 'title' => 'Title Of Notification',
10 'icon' => 'myicon',/*Default Icon*/
11 'sound' => 'mySound'/*Default sound*/
12 );
13
14 $fields = array
15 (
16 'to' => $registrationIds,
17 'notification' => $msg
18 );
19
20
21 $headers = array
22 (
23 'Authorization: key=' . API_ACCESS_KEY,
24 'Content-Type: application/json'
25 );
26
27#Send Reponse To FireBase Server
28 $ch = curl_init();
29 curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );
30 curl_setopt( $ch,CURLOPT_POST, true );
31 curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
32 curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
33 curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
34 curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
35 $result = curl_exec($ch );
36 curl_close( $ch );
37
38#Echo Result Of FireBase Server
39echo $result;
40
41#https://gist.github.com/MohammadaliMirhamed/7384b741a5c979eb13633dc6ea1269ce
42
1<?php
2
3define( 'API_ACCESS_KEY', 'AIza......Xhdsnkf' ); // get API access key from Google/Firebase API's Console
4
5$registrationIds = array( 'cyMSGTKBzwU:APA91...xMKgjgN32WfoJY6mI' ); //Replace this with your device token
6
7
8// Modify custom payload here
9$msg = array
10(
11 'mesgTitle' => 'SMART TESTING',
12 'alert' => 'This is sample notification'
13
14);
15$fields = array
16(
17 'registration_ids' => $registrationIds,
18 'data' => $msg
19);
20
21$headers = array
22(
23 'Authorization: key=' . API_ACCESS_KEY,
24 'Content-Type: application/json'
25);
26
27$ch = curl_init();
28curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' ); //For firebase, use https://fcm.googleapis.com/fcm/send
29
30curl_setopt( $ch,CURLOPT_POST, true );
31curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
32curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
33curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
34curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
35$result = curl_exec($ch );
36curl_close( $ch );
37echo $result;
38
39?>
40