├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── composer.json └── src ├── BaseMessage.php ├── Client.php └── Message.php /.gitignore: -------------------------------------------------------------------------------- 1 | composer.phar 2 | vendor/ 3 | sample/ 4 | .idea/ 5 | 6 | # Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file 7 | # You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file 8 | composer.lock 9 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | PHP albaraam/php-gcm-apns library Change Log 2 | =============================================== 3 | 4 | 1.0.0 December 3, 2015 5 | ------------------------- 6 | 7 | - Initial release. 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Albaraa Mishlawi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # albaraam/php-gcm-apns 2 | 3 | A PHP Library for sending messages to devices (Android & IOS) through GCM and Apns (respectively). 4 | 5 | 6 | Installation 7 | ------------- 8 | 9 | The preferred way to install this extension is through [composer](http://getcomposer.org/download/). 10 | 11 | Either run 12 | 13 | ```json 14 | composer require albaraam/php-gcm-apns "~1.0.0" 15 | ``` 16 | 17 | or add 18 | 19 | ```json 20 | "albaraam/php-gcm-apns": "~1.0.0" 21 | ``` 22 | 23 | to the `require` section of your composer.json. 24 | 25 | 26 | Usage 27 | ------------ 28 | 29 | ```php 30 | 31 | use albaraam\gcmapns\Message; 32 | use albaraam\gcmapns\Client; 33 | 34 | // Message creation 35 | $message = new Message("Title","Body"); 36 | 37 | // Common attributes for both ios and android 38 | $message 39 | ->setTitle("Title") 40 | ->setBody("Body") 41 | ->setSound("sound.mp3") 42 | ->setData(['foo'=>'bar']); 43 | 44 | // Android specific attributes 45 | $message->android 46 | ->setTo("ids") 47 | ->setIcon("icon") 48 | ->setCollapseKey("collapse_key") 49 | ->setColor("#333"); 50 | 51 | // IOS specific attributes 52 | $message->ios 53 | ->setTo("ids") 54 | ->setSound("sound_ios.mp3") // custom sound for ios 55 | ->setBadge(3); 56 | 57 | // Client 58 | $client = new Client("google_api_key","path/to/pem/file",Client::IOS_ENVIRONMENT_SANDBOX); 59 | 60 | // configure client 61 | $client->setIosPassphrase("passphrase"); 62 | ... 63 | 64 | // Send message 65 | $client->send($message); 66 | 67 | ``` 68 | 69 | 70 | Usage: Advanced Example 71 | ----------------------- 72 | 73 | ```php 74 | 75 | use albaraam\gcmapns\Message; 76 | use albaraam\gcmapns\Client; 77 | 78 | $message = new Message("Title","Body"); 79 | 80 | $message 81 | ->setTitle("Title") 82 | ->setBody("Body") 83 | ->setPriority(5) // 5 or 10 84 | ->setContentAvailable(true) 85 | ->setDryRun(false) 86 | ->setClickAction("") // same as Category 87 | ->setCategory("") // same as ClickAction 88 | ->setTitleLocKey("") 89 | ->setTitleLocArgs("") 90 | ->setBodyLocKey("") 91 | ->setBodyLocArgs("") 92 | ->setSound("sound.mp3") 93 | ->setData(['foo'=>'bar']); 94 | 95 | 96 | $message->android 97 | ->setTo("ids") 98 | ->setIcon("icon") 99 | ->setCollapseKey(true) 100 | ->setDelayWhileIdle(true) 101 | ->setTimeToLive(3600) 102 | ->setRestrictedPackageName("") 103 | ->setTag("") 104 | ->setColor("#333"); 105 | 106 | $message->ios 107 | ->setTo("ids") 108 | ->setLaunchImage("") 109 | ->setBadge(3) 110 | ->setActionLocKey(""); 111 | 112 | $client = new Client("google_api_key","path/to/pem/file",Client::IOS_ENVIRONMENT_SANDBOX); 113 | $client->setIosPassphrase("passphrase"); 114 | 115 | $client->sendAndroid($message)) // send for android devices only 116 | $client->sendIOS($message)) // send for ios devices only 117 | // $client->send($message)) // send for both ios & android devices 118 | 119 | ``` 120 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "albaraam/php-gcm-apns", 3 | "description": "A PHP Library for sending messages to devices (Android & IOS) through GCM and Apns (respectively).", 4 | "keywords": ["php", "gcm", "apns", "php-gcm-apns", "push"], 5 | "type": "library", 6 | "license": "MIT License", 7 | "minimum-stability": "dev", 8 | "support": { 9 | "issues": "https://github.com/albaraam/php-gcm-apns/issues", 10 | "source": "https://github.com/albaraam/php-gcm-apns" 11 | }, 12 | "authors": [ 13 | { 14 | "name": "Albaraa Mishlawi", 15 | "email": "albaraa_m@live.com" 16 | } 17 | ], 18 | "require": { 19 | "php": ">=5.3.0", 20 | "albaraam/php-gcm": "1.0.0", 21 | "duccio/apns-php": "dev-master" 22 | }, 23 | "autoload": { 24 | "psr-4": { "albaraam\\gcmapns\\": "src/" } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/BaseMessage.php: -------------------------------------------------------------------------------- 1 | title; 73 | } 74 | 75 | /** 76 | * @param string $title 77 | * @return $this 78 | */ 79 | public function setTitle($title) 80 | { 81 | $this->title = $title; 82 | return $this; 83 | } 84 | 85 | /** 86 | * @return string 87 | */ 88 | public function getBody() 89 | { 90 | return $this->body; 91 | } 92 | 93 | /** 94 | * @param string $body 95 | * @return $this 96 | */ 97 | public function setBody($body) 98 | { 99 | $this->body = $body; 100 | return $this; 101 | } 102 | 103 | /** 104 | * @return int 105 | */ 106 | public function getPriority() 107 | { 108 | return $this->priority; 109 | } 110 | 111 | /** 112 | * @param int $priority 113 | * @return $this 114 | */ 115 | public function setPriority($priority) 116 | { 117 | $this->priority = $priority; 118 | return $this; 119 | } 120 | 121 | /** 122 | * @return boolean 123 | */ 124 | public function isContentAvailable() 125 | { 126 | return $this->contentAvailable; 127 | } 128 | 129 | /** 130 | * @param boolean $contentAvailable 131 | * @return $this 132 | */ 133 | public function setContentAvailable($contentAvailable) 134 | { 135 | $this->contentAvailable = $contentAvailable; 136 | return $this; 137 | } 138 | 139 | /** 140 | * @return boolean 141 | */ 142 | public function isDryRun() 143 | { 144 | return $this->dryRun; 145 | } 146 | 147 | /** 148 | * @param boolean $dryRun 149 | * @return $this 150 | */ 151 | public function setDryRun($dryRun) 152 | { 153 | $this->dryRun = $dryRun; 154 | return $this; 155 | } 156 | 157 | /** 158 | * @return string 159 | */ 160 | public function getClickAction() 161 | { 162 | return $this->clickAction; 163 | } 164 | 165 | /** 166 | * @param string $clickAction 167 | * @return $this 168 | */ 169 | public function setClickAction($clickAction) 170 | { 171 | $this->clickAction = $clickAction; 172 | return $this; 173 | } 174 | 175 | /** 176 | * @return string 177 | */ 178 | public function getCategory() 179 | { 180 | return $this->category; 181 | } 182 | 183 | /** 184 | * @param string $category 185 | * @return $this 186 | */ 187 | public function setCategory($category) 188 | { 189 | $this->category = $category; 190 | return $this; 191 | } 192 | 193 | /** 194 | * @return string 195 | */ 196 | public function getTitleLocKey() 197 | { 198 | return $this->titleLocKey; 199 | } 200 | 201 | /** 202 | * @param string $titleLocKey 203 | * @return $this 204 | */ 205 | public function setTitleLocKey($titleLocKey) 206 | { 207 | $this->titleLocKey = $titleLocKey; 208 | return $this; 209 | } 210 | 211 | /** 212 | * @return string 213 | */ 214 | public function getTitleLocArgs() 215 | { 216 | return $this->titleLocArgs; 217 | } 218 | 219 | /** 220 | * @param string $titleLocArgs 221 | * @return $this 222 | */ 223 | public function setTitleLocArgs($titleLocArgs) 224 | { 225 | $this->titleLocArgs = $titleLocArgs; 226 | return $this; 227 | } 228 | 229 | /** 230 | * @return string 231 | */ 232 | public function getBodyLocKey() 233 | { 234 | return $this->bodyLocKey; 235 | } 236 | 237 | /** 238 | * @param string $bodyLocKey 239 | * @return $this 240 | */ 241 | public function setBodyLocKey($bodyLocKey) 242 | { 243 | $this->bodyLocKey = $bodyLocKey; 244 | return $this; 245 | } 246 | 247 | /** 248 | * @return string 249 | */ 250 | public function getBodyLocArgs() 251 | { 252 | return $this->bodyLocArgs; 253 | } 254 | 255 | /** 256 | * @param string $bodyLocArgs 257 | * @return $this 258 | */ 259 | public function setBodyLocArgs($bodyLocArgs) 260 | { 261 | $this->bodyLocArgs = $bodyLocArgs; 262 | return $this; 263 | } 264 | 265 | /** 266 | * @return string 267 | */ 268 | public function getSound() 269 | { 270 | return $this->sound; 271 | } 272 | 273 | /** 274 | * @param string $sound 275 | * @return $this 276 | */ 277 | public function setSound($sound) 278 | { 279 | $this->sound = $sound; 280 | return $this; 281 | } 282 | 283 | /** 284 | * @return array|null 285 | */ 286 | public function getData() 287 | { 288 | return $this->data; 289 | } 290 | 291 | /** 292 | * @param array|null $data 293 | * @return $this 294 | */ 295 | public function setData($data) 296 | { 297 | $this->data = $data; 298 | return $this; 299 | } 300 | 301 | 302 | } -------------------------------------------------------------------------------- /src/Client.php: -------------------------------------------------------------------------------- 1 | google_api_key = $google_api_key; 53 | $this->ios_pem_file = $ios_pem_file; 54 | $this->ios_environment = $ios_environment; 55 | } 56 | 57 | public function send(Message $message) 58 | { 59 | $response = ["android"=>[],"ios"=>[]]; 60 | if($this->getAndroidClient()) $response['android'] = $this->sendAndroid($message); 61 | if($this->getIOSClient()) $response['ios'] = $this->sendIOS($message); 62 | return $response; 63 | } 64 | 65 | public function sendAndroid(Message $message) 66 | { 67 | // payload notification 68 | $notification = new GCMNotification($message->android->getTitle(),$message->android->getBody()); 69 | $notification->setBodyLocKey($message->android->getBodyLocKey()); 70 | $notification->setBodyLocArgs($message->android->getBodyLocArgs()); 71 | $notification->setClickAction($message->android->getClickAction()); 72 | $notification->setColor($message->android->getColor()); 73 | $notification->setIcon($message->android->getIcon()); 74 | $notification->setSound($message->android->getSound()); 75 | $notification->setTag($message->android->getTag()); 76 | $notification->setTitleLocKey($message->android->getTitleLocKey()); 77 | $notification->setTitleLocArgs($message->android->getTitleLocArgs()); 78 | $notification->setContentAvailable($message->android->isContentAvailable()); 79 | 80 | // registration ids 81 | $_message = new GCMMessage($notification,$message->android->getTo()); 82 | // options 83 | $_message->setCollapseKey($message->android->getCollapseKey()); 84 | $_message->setDelayWhileIdle($message->android->getDelayWhileIdle()); 85 | $_message->setDryRun($message->android->isDryRun()); 86 | $_message->setRestrictedPackageName($message->android->getRestrictedPackageName()); 87 | $_message->setTimeToLive($message->android->getTimeToLive()); 88 | // payload data 89 | $_message->setData($message->android->getData()); 90 | 91 | return $this->getAndroidClient()->send($_message); 92 | } 93 | 94 | public function sendIOS(Message $message) 95 | { 96 | // Prepare message 97 | // $_message = new \ApnsPHP_Message(); 98 | $_message = new \ApnsPHP_Message_Custom(); 99 | foreach ($message->ios->getTo() as $token) { 100 | $_message->addRecipient($token); 101 | } 102 | // normal ApnsPHP_Message 103 | $_message->setText($message->ios->getBody()); 104 | $_message->setBadge($message->ios->getBadge()); 105 | $_message->setSound($message->ios->getSound()); 106 | $_message->setContentAvailable($message->ios->isContentAvailable()); 107 | $_message->setCategory($message->ios->getCategory()); 108 | // custom ApnsPHP_Message 109 | $_message->setTitle($message->ios->getTitle()); 110 | $_message->setLocKey($message->ios->getBodyLocKey()); 111 | $_message->setLocArgs($message->ios->getBodyLocArgs()); 112 | $_message->setLaunchImage($message->ios->getLaunchImage()); 113 | // set additional data (payload data) 114 | foreach ($message->ios->getData() as $key => $value) { 115 | $_message->setCustomProperty($key, $value); 116 | } 117 | // Connection 118 | $this->getIOSClient()->connect(); 119 | $this->getIOSClient()->add($_message); 120 | $this->getIOSClient()->send(); 121 | $this->getIOSClient()->disconnect(); 122 | return $this->getIOSClient()->getErrors(true); 123 | } 124 | 125 | private function getAndroidClient() 126 | { 127 | if($this->_android_client == null){ 128 | if($this->google_api_key == "") return null; 129 | $this->_android_client = new GCMClient($this->google_api_key); 130 | } 131 | return $this->_android_client; 132 | } 133 | 134 | private function getIOSClient() 135 | { 136 | if($this->_ios_client == null) { 137 | if($this->ios_environment === "" || $this->ios_pem_file == "" 138 | || $this->ios_environment === null || $this->ios_pem_file == null){ 139 | return null; 140 | } 141 | $this->_ios_client = new \ApnsPHP_Push( 142 | $this->ios_environment == self::IOS_ENVIRONMENT_PRODUCTION 143 | ? \ApnsPHP_Push::ENVIRONMENT_PRODUCTION 144 | : \ApnsPHP_Push::ENVIRONMENT_SANDBOX, 145 | $this->ios_pem_file 146 | ); 147 | } 148 | return $this->_ios_client; 149 | } 150 | 151 | /*********************************************** Getters & Setters ***********************************************/ 152 | 153 | /** 154 | * @return string 155 | */ 156 | public function getGoogleApiKey() 157 | { 158 | return $this->google_api_key; 159 | } 160 | 161 | /** 162 | * @return mixed 163 | */ 164 | public function getIosEnvironment() 165 | { 166 | return $this->ios_environment; 167 | } 168 | 169 | /** 170 | * @return string 171 | */ 172 | public function getIosPemFile() 173 | { 174 | return $this->ios_pem_file; 175 | } 176 | 177 | /** 178 | * @return string 179 | */ 180 | public function getIosPassphrase() 181 | { 182 | return $this->ios_passphrase; 183 | } 184 | 185 | /** 186 | * @return string 187 | */ 188 | public function setIosPassphrase($ios_passphrase) 189 | { 190 | $this->ios_passphrase = $ios_passphrase; 191 | } 192 | 193 | /** 194 | * @return mixed 195 | */ 196 | public function getIosProviderCertificatePassphrase() 197 | { 198 | return $this->ios_provider_certificate_passphrase; 199 | } 200 | 201 | /** 202 | * @param mixed $ios_provider_certificate_passphrase 203 | */ 204 | public function setIosProviderCertificatePassphrase($ios_provider_certificate_passphrase) 205 | { 206 | $this->ios_provider_certificate_passphrase = $ios_provider_certificate_passphrase; 207 | $this->getIOSClient()->setProviderCertificatePassphrase($ios_provider_certificate_passphrase); 208 | } 209 | 210 | /** 211 | * @return mixed 212 | */ 213 | public function getIosRootCertificationAuthority() 214 | { 215 | return $this->ios_root_certification_authority; 216 | } 217 | 218 | /** 219 | * @param mixed $ios_root_certification_authority 220 | */ 221 | public function setIosRootCertificationAuthority($ios_root_certification_authority) 222 | { 223 | $this->ios_root_certification_authority = $ios_root_certification_authority; 224 | $this->getIOSClient()->setRootCertificationAuthority($ios_root_certification_authority); 225 | } 226 | 227 | /** 228 | * @return mixed 229 | */ 230 | public function getIosWriteInterval() 231 | { 232 | return $this->ios_write_interval; 233 | } 234 | 235 | /** 236 | * @param mixed $ios_write_interval 237 | */ 238 | public function setIosWriteInterval($ios_write_interval) 239 | { 240 | $this->ios_write_interval = $ios_write_interval; 241 | $this->getIOSClient()->setWriteInterval($ios_write_interval); 242 | } 243 | 244 | /** 245 | * @return mixed 246 | */ 247 | public function getIosConnectTimeout() 248 | { 249 | return $this->ios_connect_timeout; 250 | } 251 | 252 | /** 253 | * @param mixed $ios_connect_timeout 254 | */ 255 | public function setIosConnectTimeout($ios_connect_timeout) 256 | { 257 | $this->ios_connect_timeout = $ios_connect_timeout; 258 | $this->getIOSClient()->setConnectTimeout($ios_connect_timeout); 259 | } 260 | 261 | /** 262 | * @return mixed 263 | */ 264 | public function getIosConnectRetryTimes() 265 | { 266 | return $this->ios_connect_retry_times; 267 | } 268 | 269 | /** 270 | * @param mixed $ios_connect_retry_times 271 | */ 272 | public function setIosConnectRetryTimes($ios_connect_retry_times) 273 | { 274 | $this->ios_connect_retry_times = $ios_connect_retry_times; 275 | $this->getIOSClient()->setConnectRetryTimes($ios_connect_retry_times); 276 | } 277 | 278 | /** 279 | * @return mixed 280 | */ 281 | public function getIosConnectRetryInterval() 282 | { 283 | return $this->ios_connect_retry_interval; 284 | } 285 | 286 | /** 287 | * @param mixed $ios_connect_retry_interval 288 | */ 289 | public function setIosConnectRetryInterval($ios_connect_retry_interval) 290 | { 291 | $this->ios_connect_retry_interval = $ios_connect_retry_interval; 292 | $this->getIOSClient()->setConnectRetryInterval($ios_connect_retry_interval); 293 | } 294 | 295 | /** 296 | * @return mixed 297 | */ 298 | public function getIosSocketSelectTimeout() 299 | { 300 | return $this->ios_socket_select_timeout; 301 | } 302 | 303 | /** 304 | * @param mixed $ios_socket_select_timeout 305 | */ 306 | public function setIosSocketSelectTimeout($ios_socket_select_timeout) 307 | { 308 | $this->ios_socket_select_timeout = $ios_socket_select_timeout; 309 | $this->getIOSClient()->setSocketSelectTimeout($ios_socket_select_timeout); 310 | } 311 | 312 | /** 313 | * @return mixed 314 | */ 315 | public function getIosLogger() 316 | { 317 | return $this->ios_logger; 318 | } 319 | 320 | /** 321 | * @param mixed $ios_logger 322 | */ 323 | public function setIosLogger(\ApnsPHP_Log_Interface $ios_logger) 324 | { 325 | $this->ios_logger = $ios_logger; 326 | $this->getIOSClient()->setLogger($ios_logger); 327 | } 328 | 329 | 330 | } 331 | -------------------------------------------------------------------------------- /src/Message.php: -------------------------------------------------------------------------------- 1 | android = new AndroidMessage(); 21 | $this->ios = new IOSMessage(); 22 | $this->setTitle($title); 23 | $this->setBody($body); 24 | return $this; 25 | } 26 | 27 | /** 28 | * @param string $title 29 | * @return $this 30 | */ 31 | public function setTitle($title) 32 | { 33 | $this->title = $title; 34 | $this->android->setTitle($title); 35 | $this->ios->setTitle($title); 36 | return $this; 37 | } 38 | 39 | /** 40 | * @param string $body 41 | * @return $this 42 | */ 43 | public function setBody($body) 44 | { 45 | $this->body = $body; 46 | $this->android->setBody($body); 47 | $this->ios->setBody($body); 48 | return $this; 49 | } 50 | 51 | /** 52 | * @param int $priority 53 | * @return $this 54 | */ 55 | public function setPriority($priority) 56 | { 57 | $this->priority = $priority; 58 | $this->android->setPriority($priority); 59 | $this->ios->setPriority($priority); 60 | return $this; 61 | } 62 | 63 | /** 64 | * @param boolean $contentAvailable 65 | * @return $this 66 | */ 67 | public function setContentAvailable($contentAvailable) 68 | { 69 | $this->contentAvailable = $contentAvailable; 70 | $this->android->setContentAvailable($contentAvailable); 71 | $this->ios->setContentAvailable($contentAvailable); 72 | return $this; 73 | } 74 | 75 | /** 76 | * @param boolean $dryRun 77 | * @return $this 78 | */ 79 | public function setDryRun($dryRun) 80 | { 81 | $this->dryRun = $dryRun; 82 | $this->android->setDryRun($dryRun); 83 | $this->ios->setDryRun($dryRun); 84 | return $this; 85 | } 86 | 87 | /** 88 | * @param string $clickAction 89 | * @return $this 90 | */ 91 | public function setClickAction($clickAction) 92 | { 93 | $this->clickAction = $clickAction; 94 | $this->android->setClickAction($clickAction); 95 | $this->ios->setCategory($clickAction); 96 | return $this; 97 | } 98 | 99 | /** 100 | * @param string $category 101 | * @return $this 102 | */ 103 | public function setCategory($category) 104 | { 105 | $this->category = $category; 106 | $this->android->setClickAction($category); 107 | $this->ios->setCategory($category); 108 | return $this; 109 | } 110 | 111 | /** 112 | * @param string $titleLocKey 113 | * @return $this 114 | */ 115 | public function setTitleLocKey($titleLocKey) 116 | { 117 | $this->titleLocKey = $titleLocKey; 118 | $this->android->setTitleLocKey($titleLocKey); 119 | $this->ios->setTitleLocKey($titleLocKey); 120 | return $this; 121 | } 122 | 123 | /** 124 | * @param string $titleLocArgs 125 | * @return $this 126 | */ 127 | public function setTitleLocArgs($titleLocArgs) 128 | { 129 | $this->titleLocArgs = $titleLocArgs; 130 | $this->android->setTitleLocArgs($titleLocArgs); 131 | $this->ios->setTitleLocArgs($titleLocArgs); 132 | return $this; 133 | } 134 | 135 | /** 136 | * @param string $bodyLocKey 137 | * @return $this 138 | */ 139 | public function setBodyLocKey($bodyLocKey) 140 | { 141 | $this->bodyLocKey = $bodyLocKey; 142 | $this->android->setBodyLocKey($bodyLocKey); 143 | $this->ios->setBodyLocKey($bodyLocKey); 144 | return $this; 145 | } 146 | 147 | /** 148 | * @param string $bodyLocArgs 149 | * @return $this 150 | */ 151 | public function setBodyLocArgs($bodyLocArgs) 152 | { 153 | $this->bodyLocArgs = $bodyLocArgs; 154 | $this->android->setBodyLocArgs($bodyLocArgs); 155 | $this->ios->setBodyLocArgs($bodyLocArgs); 156 | return $this; 157 | } 158 | 159 | /** 160 | * @param string $sound 161 | * @return $this 162 | */ 163 | public function setSound($sound) 164 | { 165 | $this->sound = $sound; 166 | $this->android->setSound($sound); 167 | $this->ios->setSound($sound); 168 | return $this; 169 | } 170 | 171 | /** 172 | * @param array|null $data 173 | * @return $this 174 | */ 175 | public function setData($data) 176 | { 177 | $this->data = $data; 178 | $this->android->setData($data); 179 | $this->ios->setData($data); 180 | return $this; 181 | } 182 | 183 | } 184 | 185 | class AndroidMessage extends BaseMessage{ 186 | 187 | private $to; 188 | private $icon; 189 | private $collapseKey; 190 | private $delayWhileIdle; 191 | private $timeToLive; 192 | private $restrictedPackageName; 193 | private $tag; 194 | private $color; 195 | 196 | /** 197 | * @return mixed 198 | */ 199 | public function getTo() 200 | { 201 | return $this->to; 202 | } 203 | 204 | /** 205 | * @param mixed $to 206 | * @return $this 207 | */ 208 | public function setTo($to) 209 | { 210 | $this->to = (is_array($to)) ? $to : [$to]; 211 | return $this; 212 | } 213 | 214 | /** 215 | * @return mixed 216 | */ 217 | public function getIcon() 218 | { 219 | return $this->icon; 220 | } 221 | 222 | /** 223 | * @param mixed $icon 224 | * @return $this 225 | */ 226 | public function setIcon($icon) 227 | { 228 | $this->icon = $icon; 229 | return $this; 230 | } 231 | 232 | /** 233 | * @return mixed 234 | */ 235 | public function getCollapseKey() 236 | { 237 | return $this->collapseKey; 238 | } 239 | 240 | /** 241 | * @param mixed $collapseKey 242 | * @return $this 243 | */ 244 | public function setCollapseKey($collapseKey) 245 | { 246 | $this->collapseKey = $collapseKey; 247 | return $this; 248 | } 249 | 250 | /** 251 | * @return mixed 252 | */ 253 | public function getDelayWhileIdle() 254 | { 255 | return $this->delayWhileIdle; 256 | } 257 | 258 | /** 259 | * @param mixed $delayWhileIdle 260 | * @return $this 261 | */ 262 | public function setDelayWhileIdle($delayWhileIdle) 263 | { 264 | $this->delayWhileIdle = $delayWhileIdle; 265 | return $this; 266 | } 267 | 268 | /** 269 | * @return mixed 270 | */ 271 | public function getTimeToLive() 272 | { 273 | return $this->timeToLive; 274 | } 275 | 276 | /** 277 | * @param mixed $timeToLive 278 | * @return $this 279 | */ 280 | public function setTimeToLive($timeToLive) 281 | { 282 | $this->timeToLive = $timeToLive; 283 | return $this; 284 | } 285 | 286 | /** 287 | * @return mixed 288 | */ 289 | public function getRestrictedPackageName() 290 | { 291 | return $this->restrictedPackageName; 292 | } 293 | 294 | /** 295 | * @param mixed $restrictedPackageName 296 | * @return $this 297 | */ 298 | public function setRestrictedPackageName($restrictedPackageName) 299 | { 300 | $this->restrictedPackageName = $restrictedPackageName; 301 | return $this; 302 | } 303 | 304 | /** 305 | * @return mixed 306 | */ 307 | public function getTag() 308 | { 309 | return $this->tag; 310 | } 311 | 312 | /** 313 | * @param mixed $tag 314 | * @return $this 315 | */ 316 | public function setTag($tag) 317 | { 318 | $this->tag = $tag; 319 | return $this; 320 | } 321 | 322 | /** 323 | * @return mixed 324 | */ 325 | public function getColor() 326 | { 327 | return $this->color; 328 | } 329 | 330 | /** 331 | * @param mixed $color 332 | * @return $this 333 | */ 334 | public function setColor($color) 335 | { 336 | $this->color = $color; 337 | return $this; 338 | } 339 | 340 | } 341 | 342 | class IOSMessage extends BaseMessage{ 343 | 344 | private $to; 345 | private $launchImage; 346 | private $badge; 347 | private $actionLocKey; 348 | 349 | /** 350 | * @return mixed 351 | */ 352 | public function getTo() 353 | { 354 | return $this->to; 355 | } 356 | 357 | /** 358 | * @param mixed $to 359 | * @return $this 360 | */ 361 | public function setTo($to) 362 | { 363 | $this->to = (is_array($to)) ? $to : [$to]; 364 | return $this; 365 | } 366 | 367 | /** 368 | * @return mixed 369 | */ 370 | public function getLaunchImage() 371 | { 372 | return $this->launchImage; 373 | } 374 | 375 | /** 376 | * @param mixed $launchImage 377 | * @return $this 378 | */ 379 | public function setLaunchImage($launchImage) 380 | { 381 | $this->launchImage = $launchImage; 382 | return $this; 383 | } 384 | 385 | /** 386 | * @return mixed 387 | */ 388 | public function getBadge() 389 | { 390 | return $this->badge; 391 | } 392 | 393 | /** 394 | * @param mixed $badge 395 | * @return $this 396 | */ 397 | public function setBadge($badge) 398 | { 399 | $this->badge = $badge; 400 | return $this; 401 | } 402 | 403 | /** 404 | * @return mixed 405 | */ 406 | public function getActionLocKey() 407 | { 408 | return $this->actionLocKey; 409 | } 410 | 411 | /** 412 | * @param mixed $actionLocKey 413 | */ 414 | public function setActionLocKey($actionLocKey) 415 | { 416 | $this->actionLocKey = $actionLocKey; 417 | } 418 | 419 | } --------------------------------------------------------------------------------