tegarkurniawan

firebase

Jan 31st, 2017
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. <?php
  2. class firebase {
  3. function sendPushNotification($fields){
  4. define('FIREBASE_API_KEY', 'AAAAcMU5rd0:APA91bEe-aoAVIhGfXhLkYfQDkd-a9Fmt0wbRgP6ge8yH0zIl759pkL_HbPMokN3XLclYfnLvjVRF1WBiTLMbVINNoh0MCOyY_Nm2L5Ko0TjLT_KWX7vl_3J8inytgkHXhtJOUKBf4Uh');
  5. $url = 'https://fcm.googleapis.com/fcm/send';
  6.  
  7. //building headers for the request
  8. $headers = array(
  9. 'Authorization: key=' . FIREBASE_API_KEY,
  10. 'Content-Type: application/json'
  11. );
  12.  
  13. //Initializing curl to open a connection
  14. $ch = curl_init();
  15.  
  16. //Setting the curl url
  17. curl_setopt($ch, CURLOPT_URL, $url);
  18.  
  19. //setting the method as post
  20. curl_setopt($ch, CURLOPT_POST, true);
  21.  
  22. //adding headers
  23. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  24. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  25.  
  26. //disabling ssl support
  27. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  28.  
  29. //adding the fields in json format
  30. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
  31.  
  32. //finally executing the curl request
  33. $result = curl_exec($ch);
  34. if ($result === FALSE) {
  35. die('Curl failed: ' . curl_error($ch));
  36. }
  37.  
  38. //Now close the connection
  39. curl_close($ch);
  40.  
  41. //and return the result
  42. return $result;
  43. }
  44. }
  45.  
  46. $res_id = mysql_insert_id();
  47. $reservasi = mysql_query("SELECT * FROM reservation WHERE reservation_id=$res_id");
  48. $rox = mysql_fetch_assoc($reservasi);
  49.  
  50. $id_user = $rox['user_id'];
  51. $id_course = $rox['course_id'];
  52. $dates = $rox['date'];
  53. $times = $rox['time'];
  54. $players = $rox['player'];
  55.  
  56. $a = "SELECT * FROM user WHERE user_id='$id_user'";
  57. $query = mysql_query($a);
  58. $row = mysql_fetch_assoc($query);
  59.  
  60. $b = "SELECT * FROM golf_course WHERE golf_course_id=$id_course";
  61. $querys = mysql_query($b);
  62. $rows = mysql_fetch_assoc($querys);
  63.  
  64. if($row['token'] != ""){
  65.  
  66. $res = array();
  67. $res['data']['title'] = $row['email'];
  68. $res['data']['message'] = "Anda telah melakukan reservasi di".$rows['golf_course_name']."<br>Tanggal :".$dates."<br>Waktu :".$times."<br> Jumlah Pemain :".$players;
  69. $result = array($row['token']);
  70.  
  71.  
  72. $fields = array(
  73. 'registration_ids' => $result,
  74. 'data' => $res,
  75. );
  76.  
  77. $push = new firebase();
  78. $push->sendPushNotification($fields);
  79. }
Advertisement
Add Comment
Please, Sign In to add comment