Guest User

Untitled

a guest
Apr 19th, 2017
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. <?php
  2. function send_notification ($tokens, $message ,$name , $status)
  3. {
  4. $url = 'https://fcm.googleapis.com/fcm/send';
  5. $fields = array(
  6. 'registration_ids' => $tokens,
  7. 'data' => $message,
  8. 'priority' => 'high',
  9. 'notification' => array(
  10. 'body' => $name . "'s leave is " .$status ,
  11. 'title' => "Leave Application",
  12. 'sound' => 'default',
  13. 'icon' => 'icon'
  14. )
  15.  
  16. );
  17. $headers = array(
  18. 'Authorization:key = AIzaSyD0HT1tKcQ3K7kWUPWiRcalmJI2rmtQjqA',
  19. 'Content-Type: application/json'
  20. );
  21. $ch = curl_init();
  22. curl_setopt($ch, CURLOPT_URL, $url);
  23. curl_setopt($ch, CURLOPT_POST, true);
  24. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  25. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  26. curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
  27. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  28. curl_setopt($ch, CURLOPT_AUTOREFERER, true);
  29.  
  30.  
  31. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
  32. $result = curl_exec($ch);
  33. if ($result === FALSE) {
  34. die('Curl failed: ' . curl_error($ch));
  35. }
  36. curl_close($ch);
  37. return $result;
  38. }
  39.  
  40. $database = $_POST['Database'];
  41.  
  42. $servername = "158.69.204.52";
  43. $username = "admin_ecampus";
  44. $password = "*dolphin987";
  45. $dbname = $database;
  46. $dbname = "admin_ecampus_1";
  47.  
  48.  
  49. $teacherID = $_POST['student_id'];
  50. $teacherID = "3";
  51.  
  52. $conn = mysqli_connect($servername, $username, $password ,$dbname );
  53. $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";
  54. $result = mysqli_query($conn,$sql);
  55. $tokens = array();
  56. if(mysqli_num_rows($result) > 0 ){
  57. while ($row = mysqli_fetch_assoc($result)) {
  58. $tokens[] = $row["fcm_token"];
  59. $name = $row["name"];
  60. $status = $row["status"];
  61. }
  62.  
  63. }
  64.  
  65. mysqli_close($conn);
  66. $message = array("message" => " your ward is absent");
  67. $message_status = send_notification($tokens, $message ,$name , $status);
  68. echo $message_status;
  69. ?>
Add Comment
Please, Sign In to add comment