Last active
March 4, 2016 14:49
-
-
Save blackcj/5976493 to your computer and use it in GitHub Desktop.
Revisions
-
blackcj revised this gist
Jul 11, 2013 . 2 changed files with 12 additions and 14 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,19 +1,18 @@ <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>GCM Sender</title> </head> <body> <h2>GCM Sender</h2> <form method="POST" name="input" action="gcm_sender.php" /> Device Token:<input name="deviceToken" /> <br /> API Key:<input name="apiKey" /> <br /> Message:<input name="message" /> <br /> Collapse Key:<input name="collapseKey" /> <br /> <input type="submit" value="Send Message"> </form> </body> </html> This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,10 @@ <?php function sendMessageToPhone() { $deviceToken = $_POST['deviceToken']; // Returned from GCM when a user opens the app, device specific $messageText = $_POST['message']; // Message that will be send to the user $collapseKey = $_POST['collapseKey']; // Key used to group messages, for example '123' $yourKey = $_POST['apiKey']; // Retrieve from https://code.google.com/apis/console/ $headers = array('Authorization:key=' . $yourKey); $data = array( @@ -42,7 +42,6 @@ function sendMessageToPhone() } if (isset($_POST['deviceToken'])) { sendMessageToPhone(); } -
blackcj revised this gist
Jul 11, 2013 . 2 changed files with 20 additions and 21 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>GCM Sender</title> </head> <body> <h2>GCM Sender</h2> <form method="POST" name="input" action="gcm_sender.php" /> Device Token:<input name="deviceToken" /> <br /> API Key:<input name="apiKey" /> <br /> Message:<input name="message" /> <br /> Collapse Key:<input name="collapseKey" /> <br /> <input type="submit" value="Send Message"> </form> </body> </html> This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -46,24 +46,4 @@ function sendMessageToPhone() sendMessageToPhone(); } ?> -
blackcj revised this gist
Jul 11, 2013 . No changes.There are no files selected for viewing
-
blackcj created this gist
Jul 11, 2013 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,69 @@ <?php function sendMessageToPhone() { $deviceToken = $_POST['deviceToken']; // Returned from GCM when a user opens the app, device specific $messageText = $_POST['message']; // Message that will be send to the user $collapseKey = $_POST['collapseKey']; // Key used to group messages, for example '123' $yourKey = $_POST['apiKey']; // Retrieve from https://code.google.com/apis/console/ $headers = array('Authorization:key=' . $yourKey); $data = array( 'to' => $deviceToken, 'collapse_key' => $collapseKey, 'data.message' => $messageText, 'delay_while_idle' => false, 'time_to_live' => 108, 'message_id' => uniqid('nerd_')); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://android.googleapis.com/gcm/send"); if ($headers) curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if (curl_errno($ch)) { //request failed return false;//probably you want to return false } if ($httpCode != 200) { //request failed return false;//probably you want to return false } curl_close($ch); $arr = array ('response'=>$response); echo json_encode($arr); return $response; } if (isset($_POST['deviceToken'])) { sendMessageToPhone(); } ?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>GCM Test</title> </head> <body> <h2>GCM Test</h2> <form method="POST" /> Device Token:<input name="deviceToken" /> <br /> API Key:<input name="apiKey" /> <br /> Message:<input name="message" /> <br /> Collapse Key:<input name="collapseKey" /> <br /> <input type="submit" value="Send Message"> </form> </body> </html>