forked from ArtooTrills/Bounty-Food-Locator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFirebase.php
More file actions
45 lines (36 loc) · 1.36 KB
/
Copy pathFirebase.php
File metadata and controls
45 lines (36 loc) · 1.36 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
<?php
class Firebase {
public function sendPushNotification($to,$msg) {
$fields = array(
'to' => $to,
'data' => array( "message" => $msg ),
);
// Set POST variables
define("GOOGLE_API_KEY", "AAAAlFNrAlw:APA91bH6GpcEf4fwkqTVjT2uWA4-wx7ZhV42-9dNqa1S9bC3lQCQFBsV4ikqF7IKBalw9YUeKJOYP7yu8F_aRcZJQPOCSAHCuMEyxJbWlPwbxg3mizYrn5k5VANAG-aNlD2t4XHOguMy");
$url = 'https://fcm.googleapis.com/fcm/send';
$headers = array(
'Authorization: key=' . GOOGLE_API_KEY,
'Content-Type: application/json'
);
// Open connection
$ch = curl_init();
// Set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Disabling SSL Certificate support temporarly
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
// Execute post
$result = curl_exec($ch);
echo $result;
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
// Close connection
curl_close($ch);
return $result;
}
}
?>