Created
July 4, 2012 08:04
-
-
Save silalahi/3046010 to your computer and use it in GitHub Desktop.
GCM Push Notification PHP
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 | |
// GCM Server URL | |
$url = 'https://android.googleapis.com/gcm/send'; | |
// Server API | |
// Didapat dari Google Console | |
$serverApiKey = "API KEY"; | |
// Device ID | |
// Didapat dari device | |
$reg = "DEVICE ID"; | |
// Data yang hendak di kirim | |
$data = array( | |
'registration_ids' => array($reg), | |
'data' => array('name' => 'Jogi Silalahi', 'location' => 'Jakarta') | |
); | |
// Header | |
$headers = array( | |
'Content-Type:application/json', | |
'Authorization:key=' . $serverApiKey | |
); | |
$message = json_encode($data); | |
$ch = curl_init(); | |
curl_setopt_array($ch, array( | |
CURLOPT_URL => $url, | |
CURLOPT_HTTPHEADER => $headers, | |
CURLOPT_POST => true, | |
CURLOPT_RETURNTRANSFER => true, | |
CURLOPT_POSTFIELDS => $message | |
)); | |
$response = curl_exec($ch); | |
curl_close($ch); | |
// Debugging | |
echo $response; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment