You are here

function _firebase_sendPushNotification in Firebase Push Notification (FCM) 7

Execute the push notification.

Parameters

string $appToken: Device token.

array $param: Parameters for payload.

Return value

object Firebase's response.

1 call to _firebase_sendPushNotification()
firebase_send in ./firebase.module
Sends the push notification.

File

./firebase.module, line 125

Code

function _firebase_sendPushNotification($appToken, array $param) {
  $headers = _firebase_buildHeaders();

  // We receive our prepared payload from buildMessage.
  // Contains the token and notification array.
  $message = _firebase_buildMessage($appToken, $param);
  $ch = curl_init(variable_get('firebase_endpoint', 'https://fcm.googleapis.com/fcm/send'));

  // Setup curl with our headers and message.
  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $message);
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

  // Send the request to Firebase.
  $response['body'] = curl_exec($ch);
  $response['body'] = json_decode($response['body']);
  curl_close($ch);
  return $response;
}