Created
October 1, 2015 15:39
-
-
Save phpfiddle/c12cf0475e97f3cf19c1 to your computer and use it in GitHub Desktop.
[ Posted by Ayush ] This is php code to test android push notifications (GCM) online. Just replace API key and device ids. It will send a notification with key "alert".
This file contains hidden or 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
<?php | |
// API access key from Google API's Console | |
define( 'API_ACCESS_KEY', 'AIzaSyDD5cwKE6O252bVA766Lyo2cQhG7RbShWA' ); | |
$registrationIds = array("erKXJiDIdiY:APA91bE3N0Bfh6e7tpIT2qcHBD_vqg6ObMQHyrbXEAf6MQqeHcGSauArLzoQRvWb7VpHY_hReEdfw3WxU5Ybk95dWnGT2KAQmC9cHAajuDQx5kJu1Ic2QJKuu3vYNtuRAo6edfuMrbJj" ); | |
// prep the bundle | |
$msg = array | |
( | |
'alert' => 'here is a message. message', | |
); | |
$fields = array | |
( | |
'registration_ids' => $registrationIds, | |
'data' => $msg | |
); | |
$headers = array | |
( | |
'Authorization: key=' . API_ACCESS_KEY, | |
'Content-Type: application/json' | |
); | |
$ch = curl_init(); | |
curl_setopt( $ch,CURLOPT_URL, 'https://gcm-http.googleapis.com/gcm/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; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment