Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class FirebaseApi {
- private $urlEndpoint = 'https://fcm.googleapis.com/fcm/send/';
- private $serverKey = 'some_sort_of_servey_key';
- private function headerInitialization () {
- $header = array(
- 'Authorization: key=' . $this->serverKey,
- 'Content-Type: application/json'
- );
- return $header;
- }
- public function init ( $message = false ) {
- $ch = curl_init();
- $message = array(
- // this is the token received when refreshtoken function was called
- // from client side(android)
- 'to' => 'alphanumeric_value:alphanumeric_value',
- 'priority' => "high",
- 'notification' => array( "tag"=>"chat", "body" => 'testing...' ),
- );
- echo json_encode( $message, TRUE );
- $options = array(
- CURLOPT_URL => $this->urlEndpoint,
- CURLOPT_HTTPHEADER => $this->headerInitialization(),
- CURLOPT_POST => 1,
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_SSL_VERIFYPEER => 0,
- CURLOPT_POSTFIELDS => json_encode( $message )
- );
- curl_setopt_array( $ch, $options );
- $response = curl_exec( $ch );
- curl_close( $ch );
- return $response;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement