Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function send_notification ($tokens, $message ,$name , $status)
- {
- $url = 'https://fcm.googleapis.com/fcm/send';
- $fields = array(
- 'registration_ids' => $tokens,
- 'data' => $message,
- 'priority' => 'high',
- 'notification' => array(
- 'body' => $name . "'s leave is " .$status ,
- 'title' => "Leave Application",
- 'sound' => 'default',
- 'icon' => 'icon'
- )
- );
- $headers = array(
- 'Authorization:key = AIzaSyD0HT1tKcQ3K7kWUPWiRcalmJI2rmtQjqA',
- '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_AUTOREFERER, true);
- 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;
- }
- $database = $_POST['Database'];
- $servername = "158.69.204.52";
- $username = "admin_ecampus";
- $password = "*dolphin987";
- $dbname = $database;
- $dbname = "admin_ecampus_1";
- $teacherID = $_POST['student_id'];
- $teacherID = "3";
- $conn = mysqli_connect($servername, $username, $password ,$dbname );
- $sql = "SELECT students_master.student_name as name , users.fcm_token as fcm_token, leaves_master.leave_status as status , users.id FROM leaves_master , users , students_master WHERE students_master.student_id = leaves_master.student_id and users.id = leaves_master.created_by and leaves_master.leave_checked_by = $teacherID";
- $result = mysqli_query($conn,$sql);
- $tokens = array();
- if(mysqli_num_rows($result) > 0 ){
- while ($row = mysqli_fetch_assoc($result)) {
- $tokens[] = $row["fcm_token"];
- $name = $row["name"];
- $status = $row["status"];
- }
- }
- mysqli_close($conn);
- $message = array("message" => " your ward is absent");
- $message_status = send_notification($tokens, $message ,$name , $status);
- echo $message_status;
- ?>
Add Comment
Please, Sign In to add comment