@@ -39,8 +39,8 @@ |
||
39 | 39 | $firebaseService = $this->getFirebaseNotificationService(); |
40 | 40 | |
41 | 41 | $result = [ |
42 | - "status" => 200, |
|
43 | - "response" => "OK" |
|
42 | + "status" => 200, |
|
43 | + "response" => "OK" |
|
44 | 44 | ]; |
45 | 45 | |
46 | 46 | $this->assertEquals(json_decode("OK", true), $firebaseService->parseResult($result)); |
@@ -21,17 +21,17 @@ discard block |
||
21 | 21 | */ |
22 | 22 | class FirebaseNotificationService |
23 | 23 | { |
24 | - protected $server_key; |
|
24 | + protected $server_key; |
|
25 | 25 | |
26 | - protected $content_available; |
|
26 | + protected $content_available; |
|
27 | 27 | |
28 | - protected $time_to_live; |
|
28 | + protected $time_to_live; |
|
29 | 29 | |
30 | - protected $message; |
|
30 | + protected $message; |
|
31 | 31 | |
32 | - const FCM_URL = "https://fcm.googleapis.com/fcm/send"; |
|
32 | + const FCM_URL = "https://fcm.googleapis.com/fcm/send"; |
|
33 | 33 | |
34 | - public function __construct($server_key, $content_available = true, $time_to_live = 30) |
|
34 | + public function __construct($server_key, $content_available = true, $time_to_live = 30) |
|
35 | 35 | { |
36 | 36 | $this->server_key = $server_key; |
37 | 37 | $this->content_available = $content_available; |
@@ -39,66 +39,66 @@ discard block |
||
39 | 39 | } |
40 | 40 | |
41 | 41 | public function createMessage($message) |
42 | - { |
|
43 | - if (!array_key_exists("to", $message)) { |
|
44 | - return false; |
|
42 | + { |
|
43 | + if (!array_key_exists("to", $message)) { |
|
44 | + return false; |
|
45 | 45 | } |
46 | 46 | $this->message["to"] = $message["to"]; |
47 | 47 | |
48 | 48 | |
49 | - if (array_key_exists("title", $message)) { |
|
50 | - $this->message["notification"]["title"] = $message["title"]; |
|
51 | - } |
|
52 | - if (array_key_exists("body", $message)) { |
|
53 | - $this->message["notification"]["body"] = $message["body"]; |
|
54 | - } |
|
55 | - if (array_key_exists("badge", $message)) { |
|
56 | - $this->message["notification"]["badge"] = $message["badge"]; |
|
57 | - } |
|
58 | - if (array_key_exists("sound", $message)) { |
|
59 | - $this->message["notification"]["sound"] = $message["sound"]; |
|
60 | - } |
|
61 | - if (array_key_exists("data", $message)) { |
|
62 | - $this->message["data"] = $message["data"]; |
|
63 | - } |
|
64 | - |
|
65 | - $this->message["content_available"] = true; |
|
66 | - |
|
67 | - $this->message["time_to_live"] = 30; |
|
68 | - |
|
69 | - return true; |
|
70 | - } |
|
71 | - |
|
72 | - public function sendNotification() |
|
73 | - { |
|
74 | - $content = json_encode($this->message); |
|
75 | - |
|
76 | - $curl = curl_init(self::FCM_URL); |
|
77 | - curl_setopt($curl, CURLOPT_HEADER, false); |
|
78 | - curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
|
79 | - curl_setopt($curl, CURLOPT_HTTPHEADER, array( |
|
80 | - "Content-type: application/json", |
|
81 | - "Authorization: key=".$this->server_key |
|
82 | - ) |
|
83 | - ); |
|
49 | + if (array_key_exists("title", $message)) { |
|
50 | + $this->message["notification"]["title"] = $message["title"]; |
|
51 | + } |
|
52 | + if (array_key_exists("body", $message)) { |
|
53 | + $this->message["notification"]["body"] = $message["body"]; |
|
54 | + } |
|
55 | + if (array_key_exists("badge", $message)) { |
|
56 | + $this->message["notification"]["badge"] = $message["badge"]; |
|
57 | + } |
|
58 | + if (array_key_exists("sound", $message)) { |
|
59 | + $this->message["notification"]["sound"] = $message["sound"]; |
|
60 | + } |
|
61 | + if (array_key_exists("data", $message)) { |
|
62 | + $this->message["data"] = $message["data"]; |
|
63 | + } |
|
64 | + |
|
65 | + $this->message["content_available"] = true; |
|
66 | + |
|
67 | + $this->message["time_to_live"] = 30; |
|
68 | + |
|
69 | + return true; |
|
70 | + } |
|
71 | + |
|
72 | + public function sendNotification() |
|
73 | + { |
|
74 | + $content = json_encode($this->message); |
|
75 | + |
|
76 | + $curl = curl_init(self::FCM_URL); |
|
77 | + curl_setopt($curl, CURLOPT_HEADER, false); |
|
78 | + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
|
79 | + curl_setopt($curl, CURLOPT_HTTPHEADER, array( |
|
80 | + "Content-type: application/json", |
|
81 | + "Authorization: key=".$this->server_key |
|
82 | + ) |
|
83 | + ); |
|
84 | 84 | $curlConf["header"] = curl_getinfo($curl, CURLOPT_HEADER); |
85 | 85 | |
86 | - curl_setopt($curl, CURLOPT_POST, true); |
|
87 | - curl_setopt($curl, CURLOPT_POSTFIELDS, $content); |
|
88 | - // @codeCoverageIgnoreStart |
|
89 | - $json_response = curl_exec($curl); |
|
90 | - $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); |
|
86 | + curl_setopt($curl, CURLOPT_POST, true); |
|
87 | + curl_setopt($curl, CURLOPT_POSTFIELDS, $content); |
|
88 | + // @codeCoverageIgnoreStart |
|
89 | + $json_response = curl_exec($curl); |
|
90 | + $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); |
|
91 | 91 | // @codeCoverageIgnoreEnd |
92 | 92 | curl_close($curl); |
93 | 93 | |
94 | 94 | return [ |
95 | - 'curlConf' => $curlConf, |
|
95 | + 'curlConf' => $curlConf, |
|
96 | 96 | 'status' => $status, |
97 | 97 | 'response' => $json_response |
98 | 98 | ]; |
99 | - } |
|
99 | + } |
|
100 | 100 | |
101 | - public function parseResult(array $result) |
|
101 | + public function parseResult(array $result) |
|
102 | 102 | { |
103 | 103 | if ($result["status"] == 200) { |
104 | 104 | return json_decode($result["response"], true); |