Advertisement
Guest User

Untitled

a guest
Jul 30th, 2016
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.19 KB | None | 0 0
  1. <?php
  2.  
  3. class FirebaseApi {
  4.  
  5.     private $urlEndpoint = 'https://fcm.googleapis.com/fcm/send/';
  6.     private $serverKey = 'some_sort_of_servey_key';
  7.  
  8.     private function headerInitialization () {
  9.  
  10.         $header = array(
  11.                 'Authorization: key=' . $this->serverKey,
  12.                 'Content-Type: application/json'
  13.             );
  14.  
  15.         return $header;
  16.        
  17.  
  18.     }
  19.  
  20.     public function init ( $message = false ) {
  21.  
  22.         $ch = curl_init();
  23.  
  24.         $message = array(
  25.                 // this is the token received when refreshtoken function was called
  26.                 // from client side(android)
  27.                 'to'           => 'alphanumeric_value:alphanumeric_value',
  28.                 'priority'     => "high",
  29.                 'notification' => array( "tag"=>"chat", "body" => 'testing...' ),
  30.             );
  31.  
  32.         echo json_encode( $message, TRUE );
  33.  
  34.         $options = array(
  35.                 CURLOPT_URL            => $this->urlEndpoint,
  36.                 CURLOPT_HTTPHEADER     => $this->headerInitialization(),
  37.                 CURLOPT_POST           => 1,
  38.                 CURLOPT_RETURNTRANSFER => true,
  39.                 CURLOPT_SSL_VERIFYPEER => 0,
  40.                 CURLOPT_POSTFIELDS     => json_encode( $message )
  41.             );
  42.  
  43.         curl_setopt_array( $ch, $options );
  44.         $response = curl_exec( $ch );
  45.         curl_close( $ch );
  46.  
  47.         return $response;
  48.     }
  49.  
  50.    
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement