-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend-fcm.php
55 lines (46 loc) · 1.28 KB
/
send-fcm.php
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
49
50
51
52
53
54
55
<?php
class startSendNotification
{
function sendNoti($titleNoti, $bodyNoti, $actionNoti){
// API access key from Google FCM App Console (Server Key)
define( 'API_ACCESS_KEY', '');
$registrationIDs = [
"xxxxxxxxxx"
];
$fcmMsg = array(
'title' => $titleNoti,
'body' => $bodyNoti,
'icon' => 'image/look24-logo-s.png',
'click_action' => $actionNoti
);
$fcmFields = array(
//'to' => $singleID,
'registration_ids' => $registrationIDs,
'priority' => 'high',
'notification' => $fcmMsg
);
$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( $fcmFields ) );
$result = curl_exec($ch );
curl_close( $ch );
echo $result . "\n\n";
}
}
?>
<?php
// How to use
$titleNoti = "Hello test";
$bodyNoti = "Morning test";
$actionNoti = "https://medium.com/@ptuckyeagle";
$callNoti = new startSendNotification();
$callNoti->sendNoti($titleNoti, $bodyNoti, $actionNoti);
?>