guigpm/php-fcm

PHP application server for google firebase cloud messaging (FCM)

1.0 2019-03-12 19:01 UTC

This package is auto-updated.

Last update: 2024-11-13 12:16:50 UTC


README

Build Status Coverage Status Latest Stable Version Total Downloads License

A fork of the phpFCM project. See the original at: https://github.com/Paragraph1/php-fcm

PHP application server implementation for Firebase Cloud Messaging.

#Setup The recommended way of installing is using Composer.

command line

composer require guigpm/php-fcm

composer.json

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

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

use paragraph1\phpFCM\Client;
use paragraph1\phpFCM\Message;
use paragraph1\phpFCM\Recipient\Device;
use paragraph1\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 paragraph1\phpFCM\Client;
use paragraph1\phpFCM\Message;
use paragraph1\phpFCM\Recipient\Topic;
use paragraph1\phpFCM\Notification;

require_once 'vendor/autoload.php';


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

$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());