Skip to content

Instantly share code, notes, and snippets.

@silalahi
Created July 3, 2012 12:15
Show Gist options
  • Save silalahi/3039397 to your computer and use it in GitHub Desktop.
Save silalahi/3039397 to your computer and use it in GitHub Desktop.
GCM PHP Source COde
<?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