Created
April 1, 2014 21:21
-
-
Save Chiggins/9923471 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// You put your own App ID and Sender IDs | |
define("GOOGLE_APP_ID", "AIxxxxxxxxx"); | |
define("SENDER_ID", "xxxxxxxxxx"); | |
// Device ID to send the message to | |
$deviceId = "insertdeviceidhere"; | |
$message = "Message from PHP!"; | |
// Create the POST request | |
$request = "https://android.googleapis.com/gcm/send"; | |
$postData = "collapse_key=score_update&time_to_live=108&delay_while_idle=1&data.message={$message}&data.time=" . date("Y-m-d H:i:s") . "®istration_id={$deviceId}"; | |
echo "Sending request to {$request} with postData {$postData}"; | |
$session = curl_init($request); | |
// Set HTTP headers | |
curl_setopt($session, CURLOPT_HTTPHEADER, array("Authorization: key=" . GOOGLE_APP_ID, "Sender: id=" . SENDER_ID, "Content-Type: application/x-www-form-urlencoded;charset=UTF-8")); | |
// Make it so it's a POST request | |
curl_setopt($session, CURLOPT_POST, true); | |
curl_setopt($session, CURLOPT_POSTFIELDS, $postData); | |
// Don't return headers, but get the response | |
curl_setopt($session, CURLOPT_HEADER, false); | |
curl_setopt($session, CURLOPT_RETURNTRANSFER, true); | |
echo "Sending..."; | |
$response = curl_exec($session); | |
curl_close($session); | |
echo "Response: {$response}"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment