Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class firebase {
- function sendPushNotification($fields){
- define('FIREBASE_API_KEY', 'AAAAcMU5rd0:APA91bEe-aoAVIhGfXhLkYfQDkd-a9Fmt0wbRgP6ge8yH0zIl759pkL_HbPMokN3XLclYfnLvjVRF1WBiTLMbVINNoh0MCOyY_Nm2L5Ko0TjLT_KWX7vl_3J8inytgkHXhtJOUKBf4Uh');
- $url = 'https://fcm.googleapis.com/fcm/send';
- //building headers for the request
- $headers = array(
- 'Authorization: key=' . FIREBASE_API_KEY,
- 'Content-Type: application/json'
- );
- //Initializing curl to open a connection
- $ch = curl_init();
- //Setting the curl url
- curl_setopt($ch, CURLOPT_URL, $url);
- //setting the method as post
- curl_setopt($ch, CURLOPT_POST, true);
- //adding headers
- curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- //disabling ssl support
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- //adding the fields in json format
- curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
- //finally executing the curl request
- $result = curl_exec($ch);
- if ($result === FALSE) {
- die('Curl failed: ' . curl_error($ch));
- }
- //Now close the connection
- curl_close($ch);
- //and return the result
- return $result;
- }
- }
- $res_id = mysql_insert_id();
- $reservasi = mysql_query("SELECT * FROM reservation WHERE reservation_id=$res_id");
- $rox = mysql_fetch_assoc($reservasi);
- $id_user = $rox['user_id'];
- $id_course = $rox['course_id'];
- $dates = $rox['date'];
- $times = $rox['time'];
- $players = $rox['player'];
- $a = "SELECT * FROM user WHERE user_id='$id_user'";
- $query = mysql_query($a);
- $row = mysql_fetch_assoc($query);
- $b = "SELECT * FROM golf_course WHERE golf_course_id=$id_course";
- $querys = mysql_query($b);
- $rows = mysql_fetch_assoc($querys);
- if($row['token'] != ""){
- $res = array();
- $res['data']['title'] = $row['email'];
- $res['data']['message'] = "Anda telah melakukan reservasi di".$rows['golf_course_name']."<br>Tanggal :".$dates."<br>Waktu :".$times."<br> Jumlah Pemain :".$players;
- $result = array($row['token']);
- $fields = array(
- 'registration_ids' => $result,
- 'data' => $res,
- );
- $push = new firebase();
- $push->sendPushNotification($fields);
- }
Advertisement
Add Comment
Please, Sign In to add comment