Przede wszystkim wykonaj Implementing GCM Client i zaimplementuj klienta gcm w swojej aplikacji na Androida.
Dla serwera GCM w php można go zaimplementować w następujący sposób. Edytuj swój kod zgodnie z potrzebami, np. Podczas pisania postu. Więcej informacji na temat wdrażania serwera GCM iść do Implementing GCM Server
<?php
// Replace with the real server API key from Google APIs
$apiKey = "your api key";
// Replace with the real client registration IDs
$registrationIDs = array("reg id1","reg id2");
// Message to be sent
$message = "Your message e.g. the title of post";
// Set POST variables
$url = 'https://android.googleapis.com/gcm/send';
$fields = array(
'registration_ids' => $registrationIDs,
'data' => array("message" => $message),
);
$headers = array(
'Authorization: key=' . $apiKey,
'Content-Type: application/json'
);
// Open connection
$ch = curl_init();
// Set the URL, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// curl_setopt($ch, CURLOPT_POST, true);
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
// Execute post
$result = curl_exec($ch);
// Close connection
curl_close($ch);
// print the result if you really need to print else neglate thi
echo $result;
//print_r($result);
//var_dump($result);
?>
Jest też dobra wiadomość Android Push Notifications dla początkujących.
Tutaj jesteś [Google Cloud Messaging na GitHub] (https://github.com/google/gcm) – BNK