You are here

private function PushNotificationsBroadcasterGcm::sendTokenBundle in Push Notifications 8

Send a token bundle.

@returns array Returns return of curl info and response from GCM.

Parameters

array $tokens: Array of tokens.

1 call to PushNotificationsBroadcasterGcm::sendTokenBundle()
PushNotificationsBroadcasterGcm::sendBroadcast in src/PushNotificationsBroadcasterGcm.php
Send the broadcast message.

File

src/PushNotificationsBroadcasterGcm.php, line 145
Contains \Drupal\push_notifications\PushNotificationsBroadcasterGcm.

Class

PushNotificationsBroadcasterGcm
Broadcasts Android messages.

Namespace

Drupal\push_notifications

Code

private function sendTokenBundle($tokens) {

  // Convert the payload into the correct format for payloads.
  // Prefill an array with values from other modules first.
  $data = array();
  foreach ($this->payload as $key => $value) {
    if ($key != 'alert') {
      $data['data'][$key] = $value;
    }
  }

  // Fill the default values required for each payload.
  $data['registration_ids'] = $tokens;
  $data['collapse_key'] = (string) time();
  $data['data']['message'] = $this->message;
  $curl = curl_init();
  curl_setopt($curl, CURLOPT_URL, self::PUSH_NOTIFICATIONS_GCM_SERVER_POST_URL);
  curl_setopt($curl, CURLOPT_HTTPHEADER, $this
    ->getHeaders());
  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
  curl_setopt($curl, CURLOPT_POST, TRUE);
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
  curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
  $response_raw = curl_exec($curl);
  $info = curl_getinfo($curl);
  curl_close($curl);
  $response = FALSE;
  if (isset($response_raw)) {
    $response = json_decode($response_raw);
  }
  return array(
    'info' => $info,
    'response' => $response,
    'response_raw' => $response_raw,
  );
}