Skip to content

Instantly share code, notes, and snippets.

@insthync
Created June 9, 2017 09:54
Show Gist options
  • Save insthync/1fc93f76220652f450468e01d068dc90 to your computer and use it in GitHub Desktop.
Save insthync/1fc93f76220652f450468e01d068dc90 to your computer and use it in GitHub Desktop.
GCM with PHP + Curl
$header = array();
$header[] = "Content-Type: application/json";
$header[] = "Authorization: key=$your_key";
$requestData = array();
$requestData['title'] = $title;
$requestData['message'] = $message;
$registration_ids = array();
$registration_ids[] = $registration_id_1;
$registration_ids[] = $registration_id_2;
$registration_ids[] = $registration_id_3;
$sendingData = array();
$sendingData['data'] = $requestData;
$sendingData['registration_ids'] = $registration_ids;
$jsonData = json_encode($sendingData);
echo $jsonData;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://android.googleapis.com/gcm/send");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment