ok
Direktori : /home2/selectio/www/y1jobportal.in/admin/api/config/ |
Current File : /home2/selectio/www/y1jobportal.in/admin/api/config/firebase.php |
<?php //include_once('crud.php'); class Firebase { protected $db; function __construct(){ /*$this->db = new Database(); $this->db->connect();*/ date_default_timezone_set('Asia/Kolkata'); } public function send($registration_ids, $message) { $fields = array( 'registration_ids' => $registration_ids, 'data' => $message, ); return $this->sendPushNotification($fields); } /* * This function will make the actuall curl request to firebase server * and then the message is sent */ private function sendPushNotification($fields) { $url = 'https://fcm.googleapis.com/fcm/send'; //building headers for the request define("FIREBASE_API_KEY",'AAAAbzFbWbk:APA91bGo_e6E5cQV-WVSVOuE0cIr0BBN3pD-Ru1720C96btr2woObRb5QdKBzM3QNtcHW7lwJI9BGIFw2DvMvWNyyi1E-OyUcXX5hXv_zl4vvKzMYErqzu6DLm5dvpiX0feV9SQ2dmLq'); //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; } }