Created
July 16, 2018 04:33
-
-
Save shikto1/ca672428af6a34bc1c14de25d3d4bca6 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 | |
require_once('connection.php'); | |
$title=$_POST['title']; | |
$mes=$_POST['details']; | |
$loc=$_POST['loc']; | |
$blood=$_POST['blood']; | |
//$uiId='gkveBvqzHoVXmAAXKU4rSbaAltu2'; | |
function send ($tokens, $msg) | |
{ | |
$url = 'https://fcm.googleapis.com/fcm/send'; | |
$server_key='AIzaSyATZezcfRTcR_BPCCiDuKTpcCZc71AVgAQ'; | |
$fields = array( | |
'registration_ids' => $tokens, | |
'data' => $msg | |
); | |
$headers = array( | |
'Authorization:key = '.$server_key, | |
'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); | |
curl_close($ch); | |
return $result; | |
} | |
if($loc=='Any Location' && $blood=='All'){ | |
$sql="SELECT token FROM donor"; | |
} | |
elseif($loc=='Any Location'){ | |
$sql="SELECT token FROM donor WHERE blood like '".$blood."';"; | |
} | |
elseif($blood=='All'){ | |
$sql="SELECT token FROM donor WHERE location like '".$loc."';"; | |
} | |
else{ | |
$sql="SELECT token FROM donor WHERE blood like '".$blood."' AND location like '".$loc."';"; | |
} | |
$result = mysqli_query($con,$sql); | |
$tokens = array(); | |
if(mysqli_num_rows($result) > 0 ){ | |
while ($row = mysqli_fetch_assoc($result)) { | |
$tokens[] = $row["token"]; | |
} | |
} | |
mysqli_close($con); | |
$msg = array("message" =>$mes, | |
"title"=> $title, | |
"type"=>"notification"); | |
$message_status = send($tokens, $msg); | |
echo $message_status; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment