From 3f5a6d2f09f3b50d5cea5200cd7ef37541b30972 Mon Sep 17 00:00:00 2001 From: Vaishali Jagtap <71736051+vaishali-vumc@users.noreply.github.com> Date: Fri, 10 May 2024 16:28:13 -0400 Subject: [PATCH 01/37] Update composer.json file --- composer.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 8baa766..28bb403 100644 --- a/composer.json +++ b/composer.json @@ -1,13 +1,13 @@ { - "name": "sngrl/php-firebase-cloud-messaging", + "name": "vanderbilt-redcap/php-firebase-cloud-messaging", "description": "PHP API for Firebase Cloud Messaging from Google", "license": "MIT", "keywords": ["PHP","FCM","Google","Firebase","Cloud","Notifications","Android","iOS","Chrome"], - "homepage": "https://github.com/sngrl/php-firebase-cloud-messaging", + "homepage": "https://github.com/vanderbilt-redcap/php-firebase-cloud-messaging", "authors": [ { - "name": "Sngrl", - "email": "i@sngrl.ru" + "name": "Vaishali Jagtap", + "email": "vaishali.jagtap@vumc.org" } ], "require": { @@ -20,12 +20,12 @@ }, "autoload": { "psr-4": { - "sngrl\\PhpFirebaseCloudMessaging\\": "src/" + "Vanderbilt\\PhpFirebaseCloudMessaging\\": "src/" } }, "autoload-dev": { "psr-4": { - "sngrl\\PhpFirebaseCloudMessaging\\Tests\\": "tests/" + "Vanderbilt\\PhpFirebaseCloudMessaging\\Tests\\": "tests/" } } } \ No newline at end of file From fd3e7130181aaf4506525f8a66a362ab644cdd7e Mon Sep 17 00:00:00 2001 From: Vaishali Jagtap <71736051+vaishali-vumc@users.noreply.github.com> Date: Fri, 10 May 2024 17:42:31 -0400 Subject: [PATCH 02/37] Updated namespace from sngrl to Vanderbilt --- src/Client.php | 8 ++++---- src/ClientInterface.php | 8 ++++---- src/Message.php | 12 ++++++------ src/Notification.php | 2 +- src/Recipient/Device.php | 2 +- src/Recipient/Recipient.php | 2 +- src/Recipient/Topic.php | 2 +- tests/ClientTest.php | 8 ++++---- tests/MessageTest.php | 12 ++++++------ tests/NotificationTest.php | 4 ++-- tests/PhpFirebaseCloudMessagingTestCase.php | 2 +- 11 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/Client.php b/src/Client.php index 5125536..9573c87 100644 --- a/src/Client.php +++ b/src/Client.php @@ -1,10 +1,10 @@ Date: Fri, 10 May 2024 20:36:12 -0400 Subject: [PATCH 03/37] Debug input param --- src/Client.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Client.php b/src/Client.php index 9573c87..05bdbc1 100644 --- a/src/Client.php +++ b/src/Client.php @@ -59,6 +59,8 @@ public function setProxyApiUrl($url) */ public function send(Message $message) { + echo $this->apiKey; + var_dump($message); die; return $this->guzzleClient->post( $this->getApiUrl(), [ From 79a77eff4f2f624f1f4f7cf2e8cbffae76c946c3 Mon Sep 17 00:00:00 2001 From: Vaishali Jagtap <71736051+vaishali-vumc@users.noreply.github.com> Date: Fri, 10 May 2024 20:43:01 -0400 Subject: [PATCH 04/37] Debug output --- src/Client.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Client.php b/src/Client.php index 05bdbc1..b59fd61 100644 --- a/src/Client.php +++ b/src/Client.php @@ -59,9 +59,7 @@ public function setProxyApiUrl($url) */ public function send(Message $message) { - echo $this->apiKey; - var_dump($message); die; - return $this->guzzleClient->post( + $output = $this->guzzleClient->post( $this->getApiUrl(), [ 'headers' => [ @@ -71,6 +69,7 @@ public function send(Message $message) 'body' => json_encode($message) ] ); + var_dump($output); die; } /** From afaf7ccfb217d7e572383b2bb5e26ba6884dba5e Mon Sep 17 00:00:00 2001 From: Vaishali Jagtap <71736051+vaishali-vumc@users.noreply.github.com> Date: Fri, 10 May 2024 20:45:15 -0400 Subject: [PATCH 05/37] Remove Debug output --- src/Client.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Client.php b/src/Client.php index b59fd61..9573c87 100644 --- a/src/Client.php +++ b/src/Client.php @@ -59,7 +59,7 @@ public function setProxyApiUrl($url) */ public function send(Message $message) { - $output = $this->guzzleClient->post( + return $this->guzzleClient->post( $this->getApiUrl(), [ 'headers' => [ @@ -69,7 +69,6 @@ public function send(Message $message) 'body' => json_encode($message) ] ); - var_dump($output); die; } /** From 6d6e1793013699d43a09fd80548f5c2876546d69 Mon Sep 17 00:00:00 2001 From: Vaishali Jagtap <71736051+vaishali-vumc@users.noreply.github.com> Date: Fri, 10 May 2024 21:06:55 -0400 Subject: [PATCH 06/37] Debug input --- src/Client.php | 3 +++ src/Message.php | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Client.php b/src/Client.php index 9573c87..fc41b3c 100644 --- a/src/Client.php +++ b/src/Client.php @@ -59,6 +59,9 @@ public function setProxyApiUrl($url) */ public function send(Message $message) { + var_dump($message); + var_dump(json_encode($message)); + die; return $this->guzzleClient->post( $this->getApiUrl(), [ diff --git a/src/Message.php b/src/Message.php index fecdb98..5a63d6c 100644 --- a/src/Message.php +++ b/src/Message.php @@ -15,7 +15,7 @@ class Message implements \JsonSerializable */ const MAX_TOPICS = 3; const MAX_DEVICES = 1000; - + private $message; private $notification; private $collapseKey; private $priority; @@ -53,7 +53,8 @@ public function addRecipient(Recipient $recipient) public function setNotification(Notification $notification) { - $this->notification = $notification; + //$this->notification = $notification; + $this->message = $notification; return $this; } From 1ad004c3fe4ff06b6ab3c3b4f8e1aa7061aacb97 Mon Sep 17 00:00:00 2001 From: Vaishali Jagtap <71736051+vaishali-vumc@users.noreply.github.com> Date: Fri, 10 May 2024 21:17:21 -0400 Subject: [PATCH 07/37] Set message --- src/Message.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Message.php b/src/Message.php index 5a63d6c..5694277 100644 --- a/src/Message.php +++ b/src/Message.php @@ -53,11 +53,15 @@ public function addRecipient(Recipient $recipient) public function setNotification(Notification $notification) { - //$this->notification = $notification; - $this->message = $notification; + $this->notification = $notification; return $this; } + public function setMessage(Message $message) + { + $this->message = $message; + return $this; + } public function setCollapseKey($collapseKey) { $this->collapseKey = $collapseKey; From 811075225d575aa0cff98aab148c1a1d805ea25c Mon Sep 17 00:00:00 2001 From: Vaishali Jagtap <71736051+vaishali-vumc@users.noreply.github.com> Date: Fri, 10 May 2024 21:20:26 -0400 Subject: [PATCH 08/37] Set message --- src/Message.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Message.php b/src/Message.php index 5694277..1677532 100644 --- a/src/Message.php +++ b/src/Message.php @@ -53,15 +53,15 @@ public function addRecipient(Recipient $recipient) public function setNotification(Notification $notification) { - $this->notification = $notification; + $this->message->notification = $notification; return $this; } - public function setMessage(Message $message) + /*public function setMessage(Message $message) { $this->message = $message; return $this; - } + }*/ public function setCollapseKey($collapseKey) { $this->collapseKey = $collapseKey; From 9cd41c8d592ca0874a390ed9e68ddb96e1c615e1 Mon Sep 17 00:00:00 2001 From: Vaishali Jagtap <71736051+vaishali-vumc@users.noreply.github.com> Date: Fri, 10 May 2024 21:23:35 -0400 Subject: [PATCH 09/37] remove Set message --- src/Message.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/Message.php b/src/Message.php index 1677532..b35dc2e 100644 --- a/src/Message.php +++ b/src/Message.php @@ -15,7 +15,7 @@ class Message implements \JsonSerializable */ const MAX_TOPICS = 3; const MAX_DEVICES = 1000; - private $message; + private $notification; private $collapseKey; private $priority; @@ -53,15 +53,10 @@ public function addRecipient(Recipient $recipient) public function setNotification(Notification $notification) { - $this->message->notification = $notification; + $this->notification = $notification; return $this; } - /*public function setMessage(Message $message) - { - $this->message = $message; - return $this; - }*/ public function setCollapseKey($collapseKey) { $this->collapseKey = $collapseKey; From bf262a1594f1b90ae41c11868e6ac2462ffb4e0d Mon Sep 17 00:00:00 2001 From: Vaishali Jagtap <71736051+vaishali-vumc@users.noreply.github.com> Date: Mon, 13 May 2024 14:03:29 -0400 Subject: [PATCH 10/37] Debug request array --- src/Client.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Client.php b/src/Client.php index fc41b3c..6ecd852 100644 --- a/src/Client.php +++ b/src/Client.php @@ -59,8 +59,15 @@ public function setProxyApiUrl($url) */ public function send(Message $message) { - var_dump($message); - var_dump(json_encode($message)); + echo $this->getApiUrl(); + $requestArr = [ + 'headers' => [ + 'Authorization' => sprintf('key=%s', $this->apiKey), + 'Content-Type' => 'application/json' + ], + 'body' => json_encode($message) + ]; + print_array($requestArr); die; return $this->guzzleClient->post( $this->getApiUrl(), From a56d8cd8bbabf439dedb96c4705d3906a29e4ecc Mon Sep 17 00:00:00 2001 From: Vaishali Jagtap <71736051+vaishali-vumc@users.noreply.github.com> Date: Mon, 13 May 2024 15:11:39 -0400 Subject: [PATCH 11/37] Debug request array --- src/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 6ecd852..ce84477 100644 --- a/src/Client.php +++ b/src/Client.php @@ -67,7 +67,7 @@ public function send(Message $message) ], 'body' => json_encode($message) ]; - print_array($requestArr); + print_r($requestArr); die; return $this->guzzleClient->post( $this->getApiUrl(), From 9f77047d3ef785741cceb28f8af0d550cd4c6802 Mon Sep 17 00:00:00 2001 From: Vaishali Jagtap <71736051+vaishali-vumc@users.noreply.github.com> Date: Mon, 13 May 2024 15:13:15 -0400 Subject: [PATCH 12/37] Remove Debug request array --- src/Client.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/Client.php b/src/Client.php index ce84477..9573c87 100644 --- a/src/Client.php +++ b/src/Client.php @@ -59,16 +59,6 @@ public function setProxyApiUrl($url) */ public function send(Message $message) { - echo $this->getApiUrl(); - $requestArr = [ - 'headers' => [ - 'Authorization' => sprintf('key=%s', $this->apiKey), - 'Content-Type' => 'application/json' - ], - 'body' => json_encode($message) - ]; - print_r($requestArr); - die; return $this->guzzleClient->post( $this->getApiUrl(), [ From 829e7e1f25cb7d572cf6457a0e8b1c5145ed3837 Mon Sep 17 00:00:00 2001 From: Vaishali Jagtap <71736051+vaishali-vumc@users.noreply.github.com> Date: Mon, 13 May 2024 15:16:04 -0400 Subject: [PATCH 13/37] Debug request array --- src/Client.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Client.php b/src/Client.php index 9573c87..ce84477 100644 --- a/src/Client.php +++ b/src/Client.php @@ -59,6 +59,16 @@ public function setProxyApiUrl($url) */ public function send(Message $message) { + echo $this->getApiUrl(); + $requestArr = [ + 'headers' => [ + 'Authorization' => sprintf('key=%s', $this->apiKey), + 'Content-Type' => 'application/json' + ], + 'body' => json_encode($message) + ]; + print_r($requestArr); + die; return $this->guzzleClient->post( $this->getApiUrl(), [ From 010659386d32001ca5b50d9941dfb99629f0c553 Mon Sep 17 00:00:00 2001 From: Vaishali Jagtap <71736051+vaishali-vumc@users.noreply.github.com> Date: Mon, 13 May 2024 15:16:56 -0400 Subject: [PATCH 14/37] Removed Debug request array --- src/Client.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/Client.php b/src/Client.php index ce84477..9573c87 100644 --- a/src/Client.php +++ b/src/Client.php @@ -59,16 +59,6 @@ public function setProxyApiUrl($url) */ public function send(Message $message) { - echo $this->getApiUrl(); - $requestArr = [ - 'headers' => [ - 'Authorization' => sprintf('key=%s', $this->apiKey), - 'Content-Type' => 'application/json' - ], - 'body' => json_encode($message) - ]; - print_r($requestArr); - die; return $this->guzzleClient->post( $this->getApiUrl(), [ From d9b8d15e2ee34717d4e952590473f8c3823e90b4 Mon Sep 17 00:00:00 2001 From: Vaishali Jagtap <71736051+vaishali-vumc@users.noreply.github.com> Date: Mon, 20 May 2024 11:48:13 -0400 Subject: [PATCH 15/37] Migrate from legacy FCM APIs to HTTP v1 --- src/Client.php | 56 ++++++++++++++++++++++++++++++++++++++++++++++--- src/Message.php | 8 +++++-- 2 files changed, 59 insertions(+), 5 deletions(-) diff --git a/src/Client.php b/src/Client.php index 9573c87..40fae0c 100644 --- a/src/Client.php +++ b/src/Client.php @@ -9,10 +9,14 @@ class Client implements ClientInterface { const DEFAULT_API_URL = 'https://fcm.googleapis.com/fcm/send'; + const HTTPV1_API_URL_PREFIX = 'https://fcm.googleapis.com/v1/projects/'; + const HTTPV1_API_URL_POSTEFIX = '/messages:send'; const DEFAULT_TOPIC_ADD_SUBSCRIPTION_API_URL = 'https://iid.googleapis.com/iid/v1:batchAdd'; const DEFAULT_TOPIC_REMOVE_SUBSCRIPTION_API_URL = 'https://iid.googleapis.com/iid/v1:batchRemove'; private $apiKey; + private $accessToken; + private $projectId; private $proxyApiUrl; private $guzzleClient; @@ -59,14 +63,16 @@ public function setProxyApiUrl($url) */ public function send(Message $message) { + $param = ['message' => $message]; + return $this->guzzleClient->post( - $this->getApiUrl(), + $this->getHTTPV1ApiUrl(), [ 'headers' => [ - 'Authorization' => sprintf('key=%s', $this->apiKey), + 'Authorization' => sprintf('Bearer %s', $this->accessToken), 'Content-Type' => 'application/json' ], - 'body' => json_encode($message) + 'body' => json_encode($param) ] ); } @@ -127,4 +133,48 @@ private function getApiUrl() { return isset($this->proxyApiUrl) ? $this->proxyApiUrl : self::DEFAULT_API_URL; } + + /** + * Set your server access token here + * + * @param string $accessToken + * + * @return void + */ + public function setAccessToken($accessToken) + { + $this->accessToken = $accessToken; + } + + /** + * Set your project ID + * + * @param string $projectId + * + * @return void + */ + public function setProjectId($projectId) + { + $this->projectId = $projectId; + } + + /** + * Build endpoint URL for Firebase HTTP V1 API + * + * @return string + */ + private function getHTTPV1ApiUrl() + { + return self::HTTPV1_API_URL_PREFIX.$this->getProjectId().self::HTTPV1_API_URL_POSTEFIX; + } + + /** + * Get your project ID + * + * @return string + */ + public function getProjectId() + { + return $this->projectId; + } } \ No newline at end of file diff --git a/src/Message.php b/src/Message.php index b35dc2e..5a325e4 100644 --- a/src/Message.php +++ b/src/Message.php @@ -166,7 +166,11 @@ public function jsonSerialize() } if (count($this->recipients) == 1) { - $jsonData['to'] = $this->createTarget(); + if ($this->recipientType == Device::class) { + $jsonData['token'] = $this->createTarget(); + } else { + $jsonData['topic'] = $this->createTarget(); + } } elseif ($this->recipientType == Device::class) { $jsonData['registration_ids'] = $this->createTarget(); } else { @@ -198,7 +202,7 @@ private function createTarget() case Topic::class: if ($recipientCount == 1) { - return sprintf('/topics/%s', current($this->recipients)->getName()); + return sprintf('%s', current($this->recipients)->getName()); } else if ($recipientCount > self::MAX_TOPICS) { throw new \OutOfRangeException(sprintf('Message topic limit exceeded. Firebase supports a maximum of %u topics.', self::MAX_TOPICS)); From 4484caaa697eb88111bb804af43105f0b743646e Mon Sep 17 00:00:00 2001 From: Vaishali Jagtap <71736051+vaishali-vumc@users.noreply.github.com> Date: Tue, 21 May 2024 14:22:36 -0400 Subject: [PATCH 16/37] Alternative to "registered_ids is not supported in http v1" to send notification to multiple devices. --- src/Client.php | 91 ++++++++++++++++++++++++++++++------------------- src/Message.php | 5 +++ 2 files changed, 61 insertions(+), 35 deletions(-) diff --git a/src/Client.php b/src/Client.php index 40fae0c..d866085 100644 --- a/src/Client.php +++ b/src/Client.php @@ -52,6 +52,18 @@ public function setProxyApiUrl($url) return $this; } + /** + * add your server access token here + * + * @param string $accessToken + * + * @return \Vanderbilt\PhpFirebaseCloudMessaging\Client + */ + public function setAccessToken($accessToken) + { + $this->accessToken = $accessToken; + return $this; + } /** * sends your notification to the google servers and returns a guzzle repsonse object * containing their answer. @@ -65,16 +77,48 @@ public function send(Message $message) { $param = ['message' => $message]; - return $this->guzzleClient->post( - $this->getHTTPV1ApiUrl(), - [ - 'headers' => [ - 'Authorization' => sprintf('Bearer %s', $this->accessToken), - 'Content-Type' => 'application/json' - ], - 'body' => json_encode($param) - ] - ); + // FCM HTTP V1 does not support sending notifications to multiple devices (supported only in legacy API via registration_tokens + // So, Adding topic subscription, sending notification to topic, then remove topic subscription + $recipients = $message->getRecipients(); + if (count($recipients) > 1) { + $tokens = []; + foreach ($recipients as $recipient) { + $tokens[] = $recipient->getToken(); + } + $topic = "Topic_".date("YmdHis")."_".substr(md5(rand()), 0, 4); + $response = $this->addTopicSubscription($topic, $tokens); + if ($response->getStatusCode() == 200) { + $messageArr = json_decode(json_encode($param), true); + unset($messageArr['message']['registration_ids']); + $messageArr['message']['topic'] = $topic; + print_r($messageArr); + $output = $this->guzzleClient->post( + $this->getHTTPV1ApiUrl(), + [ + 'headers' => [ + 'Authorization' => sprintf('Bearer %s', $this->accessToken), + 'Content-Type' => 'application/json' + ], + 'body' => json_encode($messageArr) + ] + ); + } + $response = $this->removeTopicSubscription($topic, $tokens); + return $output; + } else { + return $this->guzzleClient->post( + $this->getHTTPV1ApiUrl(), + [ + 'headers' => [ + 'Authorization' => sprintf('Bearer %s', $this->accessToken), + 'Content-Type' => 'application/json' + ], + 'body' => json_encode($param) + ] + ); + } + return $output; + } /** @@ -135,44 +179,21 @@ private function getApiUrl() } /** - * Set your server access token here - * - * @param string $accessToken - * - * @return void - */ - public function setAccessToken($accessToken) - { - $this->accessToken = $accessToken; - } - - /** - * Set your project ID + * add your project ID * * @param string $projectId * - * @return void + * @return \Vanderbilt\PhpFirebaseCloudMessaging\Client */ public function setProjectId($projectId) { $this->projectId = $projectId; } - - /** - * Build endpoint URL for Firebase HTTP V1 API - * - * @return string - */ private function getHTTPV1ApiUrl() { return self::HTTPV1_API_URL_PREFIX.$this->getProjectId().self::HTTPV1_API_URL_POSTEFIX; } - /** - * Get your project ID - * - * @return string - */ public function getProjectId() { return $this->projectId; diff --git a/src/Message.php b/src/Message.php index 5a325e4..16f69d2 100644 --- a/src/Message.php +++ b/src/Message.php @@ -244,4 +244,9 @@ private function createTarget() } return null; } + + /* Get All recipients */ + public function getRecipients() { + return $this->recipients; + } } \ No newline at end of file From 1d2b2017af00182c8c73f1fe04108d8ff624a1ff Mon Sep 17 00:00:00 2001 From: Vaishali Jagtap <71736051+vaishali-vumc@users.noreply.github.com> Date: Tue, 21 May 2024 17:36:39 -0400 Subject: [PATCH 17/37] Set priority for android devices as "priority='high'" is not supported in FCM http v1 API --- src/Message.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Message.php b/src/Message.php index 16f69d2..3b2addf 100644 --- a/src/Message.php +++ b/src/Message.php @@ -19,6 +19,7 @@ class Message implements \JsonSerializable private $notification; private $collapseKey; private $priority; + private $android; private $data; private $recipients = []; private $recipientType; @@ -68,7 +69,11 @@ public function setPriority($priority) $this->priority = $priority; return $this; } - + public function setAndroidPriority(array $priority) + { + $this->android = $priority; + return $this; + } public function setData(array $data) { $this->data = $data; @@ -189,6 +194,9 @@ public function jsonSerialize() if ($this->notification) { $jsonData['notification'] = $this->notification; } + if ($this->android) { + $jsonData['android'] = $this->android; + } return $jsonData; } From 80d2ab84c613136acc734d945cc1ab84ac513107 Mon Sep 17 00:00:00 2001 From: Vaishali Jagtap <71736051+vaishali-vumc@users.noreply.github.com> Date: Wed, 22 May 2024 14:25:49 -0400 Subject: [PATCH 18/37] Removed debug print array line --- src/Client.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index d866085..69fca20 100644 --- a/src/Client.php +++ b/src/Client.php @@ -91,7 +91,6 @@ public function send(Message $message) $messageArr = json_decode(json_encode($param), true); unset($messageArr['message']['registration_ids']); $messageArr['message']['topic'] = $topic; - print_r($messageArr); $output = $this->guzzleClient->post( $this->getHTTPV1ApiUrl(), [ From 5e122218e81c5bfaf19f4782bd867e3b380f8060 Mon Sep 17 00:00:00 2001 From: Vaishali Jagtap <71736051+vaishali-vumc@users.noreply.github.com> Date: Wed, 22 May 2024 15:10:28 -0400 Subject: [PATCH 19/37] Debug response --- src/Client.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Client.php b/src/Client.php index 69fca20..2e133de 100644 --- a/src/Client.php +++ b/src/Client.php @@ -87,6 +87,7 @@ public function send(Message $message) } $topic = "Topic_".date("YmdHis")."_".substr(md5(rand()), 0, 4); $response = $this->addTopicSubscription($topic, $tokens); + var_dump($response); if ($response->getStatusCode() == 200) { $messageArr = json_decode(json_encode($param), true); unset($messageArr['message']['registration_ids']); @@ -103,6 +104,8 @@ public function send(Message $message) ); } $response = $this->removeTopicSubscription($topic, $tokens); + var_dump($response); + var_dump($output); return $output; } else { return $this->guzzleClient->post( From 7489d46a248124f97b963355bdc756df34621b19 Mon Sep 17 00:00:00 2001 From: Vaishali Jagtap <71736051+vaishali-vumc@users.noreply.github.com> Date: Wed, 22 May 2024 15:13:51 -0400 Subject: [PATCH 20/37] Removed debug print array line --- src/Client.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Client.php b/src/Client.php index 2e133de..69fca20 100644 --- a/src/Client.php +++ b/src/Client.php @@ -87,7 +87,6 @@ public function send(Message $message) } $topic = "Topic_".date("YmdHis")."_".substr(md5(rand()), 0, 4); $response = $this->addTopicSubscription($topic, $tokens); - var_dump($response); if ($response->getStatusCode() == 200) { $messageArr = json_decode(json_encode($param), true); unset($messageArr['message']['registration_ids']); @@ -104,8 +103,6 @@ public function send(Message $message) ); } $response = $this->removeTopicSubscription($topic, $tokens); - var_dump($response); - var_dump($output); return $output; } else { return $this->guzzleClient->post( From cacfa55c5feac9f0979114acd90854287c257faf Mon Sep 17 00:00:00 2001 From: Vaishali Jagtap <71736051+vaishali-vumc@users.noreply.github.com> Date: Wed, 22 May 2024 15:17:20 -0400 Subject: [PATCH 21/37] Debug --- src/Client.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Client.php b/src/Client.php index 69fca20..5f6a501 100644 --- a/src/Client.php +++ b/src/Client.php @@ -85,6 +85,7 @@ public function send(Message $message) foreach ($recipients as $recipient) { $tokens[] = $recipient->getToken(); } + var_dump($tokens); die; $topic = "Topic_".date("YmdHis")."_".substr(md5(rand()), 0, 4); $response = $this->addTopicSubscription($topic, $tokens); if ($response->getStatusCode() == 200) { From 742fc7805c8a6d992c79796bcbd3340e32263992 Mon Sep 17 00:00:00 2001 From: Vaishali Jagtap <71736051+vaishali-vumc@users.noreply.github.com> Date: Wed, 22 May 2024 15:21:19 -0400 Subject: [PATCH 22/37] Removed debug print array line --- src/Client.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 5f6a501..69fca20 100644 --- a/src/Client.php +++ b/src/Client.php @@ -85,7 +85,6 @@ public function send(Message $message) foreach ($recipients as $recipient) { $tokens[] = $recipient->getToken(); } - var_dump($tokens); die; $topic = "Topic_".date("YmdHis")."_".substr(md5(rand()), 0, 4); $response = $this->addTopicSubscription($topic, $tokens); if ($response->getStatusCode() == 200) { From a77947572e3c87675430e3c5221d7fd26a4e2e0b Mon Sep 17 00:00:00 2001 From: Vaishali Jagtap <71736051+vaishali-vumc@users.noreply.github.com> Date: Wed, 22 May 2024 15:50:47 -0400 Subject: [PATCH 23/37] debug --- src/Client.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Client.php b/src/Client.php index 69fca20..9734b1a 100644 --- a/src/Client.php +++ b/src/Client.php @@ -105,6 +105,7 @@ public function send(Message $message) $response = $this->removeTopicSubscription($topic, $tokens); return $output; } else { + print_r($param); die; return $this->guzzleClient->post( $this->getHTTPV1ApiUrl(), [ From 4be2072d4daf99e0a589a3ed3f51d68c8f05d75e Mon Sep 17 00:00:00 2001 From: Vaishali Jagtap <71736051+vaishali-vumc@users.noreply.github.com> Date: Wed, 22 May 2024 15:51:46 -0400 Subject: [PATCH 24/37] debug --- src/Client.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 9734b1a..23a24ae 100644 --- a/src/Client.php +++ b/src/Client.php @@ -105,7 +105,8 @@ public function send(Message $message) $response = $this->removeTopicSubscription($topic, $tokens); return $output; } else { - print_r($param); die; + print_r($param); + echo json_encode($param); die; return $this->guzzleClient->post( $this->getHTTPV1ApiUrl(), [ From feaff36ef4f49818076534c1736ced0dde9d3cda Mon Sep 17 00:00:00 2001 From: Vaishali Jagtap <71736051+vaishali-vumc@users.noreply.github.com> Date: Wed, 22 May 2024 15:53:28 -0400 Subject: [PATCH 25/37] debug --- src/Client.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Client.php b/src/Client.php index 23a24ae..ee155b9 100644 --- a/src/Client.php +++ b/src/Client.php @@ -91,6 +91,7 @@ public function send(Message $message) $messageArr = json_decode(json_encode($param), true); unset($messageArr['message']['registration_ids']); $messageArr['message']['topic'] = $topic; + echo json_encode($messageArr); $output = $this->guzzleClient->post( $this->getHTTPV1ApiUrl(), [ @@ -105,8 +106,6 @@ public function send(Message $message) $response = $this->removeTopicSubscription($topic, $tokens); return $output; } else { - print_r($param); - echo json_encode($param); die; return $this->guzzleClient->post( $this->getHTTPV1ApiUrl(), [ From 1c87f26f84bd09060273940923d10f9e15ea1a13 Mon Sep 17 00:00:00 2001 From: Vaishali Jagtap <71736051+vaishali-vumc@users.noreply.github.com> Date: Wed, 22 May 2024 15:56:52 -0400 Subject: [PATCH 26/37] Assigned topic name to projectCode --- src/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index ee155b9..bd76dc7 100644 --- a/src/Client.php +++ b/src/Client.php @@ -91,7 +91,7 @@ public function send(Message $message) $messageArr = json_decode(json_encode($param), true); unset($messageArr['message']['registration_ids']); $messageArr['message']['topic'] = $topic; - echo json_encode($messageArr); + $messageArr['message']['data']['projectCode'] = $topic; $output = $this->guzzleClient->post( $this->getHTTPV1ApiUrl(), [ From e3656273f44edb968b361ab6519eeccdefc3835b Mon Sep 17 00:00:00 2001 From: Vaishali Jagtap <71736051+vaishali-vumc@users.noreply.github.com> Date: Wed, 22 May 2024 15:58:03 -0400 Subject: [PATCH 27/37] debug --- src/Client.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Client.php b/src/Client.php index bd76dc7..e567040 100644 --- a/src/Client.php +++ b/src/Client.php @@ -92,6 +92,7 @@ public function send(Message $message) unset($messageArr['message']['registration_ids']); $messageArr['message']['topic'] = $topic; $messageArr['message']['data']['projectCode'] = $topic; + echo json_encode($messageArr); $output = $this->guzzleClient->post( $this->getHTTPV1ApiUrl(), [ From 6b7eae73d4f5dc16194f798d8915ec616b6ec9c0 Mon Sep 17 00:00:00 2001 From: Vaishali Jagtap <71736051+vaishali-vumc@users.noreply.github.com> Date: Wed, 22 May 2024 15:59:45 -0400 Subject: [PATCH 28/37] Unset participantCode --- src/Client.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Client.php b/src/Client.php index e567040..83616f9 100644 --- a/src/Client.php +++ b/src/Client.php @@ -90,6 +90,7 @@ public function send(Message $message) if ($response->getStatusCode() == 200) { $messageArr = json_decode(json_encode($param), true); unset($messageArr['message']['registration_ids']); + unset($messageArr['message']['data']['participantCode']); $messageArr['message']['topic'] = $topic; $messageArr['message']['data']['projectCode'] = $topic; echo json_encode($messageArr); From e388e642a055e6818dd2cfb7d608c8a0984b4779 Mon Sep 17 00:00:00 2001 From: Vaishali Jagtap <71736051+vaishali-vumc@users.noreply.github.com> Date: Wed, 22 May 2024 16:07:02 -0400 Subject: [PATCH 29/37] Removed debug print array line --- src/Client.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 83616f9..956b72d 100644 --- a/src/Client.php +++ b/src/Client.php @@ -93,7 +93,6 @@ public function send(Message $message) unset($messageArr['message']['data']['participantCode']); $messageArr['message']['topic'] = $topic; $messageArr['message']['data']['projectCode'] = $topic; - echo json_encode($messageArr); $output = $this->guzzleClient->post( $this->getHTTPV1ApiUrl(), [ From 9f6caee9771dfcfda04af52c901931adbebe2058 Mon Sep 17 00:00:00 2001 From: Vaishali Jagtap <71736051+vaishali-vumc@users.noreply.github.com> Date: Wed, 22 May 2024 16:36:07 -0400 Subject: [PATCH 30/37] remove topic subscription only when response is OK --- src/Client.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Client.php b/src/Client.php index 956b72d..4728b93 100644 --- a/src/Client.php +++ b/src/Client.php @@ -90,9 +90,7 @@ public function send(Message $message) if ($response->getStatusCode() == 200) { $messageArr = json_decode(json_encode($param), true); unset($messageArr['message']['registration_ids']); - unset($messageArr['message']['data']['participantCode']); $messageArr['message']['topic'] = $topic; - $messageArr['message']['data']['projectCode'] = $topic; $output = $this->guzzleClient->post( $this->getHTTPV1ApiUrl(), [ @@ -104,7 +102,9 @@ public function send(Message $message) ] ); } - $response = $this->removeTopicSubscription($topic, $tokens); + if ($output->getStatusCode() == 200) { + $response = $this->removeTopicSubscription($topic, $tokens); + } return $output; } else { return $this->guzzleClient->post( From 8e836718ad725202e9bc003e1e56a3ae1886bc9d Mon Sep 17 00:00:00 2001 From: Vaishali Jagtap <71736051+vaishali-vumc@users.noreply.github.com> Date: Wed, 22 May 2024 16:37:21 -0400 Subject: [PATCH 31/37] Debug --- src/Client.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Client.php b/src/Client.php index 4728b93..2aa478c 100644 --- a/src/Client.php +++ b/src/Client.php @@ -102,9 +102,9 @@ public function send(Message $message) ] ); } - if ($output->getStatusCode() == 200) { + /*if ($output->getStatusCode() == 200) { $response = $this->removeTopicSubscription($topic, $tokens); - } + }*/ return $output; } else { return $this->guzzleClient->post( From e0f9e0bbb6d1a9834d08ee2c04bb34900ff04068 Mon Sep 17 00:00:00 2001 From: Vaishali Jagtap <71736051+vaishali-vumc@users.noreply.github.com> Date: Wed, 22 May 2024 16:53:37 -0400 Subject: [PATCH 32/37] Debug --- src/Client.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Client.php b/src/Client.php index 2aa478c..bb44567 100644 --- a/src/Client.php +++ b/src/Client.php @@ -162,11 +162,11 @@ protected function processTopicSubscription($topic_id, $recipients_tokens, $url) $url, [ 'headers' => [ - 'Authorization' => sprintf('key=%s', $this->apiKey), + 'Authorization' => sprintf('Bearer %s', $this->accessToken), 'Content-Type' => 'application/json' ], 'body' => json_encode([ - 'to' => '/topics/' . $topic_id, + 'topic' => $topic_id, 'registration_tokens' => $recipients_tokens, ]) ] From cddf6d89f2f9518539bde61e9c4e4f27258fce9d Mon Sep 17 00:00:00 2001 From: Vaishali Jagtap <71736051+vaishali-vumc@users.noreply.github.com> Date: Wed, 22 May 2024 16:56:31 -0400 Subject: [PATCH 33/37] Debug --- src/Client.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Client.php b/src/Client.php index bb44567..2aa478c 100644 --- a/src/Client.php +++ b/src/Client.php @@ -162,11 +162,11 @@ protected function processTopicSubscription($topic_id, $recipients_tokens, $url) $url, [ 'headers' => [ - 'Authorization' => sprintf('Bearer %s', $this->accessToken), + 'Authorization' => sprintf('key=%s', $this->apiKey), 'Content-Type' => 'application/json' ], 'body' => json_encode([ - 'topic' => $topic_id, + 'to' => '/topics/' . $topic_id, 'registration_tokens' => $recipients_tokens, ]) ] From c84212d95b1be15153c27b0064a276fabbff27cf Mon Sep 17 00:00:00 2001 From: Vaishali Jagtap <71736051+vaishali-vumc@users.noreply.github.com> Date: Wed, 22 May 2024 19:06:59 -0400 Subject: [PATCH 34/37] Debug --- src/Client.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 2aa478c..db0dc4a 100644 --- a/src/Client.php +++ b/src/Client.php @@ -162,7 +162,8 @@ protected function processTopicSubscription($topic_id, $recipients_tokens, $url) $url, [ 'headers' => [ - 'Authorization' => sprintf('key=%s', $this->apiKey), + 'Authorization' => sprintf('Bearer %s', $this->accessToken), + 'access_token_auth' => true, 'Content-Type' => 'application/json' ], 'body' => json_encode([ From 89d6055bf46677a61a48667a8c801631c9a2d1ec Mon Sep 17 00:00:00 2001 From: Vaishali Jagtap <71736051+vaishali-vumc@users.noreply.github.com> Date: Thu, 30 May 2024 19:38:39 -0400 Subject: [PATCH 35/37] Fix for Sending notification to multiple devices at same time --- src/Client.php | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/src/Client.php b/src/Client.php index db0dc4a..20cb153 100644 --- a/src/Client.php +++ b/src/Client.php @@ -78,33 +78,25 @@ public function send(Message $message) $param = ['message' => $message]; // FCM HTTP V1 does not support sending notifications to multiple devices (supported only in legacy API via registration_tokens - // So, Adding topic subscription, sending notification to topic, then remove topic subscription + // So, sending notification to devices in a loop (It will be rare case where same participant joined from different devices) $recipients = $message->getRecipients(); if (count($recipients) > 1) { - $tokens = []; foreach ($recipients as $recipient) { - $tokens[] = $recipient->getToken(); - } - $topic = "Topic_".date("YmdHis")."_".substr(md5(rand()), 0, 4); - $response = $this->addTopicSubscription($topic, $tokens); - if ($response->getStatusCode() == 200) { + $token = $recipient->getToken(); $messageArr = json_decode(json_encode($param), true); unset($messageArr['message']['registration_ids']); - $messageArr['message']['topic'] = $topic; + $messageArr['message']['token'] = $token; $output = $this->guzzleClient->post( - $this->getHTTPV1ApiUrl(), - [ - 'headers' => [ - 'Authorization' => sprintf('Bearer %s', $this->accessToken), - 'Content-Type' => 'application/json' - ], - 'body' => json_encode($messageArr) - ] + $this->getHTTPV1ApiUrl(), + [ + 'headers' => [ + 'Authorization' => sprintf('Bearer %s', $this->accessToken), + 'Content-Type' => 'application/json' + ], + 'body' => json_encode($messageArr) + ] ); } - /*if ($output->getStatusCode() == 200) { - $response = $this->removeTopicSubscription($topic, $tokens); - }*/ return $output; } else { return $this->guzzleClient->post( @@ -118,8 +110,6 @@ public function send(Message $message) ] ); } - return $output; - } /** From 2a459139f62420655a5818e3695df6bfcdefe1b9 Mon Sep 17 00:00:00 2001 From: "mend-for-github-com[bot]" <50673670+mend-for-github-com[bot]@users.noreply.github.com> Date: Fri, 1 Aug 2025 19:15:24 +0000 Subject: [PATCH 36/37] Add .whitesource configuration file --- .whitesource | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .whitesource diff --git a/.whitesource b/.whitesource new file mode 100644 index 0000000..0255b87 --- /dev/null +++ b/.whitesource @@ -0,0 +1,3 @@ +{ + "settingsInheritedFrom": "vanderbilt-redcap/whitesource-config@main" +} \ No newline at end of file From c1d937d7138531fa3c56e8ad179abb691526d8a1 Mon Sep 17 00:00:00 2001 From: Vaishali Jagtap <71736051+vaishali-vumc@users.noreply.github.com> Date: Mon, 29 Jun 2026 12:09:39 -0400 Subject: [PATCH 37/37] Update to Guzzle 7 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 28bb403..00b2a58 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ } ], "require": { - "guzzlehttp/guzzle": "*", + "guzzlehttp/guzzle": "^7.8", "php": ">=5.5" }, "require-dev": {