· 4 years ago · Apr 08, 2021, 10:42 AM
1 $id = $notification["token_mobile"];
2 $message = $notification["text"];
3 $url = 'https://fcm.googleapis.com/fcm/send';
4
5 $fields = array(
6 'registration_ids' => array(
7 $id
8 ),
9 'data' => array(
10 "title" => "PartyFinder",
11 "body" => $message,
12 )
13 );
14 $fields = json_encode($fields);
15
16 $headers = array(
17 'Authorization: key=' . "AAAAaY3Oq3A:APA91bEnDNmiamWaEvRIh6yoShnP2701EfSSvfyL8Q3_Uj_EvIciGe2QHiPYDpg8h7LWHBK2gPHGNMBr_enc5UDwEnUHQ9oBFGmnSVF1YeQy_tkFMeXIHzTtFVq8W8BHKpjYQ7-fe_NO", // to klucz API serwera (lub klucz API starszego serwera)
18 'Content-Type: application/json'
19 );
20
21 $ch = curl_init();
22 curl_setopt($ch, CURLOPT_URL, $url);
23 curl_setopt($ch, CURLOPT_POST, true);
24 curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
25 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
26 curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
27
28 $result = curl_exec($ch);
29 echo $result;
30 curl_close($ch);