Created
July 3, 2012 12:15
-
-
Save silalahi/3039397 to your computer and use it in GitHub Desktop.
GCM PHP Source COde
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 = "YOUR SERVER 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); | |
// Untuk debug saja | |
echo $response; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment