-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.php
More file actions
48 lines (42 loc) · 1.12 KB
/
Copy pathindex.php
File metadata and controls
48 lines (42 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
function sendPushNotification($fields = array())
{
$API_ACCESS_KEY = 'Your API Key';
$headers = array
(
'Authorization: key=' . $API_ACCESS_KEY,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch );
curl_close( $ch );
echo $result;
}
$title = "Test";
$message = "Hello World";
$fields = array
(
'to' => '/topics/Your topic name',
'priority' => 'high',
'notification' => array(
'body' => $message,
'title' => $title,
'sound' => 'default',
'icon' => '',
'image'=> ''
),
'data' => array(
'message' => $message,
'title' => $title,
'sound' => 'default',
'icon' => '',
'image'=> ''
)
);
sendPushNotification($fields);