8
8
*/
9
9
class Fcm
10
10
{
11
+ const ENDPOINT = 'https://fcm.googleapis.com/fcm/send ' ;
12
+
11
13
protected $ recipients ;
12
14
protected $ topic ;
13
15
protected $ data ;
14
16
protected $ notification ;
15
17
protected $ timeToLive ;
16
18
protected $ priority ;
17
19
20
+ protected $ serverKey ;
21
+
22
+ public function __construct ($ serverKey )
23
+ {
24
+ $ this ->serverKey = $ serverKey ;
25
+ }
26
+
18
27
public function to (array $ recipients )
19
28
{
20
29
$ this ->recipients = $ recipients ;
@@ -66,8 +75,6 @@ public function timeToLive(int $timeToLive)
66
75
67
76
public function send ()
68
77
{
69
- $ fcmEndpoint = 'https://fcm.googleapis.com/fcm/send ' ;
70
-
71
78
$ payloads = [
72
79
'content_available ' => true ,
73
80
'priority ' => $ this ->priority ?? 'high ' ,
@@ -85,15 +92,13 @@ public function send()
85
92
$ payloads ['time_to_live ' ] = (int ) $ this ->timeToLive ;
86
93
}
87
94
88
- $ serverKey = config ('laravel-fcm.server_key ' );
89
-
90
95
$ headers = [
91
- 'Authorization: key= ' . $ serverKey ,
92
- 'Content-Type: application/json '
96
+ 'Authorization: key= ' . $ this -> serverKey ,
97
+ 'Content-Type: application/json ' ,
93
98
];
94
99
95
100
$ ch = curl_init ();
96
- curl_setopt ($ ch , CURLOPT_URL , $ fcmEndpoint );
101
+ curl_setopt ($ ch , CURLOPT_URL , self :: ENDPOINT );
97
102
curl_setopt ($ ch , CURLOPT_POST , true );
98
103
curl_setopt ($ ch , CURLOPT_HTTPHEADER , $ headers );
99
104
curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , true );
0 commit comments