Skip to content

Instantly share code, notes, and snippets.

@silalahi
Created July 4, 2012 08:04
Show Gist options
  • Save silalahi/3046010 to your computer and use it in GitHub Desktop.
Save silalahi/3046010 to your computer and use it in GitHub Desktop.
GCM Push Notification PHP
<?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