Created
August 30, 2017 22:47
Revisions
-
iespino00 revised this gist
Aug 30, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -34,7 +34,7 @@ return $result; } $conn = mysqli_connect("localhost","root","Password","fcm"); $sql = "select token from users"; $result = mysqli_query($conn,$sql); $tokens = array(); -
iespino00 created this gist
Aug 30, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,58 @@ <?php function send_notification($tokens, $message) { $url='https://fcm.googleapis.com/fcm/send'; $fields = array( 'registration_ids' => $tokens, 'data' => $message ); $headers = array( 'Authorization:key = AOyUEjHurDZNKM-D7hcGG7wnSwSEY_ngA4P-w', 'Content-Type: application/json' ); $ch = curl_init(); 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_SSL_VERIFYHOST, 0); curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch,CURLOPT_POSTFIELDS, json_encode($fields)); $result = curl_exec($ch); if($result === FALSE) { die('Curl failed: ' . curl_error($ch)); } curl_close($ch); return $result; } $conn = mysqli_connect("localhost","root","Password1","fcm"); $sql = "select token from users"; $result = mysqli_query($conn,$sql); $tokens = array(); if(mysqli_num_rows($result) > 0) { while ($row = mysqli_fetch_assoc($result)) { $tokens[] = $row["Token"]; } } mysqli_close($conn); $message = array("message" => "FCM PUSH NOTIFICATION TEST"); $message_status = send_notification($tokens, $message); echo $message_status; ?>