diff --git a/src/PHP_GCM/Message.php b/src/PHP_GCM/Message.php index c11c4d9..8d88e43 100755 --- a/src/PHP_GCM/Message.php +++ b/src/PHP_GCM/Message.php @@ -27,6 +27,7 @@ class Message { const NOTIFICATION_TITLE_LOC_ARGS = 'title_loc_args'; const CONTENT_AVAILABLE = 'content_available'; const PRIORITY = 'priority'; + const RAW_DATA = 'raw_data'; private $collapseKey; private $delayWhileIdle; @@ -37,6 +38,9 @@ class Message { private $notification; private $contentAvailable; private $priority; + private $rawData; + private $publicKey; + private $salt; /** * Message Constructor @@ -196,6 +200,51 @@ public function getPriority() { return $this->priority; } + /** + * Sets the rawData property + * + * @param $rawData + * @return $this + */ + public function rawData($rawData) { + $this->rawData = $rawData; + return $this; + } + + public function getRawData() { + return $this->rawData; + } + + /** + * Sets the publicKey property + * + * @param $publicKey + * @return $this + */ + public function publicKey($publicKey) { + $this->publicKey = $publicKey; + return $this; + } + + public function getPublicKey() { + return $this->publicKey; + } + + /** + * Sets the salt property + * + * @param $salt + * @return $this + */ + public function salt($salt) { + $this->salt = $salt; + return $this; + } + + public function getSalt() { + return $this->salt; + } + public function build($recipients) { $message = array(); @@ -251,6 +300,10 @@ public function build($recipients) { $message[self::NOTIFICATION][self::NOTIFICATION_TITLE_LOC_KEY] = $this->notification->getTitleLocKey(); } + if (!empty($this->rawData)) { + $message[self::RAW_DATA] = $this->rawData; + } + return json_encode($message); } } diff --git a/src/PHP_GCM/Sender.php b/src/PHP_GCM/Sender.php index 3450fe9..a5bd6b9 100755 --- a/src/PHP_GCM/Sender.php +++ b/src/PHP_GCM/Sender.php @@ -259,7 +259,15 @@ private function performDeviceGroupOperation($senderId, $notificationKeyName, $n private function makeRequest(Message $message, array $registrationIds) { $ch = $this->getCurlRequest(); curl_setopt($ch, CURLOPT_URL, self::SEND_ENDPOINT); - curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Authorization: key=' . $this->key)); + $headers = array('Content-Type: application/json', 'Authorization: key=' . $this->key); + if(!is_null($message->getSalt()) && !is_null($message->getPublicKey())) { + $headers = array_merge($headers, array( + 'Encryption: salt=' . $message->getSalt(), + 'Crypto-Key: dh=' . $message->getPublicKey(), + 'Content-Encoding: aesgcm' + )); + } + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_POSTFIELDS, $message->build($registrationIds)); $response = curl_exec($ch); $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);