This repository has been archived by the owner on Jul 26, 2019. It is now read-only.
forked from caffeinalab/ti.goosh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-fcm
executable file
·66 lines (55 loc) · 1.54 KB
/
test-fcm
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
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/php
<?php
$ID = getenv('DEVICE_ID');
$KEY = getenv('SERVER_KEY');
if (empty($KEY)) {
$KEY = "AIzaSyAKhb8Q5B0EOtpQ5u087hbxKvT0O_vP9jc";
}
function sendGCM($id, $auth) {
$url = 'https://android.googleapis.com/gcm/send';
return post($url, headers($auth), fields($id));
}
function sendFCM($id, $auth) {
$url = 'https://fcm.googleapis.com/fcm/send';
return post($url, headers($auth), fields($id));
}
function fields($id) {
return json_encode( array (
'registration_ids' => array ( $id ),
"data" => [ "data" => payload() ]
) );
}
function headers($auth) {
return array (
'Authorization: key=' . $auth,
'Content-Type: application/json'
);
}
function payload() {
return [
"alert" => "Testing " . time(),
"title" => "The title ". time(),
"vibrate" => [100,50,50,50,100],
"sound" => "default",
"badge" => 1,
"tag" => "TestApp",
"group" => "Group x",
"group_summary" => 1,
"force_show_in_foreground" => false,
"priority" => "max"
];
}
function post($url, $headers, $data) {
$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_SSL_VERIFYPEER, false );
curl_setopt ( $ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data );
$result = curl_exec ( $ch );
curl_close ( $ch );
return $result;
}
echo sendFCM($ID, $KEY);