-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added php example using google's Firebase endpoint
- Loading branch information
Ani Sinanaj
committed
Jan 10, 2017
1 parent
f6aed79
commit 37c9ce7
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/php | ||
<?php | ||
function sendGCM($message, $id) { | ||
|
||
|
||
$url = 'https://fcm.googleapis.com/fcm/send'; | ||
|
||
$fields = array ( | ||
'registration_ids' => array ( | ||
$id | ||
), | ||
"data" => [ | ||
"data" => [ | ||
"alert" => "Testing " . time(), | ||
"title" => "The title", | ||
"vibrate" => [100,50,50,50,100], | ||
"badge" => 1, | ||
"tag" => "APP" | ||
] | ||
] | ||
); | ||
$fields = json_encode ( $fields ); | ||
|
||
$headers = array ( | ||
'Authorization: key=' . "<AUTH KEY>", | ||
'Content-Type: application/json' | ||
); | ||
|
||
$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_POSTFIELDS, $fields ); | ||
|
||
$result = curl_exec ( $ch ); | ||
echo $result; | ||
curl_close ( $ch ); | ||
} | ||
|
||
sendGCM("Test", "DEVICE TOKEN"); |