test.php 1.0 KB

12345678910111213141516171819202122232425262728
  1. <?php
  2. require_once '../vendor/autoload.php';
  3. putenv('GOOGLE_APPLICATION_CREDENTIALS=/home/axel/configs/narkampen-firebase-adminsdk-k42j5-d3d0354e37.json');
  4. $client = new Google_Client();
  5. $client->useApplicationDefaultCredentials();
  6. $client->addScope('https://www.googleapis.com/auth/firebase.messaging');
  7. $httpClient = $client->authorize();
  8. $token = "f2lMMUNKR9SOQcVZFm7VUJ:APA91bHnfv3D2yxAPX9lXT81ovuH6gDgga6ZrNXRwAZZE5xa7AcjWzeKAON-7s1oAVM4AwTSgjb-IkmT5NvujjqSib9wFCcwaPX205dh8rSGAj6ltTp670dTkdbVIykefURMoG8EhFQd";
  9. // Your Firebase project ID
  10. $project = "narkampen";
  11. // Creates a notification for subscribers to the debug topic
  12. $message = [
  13. "message" => [
  14. "token" => $token,
  15. "notification" => [
  16. "body" => "This is an FCM notification message!",
  17. "title" => "FCM Message",
  18. ]
  19. ]
  20. ];
  21. // Send the Push Notification - use $response to inspect success or errors
  22. $response = $httpClient->post("https://fcm.googleapis.com/v1/projects/{$project}/messages:send", ['json' => $message]);
  23. var_dump($response);