1 | <?php |
||
5 | class FcmMessage |
||
6 | { |
||
7 | const PRIORITY_NORMAL = 'normal'; |
||
8 | |||
9 | const PRIORITY_HIGH = 'high'; |
||
10 | |||
11 | /** |
||
12 | * @var string |
||
13 | */ |
||
14 | protected $fcmKey; |
||
15 | |||
16 | /** |
||
17 | * @var string |
||
18 | */ |
||
19 | protected $to; |
||
20 | |||
21 | /** |
||
22 | * @var array |
||
23 | */ |
||
24 | protected $registrationIds; |
||
25 | |||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $condition; |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $collapseKey; |
||
35 | |||
36 | /** |
||
37 | * @var bool |
||
38 | */ |
||
39 | protected $contentAvailable; |
||
40 | |||
41 | /** |
||
42 | * @var bool |
||
43 | */ |
||
44 | protected $mutableContent; |
||
45 | |||
46 | /** |
||
47 | * @var string |
||
48 | */ |
||
49 | protected $priority; |
||
50 | |||
51 | /** |
||
52 | * @var int |
||
53 | */ |
||
54 | protected $timeToLive = 2419200; |
||
55 | |||
56 | /** |
||
57 | * @var bool |
||
58 | */ |
||
59 | protected $dryRun = false; |
||
60 | |||
61 | /** |
||
62 | * @var object |
||
63 | */ |
||
64 | protected $data; |
||
65 | |||
66 | /** |
||
67 | * @var FcmNotification |
||
68 | */ |
||
69 | protected $notification; |
||
70 | |||
71 | public static function create() |
||
75 | |||
76 | /** |
||
77 | * @return string |
||
78 | */ |
||
79 | public function getFcmKey() |
||
83 | |||
84 | /** |
||
85 | * This method can be used to override the default FCM key used in the config/broadcasting.php. |
||
86 | * |
||
87 | * @param string $fcmKey |
||
88 | * @return $this |
||
89 | */ |
||
90 | public function setFcmKey($fcmKey) |
||
96 | |||
97 | /** |
||
98 | * @return string |
||
99 | */ |
||
100 | public function getTo() |
||
104 | |||
105 | /** |
||
106 | * This parameter specifies the recipient of a message. |
||
107 | * The value can be a device's registration token, a device group's notification key, or a single topic (prefixed with /topics/). To send to multiple |
||
108 | * topics, use the condition parameter. |
||
109 | * |
||
110 | * @param string $to |
||
111 | * @return $this |
||
112 | */ |
||
113 | public function setTo($to) |
||
119 | |||
120 | /** |
||
121 | * @return array |
||
122 | */ |
||
123 | public function getRegistrationIds() |
||
127 | |||
128 | /** |
||
129 | * This parameter specifies the recipient of a multicast message, a message sent to more than one registration token. |
||
130 | * The value should be an array of registration tokens to which to send the multicast message. The array must contain at least 1 and at most 1000 |
||
131 | * registration tokens. To send a message to a single device, use the to parameter. |
||
132 | * Multicast messages are only allowed using the HTTP JSON format. |
||
133 | * |
||
134 | * @param array $registrationIds |
||
135 | * @return $this |
||
136 | */ |
||
137 | public function setRegistrationIds($registrationIds) |
||
143 | |||
144 | /** |
||
145 | * @return string |
||
146 | */ |
||
147 | public function getCondition() |
||
151 | |||
152 | /** |
||
153 | * [Optional] This parameter specifies a logical expression of conditions that determine the message target. |
||
154 | * Supported condition: Topic, formatted as "'yourTopic' in topics". This value is case-insensitive. |
||
155 | * Supported operators: &&, ||. Maximum two operators per topic message supported. |
||
156 | * |
||
157 | * @param string $condition |
||
158 | * @return $this |
||
159 | */ |
||
160 | public function setCondition($condition) |
||
166 | |||
167 | /** |
||
168 | * @return string |
||
169 | */ |
||
170 | public function getCollapseKey() |
||
174 | |||
175 | /** |
||
176 | * [Optional] This parameter identifies a group of messages (e.g., with collapse_key: "Updates Available") that can be collapsed, so that only the last |
||
177 | * message gets sent when delivery can be resumed. This is intended to avoid sending too many of the same messages when the device comes back online or |
||
178 | * becomes active. |
||
179 | * Note that there is no guarantee of the order in which messages get sent. |
||
180 | * Note: A maximum of 4 different collapse keys is allowed at any given time. This means a FCM connection server can simultaneously store 4 different |
||
181 | * send-to-sync messages per client app. If you exceed this number, there is no guarantee which 4 collapse keys the FCM connection server will keep. |
||
182 | * |
||
183 | * @param string $collapseKey |
||
184 | * @return $this |
||
185 | */ |
||
186 | public function setCollapseKey($collapseKey) |
||
192 | |||
193 | /** |
||
194 | * @return bool |
||
195 | */ |
||
196 | public function isContentAvailable() |
||
200 | |||
201 | /** |
||
202 | * [Optional] On iOS, use this field to represent content-available in the APNs payload. When a notification or message is sent and this is set to true, an |
||
203 | * inactive client app is awoken. On Android, data messages wake the app by default. On Chrome, currently not supported. |
||
204 | * |
||
205 | * @param bool $contentAvailable |
||
206 | * @return $this |
||
207 | */ |
||
208 | public function setContentAvailable($contentAvailable) |
||
214 | |||
215 | /** |
||
216 | * @return bool |
||
217 | */ |
||
218 | public function isMutableContent() |
||
222 | |||
223 | /** |
||
224 | * [Optional] Currently for iOS 10+ devices only. On iOS, use this field to represent mutable-content in the APNS payload. When a notification is sent and |
||
225 | * this is set to true, the content of the notification can be modified before it is displayed, using a Notification Service app extension. This parameter |
||
226 | * will be ignored for Android and web. |
||
227 | * |
||
228 | * @param bool $mutableContent |
||
229 | * @return $this |
||
230 | */ |
||
231 | public function setMutableContent($mutableContent) |
||
237 | |||
238 | /** |
||
239 | * @return string |
||
240 | */ |
||
241 | public function getPriority() |
||
245 | |||
246 | /** |
||
247 | * [Optional] Sets the priority of the message. Valid values are "normal" and "high." On iOS, these correspond to APNs priorities 5 and 10. |
||
248 | * By default, notification messages are sent with high priority, and data messages are sent with normal priority. Normal priority optimizes the client |
||
249 | * app's battery consumption and should be used unless immediate delivery is required. For messages with normal priority, the app may receive the message |
||
250 | * with unspecified delay. |
||
251 | * When a message is sent with high priority, it is sent immediately, and the app can wake a sleeping device and open a network connection to your server. |
||
252 | * |
||
253 | * @param string $priority |
||
254 | * @return $this |
||
255 | */ |
||
256 | public function setPriority($priority) |
||
262 | |||
263 | /** |
||
264 | * @return int |
||
265 | */ |
||
266 | public function getTimeToLive() |
||
270 | |||
271 | /** |
||
272 | * This parameter specifies how long (in seconds) the message should be kept in FCM storage if the device is offline. The maximum time to live |
||
273 | * supported is 4 weeks, and the default value is 4 weeks. |
||
274 | * |
||
275 | * @param int $timeToLive |
||
276 | * @return $this |
||
277 | */ |
||
278 | public function setTimeToLive($timeToLive) |
||
284 | |||
285 | /** |
||
286 | * @return bool |
||
287 | */ |
||
288 | public function isDryRun() |
||
292 | |||
293 | /** |
||
294 | * This parameter, when set to true, allows developers to test a request without actually sending a message. |
||
295 | * |
||
296 | * @param bool $dryRun |
||
297 | * @return $this |
||
298 | */ |
||
299 | public function setDryRun($dryRun) |
||
305 | |||
306 | /** |
||
307 | * @return object |
||
308 | */ |
||
309 | public function getData() |
||
313 | |||
314 | /** |
||
315 | * [Optional] This parameter specifies the custom key-value pairs of the message's payload. |
||
316 | * For example, with data:{"score":"3x1"}: |
||
317 | * On iOS, if the message is sent via APNS, it represents the custom data fields. If it is sent via FCM connection server, it would be represented as key |
||
318 | * value dictionary in AppDelegate application:didReceiveRemoteNotification:. |
||
319 | * On Android, this would result in an intent extra named score with the string value 3x1. |
||
320 | * The key should not be a reserved word ("from" or any word starting with "google" or "gcm"). Do not use any of the words defined in this table (such as |
||
321 | * collapse_key). |
||
322 | * Values in string types are recommended. You have to convert values in objects or other non-string data types (e.g., integers or booleans) to string. |
||
323 | * |
||
324 | * @param object $data |
||
325 | * @return $this |
||
326 | */ |
||
327 | public function setData($data) |
||
333 | |||
334 | /** |
||
335 | * @return FcmNotification |
||
336 | */ |
||
337 | public function getNotification() |
||
341 | |||
342 | /** |
||
343 | * [Optional] This parameter specifies the predefined, user-visible key-value pairs of the notification payload. |
||
344 | * |
||
345 | * @param FcmNotification $notification |
||
346 | * @return $this |
||
347 | */ |
||
348 | public function setNotification($notification) |
||
354 | |||
355 | /** |
||
356 | * @return string |
||
357 | */ |
||
358 | public function toJson() |
||
362 | |||
363 | /** |
||
364 | * @return array |
||
365 | */ |
||
366 | public function toArray() |
||
387 | } |
||
388 |