Kleine Funktion, mit der es möglich ist Push Mitteilungen über den GoogleCloud Message Dienst an registrierte Android Geräte zu versenden.
function android_sendPush($arDeviceIDs, $data)
{
$apiKey = ''; // API Schlüssel eintragen
$url = 'https://android.googleapis.com/gcm/send';
$post = array(
'registration_ids' =>$arDeviceIDs,
'data' => $data
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: key='.$apiKey,
'Content-Type: application/json'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post));
$result = curl_exec($ch);
if (curl_errno($ch))
{
die('CURL Fehler: '.curl_error($ch));
curl_close($ch);
return 0;
}
return sizeof($arDeviceIDs);
}