kedniko / firebase-cloud-messaging-http-v1-php
Firebase cloud messaging http v1 php
Installs: 2 301
Dependents: 0
Suggesters: 0
Security: 0
Stars: 11
Watchers: 2
Forks: 5
Open Issues: 1
Requires
- php: ^8.2.0
- firebase/php-jwt: ^6.10
- guzzlehttp/guzzle: ^7.8
Requires (Dev)
- laravel/pint: ^1.13.1
- pestphp/pest: ^2.19.2
- phpstan/phpstan: ^1.10.34
- rector/rector: ^0.18.3
- symfony/var-dumper: ^6.3.4
README
Firebase Cloud Messaging Http v1 for PHP
Installation
composer require kedniko/firebase-cloud-messaging-http-v1-php
Send a message
<?php $authKeyContent = json_decode(file_get_contents(__DIR__ . '/appname-30xfgre76.json'), true); $projectID = 'my-project-1'; $body = [ 'message' => [ 'token' => '<token:string>', 'notification' => [ 'title' => 'Breaking News', 'body' => 'New news story available.', ], 'data' => [ 'story_id' => 'story_12345', ], ], ]; $bearerToken = FCM::getBearerToken($authKeyContent); FCM::send($bearerToken, $projectID, $body);
Send multiple messages
<?php $authKeyContent = json_decode(file_get_contents(__DIR__ . '/appname-30xfgre76.json'), true); $projectID = 'my-project-1'; $tokens = [ '<token1:string>', '<token2:string>', '<token3:string>', ]; $bearerToken = FCM::getBearerToken($authKeyContent); foreach ($tokens as $token) { $body = [ 'message' => [ 'token' => $token, 'notification' => [ 'title' => 'Breaking News', 'body' => 'New news story available.', ], 'data' => [ 'story_id' => 'story_12345', ], ], ]; FCM::send($bearerToken, $projectID, $body); }
Subscribe to topic
<?php $authKeyContent = json_decode(file_get_contents(__DIR__ . '/appname-30xfgre76.json'), true); $tokens = [ '<token1:string>', '<token2:string>', '<token3:string>', ]; $bearerToken = FCM::getBearerToken($authKeyContent); FCM::subscribeToTopic($bearerToken, 'my-topic-1', $tokens);
Unsubscribe from topic
<?php $authKeyContent = json_decode(file_get_contents(__DIR__ . '/appname-30xfgre76.json'), true); $tokens = [ '<token1:string>', '<token2:string>', '<token3:string>', ]; $bearerToken = FCM::getBearerToken($authKeyContent); FCM::unsubscribeFromTopic($bearerToken, 'my-topic-1', $tokens);