Skip to content

simPRO-Software/php-fcm

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

90 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

phpFCM

Build Status Coverage Status Latest Stable Version Total Downloads License

PHP application server implementation for Firebase Cloud Messaging.

#Setup The recommended way of installing is using Composer.

command line

composer require php-fcm/php-fcm

composer.json

"require": {
    "php-fcm/php-fcm": "*"
}

#Send to Device also see https://firebase.google.com/docs/cloud-messaging/downstream

use FCM\phpFCM\Client;
use FCM\phpFCM\Message;
use FCM\phpFCM\Recipient\Device;
use FCM\phpFCM\Notification;

require_once 'vendor/autoload.php';

$apiKey = 'YOUR SERVER KEY';
$client = new Client();
$client->setApiKey($apiKey);
$client->injectHttpClient(new \GuzzleHttp\Client());

$note = new Notification('test title', 'testing body');
$note->setIcon('notification_icon_resource_name')
    ->setColor('#ffffff')
    ->setBadge(1);

$message = new Message();
$message->addRecipient(new Device('your-device-token'));
$message->setNotification($note)
    ->setData(array('someId' => 111));

$response = $client->send($message);
var_dump($response->getStatusCode());

#Send to topic also see https://firebase.google.com/docs/cloud-messaging/topic-messaging

use FCM\phpFCM\Client;
use FCM\phpFCM\Message;
use FCM\phpFCM\Recipient\Topic;
use FCM\phpFCM\Notification;

require_once 'vendor/autoload.php';


$apiKey = 'YOUR SERVER KEY';
$client = new Client();
$client->setApiKey($apiKey);
$client->injectHttpClient(new \GuzzleHttp\Client());

$message = new Message();
$message->addRecipient(new Topic('your-topic'));
//select devices where has 'your-topic1' && 'your-topic2' topics
$message->addRecipient(new Topic(['your-topic1', 'your-topic2']));
$message->setNotification(new Notification('test title', 'testing body'))
    ->setData(array('someId' => 111));

$response = $client->send($message);
var_dump($response->getStatusCode());

About

PHP Firebase Messaging

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%