From 7904e52c8c0857ebbd52944d15d092d79aed61bd Mon Sep 17 00:00:00 2001 From: ZeroHuang Date: Fri, 29 Apr 2016 17:38:16 +0800 Subject: [PATCH 1/4] Fix message content error --- src/Services/GooglePushService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Services/GooglePushService.php b/src/Services/GooglePushService.php index b4614de..e0fde4a 100644 --- a/src/Services/GooglePushService.php +++ b/src/Services/GooglePushService.php @@ -49,7 +49,7 @@ public function send() } if ($this->messageText !== null) { - $body['data']['message'] = $this->messageText; + $body['data']['content'] = $this->messageText; } $ok = []; From f1868c62e7a7f001c0ed6ed3c15b22070f299e2b Mon Sep 17 00:00:00 2001 From: ZeroHuang Date: Fri, 29 Apr 2016 18:44:18 +0800 Subject: [PATCH 2/4] Add message title --- src/Services/GooglePushService.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Services/GooglePushService.php b/src/Services/GooglePushService.php index e0fde4a..6c8725d 100644 --- a/src/Services/GooglePushService.php +++ b/src/Services/GooglePushService.php @@ -13,6 +13,12 @@ class GooglePushService extends AbstractPushService */ private $client; + /** + * @var string + * The title of message + */ + protected $messageTitle = null; + /** * @inheritdoc */ @@ -35,6 +41,17 @@ public function loadConfiguration($config) return true; } + /** + * Set message title + * + * @param string $title message title + */ + public function setMessageTitle($title) + { + $this->messageTitle = $title; + return $this; + } + /** * @inheritdoc */ @@ -48,6 +65,10 @@ public function send() $body['data'] = $this->messageData; } + if ($this->messageTitle !== null) { + $body['data']['title'] = $this->messageTitle; + } + if ($this->messageText !== null) { $body['data']['content'] = $this->messageText; } From c0b282b0fc1c1d604b3407725ebc8ab974a185ca Mon Sep 17 00:00:00 2001 From: Zero Date: Wed, 4 May 2016 08:52:07 +0800 Subject: [PATCH 3/4] Define member and method --- src/Services/AbstractPushService.php | 6 ++++++ src/Services/GooglePushService.php | 6 ------ src/Services/PushService.php | 10 ++++++++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Services/AbstractPushService.php b/src/Services/AbstractPushService.php index a5e8ec3..6f698e1 100644 --- a/src/Services/AbstractPushService.php +++ b/src/Services/AbstractPushService.php @@ -9,6 +9,12 @@ abstract class AbstractPushService implements PushService */ protected $messageText = null; + /** + * @var string|null + * The text of the message + */ + protected $messageTitle = null; + /** * @var array|null * The data of the message diff --git a/src/Services/GooglePushService.php b/src/Services/GooglePushService.php index 6c8725d..a7a715e 100644 --- a/src/Services/GooglePushService.php +++ b/src/Services/GooglePushService.php @@ -13,12 +13,6 @@ class GooglePushService extends AbstractPushService */ private $client; - /** - * @var string - * The title of message - */ - protected $messageTitle = null; - /** * @inheritdoc */ diff --git a/src/Services/PushService.php b/src/Services/PushService.php index f543e36..3954a59 100644 --- a/src/Services/PushService.php +++ b/src/Services/PushService.php @@ -23,6 +23,16 @@ public function loadConfiguration($config); */ public function setMessageText($message); + /** + * Set the message title for this push message. + * + * @param string $title + * The message title to set + * @return self + * This instance, to allow chaining + */ + public function setMessageTitle($title); + /** * Set the message data for this push message. * This will clear any previous message data From 0d68908cb7e777b3ea370db04161e40fbe45915e Mon Sep 17 00:00:00 2001 From: Zero Date: Wed, 4 May 2016 08:55:53 +0800 Subject: [PATCH 4/4] Throw exception when setMessageTitle() called in ApplePushService --- src/Services/ApplePushService.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Services/ApplePushService.php b/src/Services/ApplePushService.php index 2b65764..1ab3e79 100644 --- a/src/Services/ApplePushService.php +++ b/src/Services/ApplePushService.php @@ -13,6 +13,11 @@ class ApplePushService extends AbstractPushService */ private $client; + public function setMessageTitle($title) + { + throw new RuntimeException('APNS does not support message title'); + } + /** * @inheritdoc */