Advertisement
Zgragselus

Copilot - fcm

Mar 1st, 2024 (edited)
590
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.82 KB | None | 0 0
  1. <?php
  2. require 'vendor/autoload.php';
  3.  
  4. use Google\Cloud\Core\ServiceBuilder;
  5.  
  6. // Authenticate with Google Cloud
  7. $cloud = new ServiceBuilder([
  8.     'keyFilePath' => 'path-to-your-service-account-json-file',
  9.     'projectId' => 'your-project-id'
  10. ]);
  11.  
  12. // Get an instance of the Firebase Cloud Messaging client
  13. $messaging = $cloud->messaging();
  14.  
  15. // Create a message
  16. $message = [
  17.     'notification' => [
  18.         'title' => 'Notification title',
  19.         'body' => 'Notification body'
  20.     ],
  21.     'android' => [
  22.         'ttl' => '3600s',
  23.         'priority' => 'normal',
  24.         'notification' => [
  25.             'icon' => 'stock_ticker_update',
  26.             'color' => '#f45342'
  27.         ]
  28.     ],
  29.     'token' => 'device-registration-token'
  30. ];
  31.  
  32. // Send the message
  33. $response = $messaging->send($message);
  34.  
  35. echo $response;
  36. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement