Implementation of Firebase Cloud Messaging HTTP v1 API in PHP

Overview

php-fcm-v1

Build Status codecov Latest Stable Version Total Downloads License

php-fcm-v1 is an PHP implementation of FCM HTTP v1 API

What is different compared to others FCM Libraries?

Most of other libraries are implementation of FCM's Legacy HTTP Server Protocol. It requires a server key from Firebase console (which means you have to copy and paste in your code) (Docs)

HTTP v1 API, in contrast, leverages OAuth2 security model. You need to get an access token (which is valid for about an hour) in order to request sending notification with service account's private key file. Although (See the blog post about HTTP v1 API)

References

How to use

  • Install the library with composer

    composer require lkaybob/php-fcm-v1
    

  • Import the library with autoload.php

    <?php
    require_once __DIR__ . '/vendor/autoload.php';
    
    use phpFCMv1\Client;
    use phpFCMv1\Notification;
    use phpFCMv1\Recipient;
  • Create Necessary class instances, Client, Recipient, Notification/Data

    // Client instance should be created with path to service account key file
    $client = new Client('service_account.json');
    $recipient = new Recipient();
    // Either Notification or Data (or both) instance should be created
    $notification = new Notification();
  • Setup each instances with necessary information

    // Recipient could accept individual device token,
    // the name of topic, and conditional statement
    $recipient -> setSingleREcipient('DEVICE_TOKEN');
    // Setup Notificaition title and body
    $notification -> setNotification('NOTIFICATION_TITLE', 'NOTIFICATION_BODY');
    // Build FCM request payload
    $client -> build($recipient, $notification);
  • Fire in the FCM Server!

    $result = $client -> fire();
    // You can check the result
    // If successful, true will be returned
    // If not, error message will be returned
    echo $result;

Further Example

  • Full Simple Example

    <?php
    require_once __DIR__ . '/vendor/autoload.php';
    
    use phpFCMv1\Client;
    use phpFCMv1\Notification;
    use phpFCMv1\Recipient;
    
    $client = new Client('service_account.json');
    $recipient = new Recipient();
    $notification = new Notification();
    
    $recipient -> setSingleRecipient('DEVICE_TOKEN');
    $notification -> setNotification('NOTIFICATION_TITILE', 'NOTIFICATION_BODY');
    $client -> build($recipient, $notification);
    $client -> fire();
  • Using with PRIOIRTY option (for both Android & iOS)

    <?php
    require_once __DIR__ . '/vendor/autoload.php';
    
    use phpFCMv1\Client;
    use phpFCMv1\Config;
    use phpFCMv1\Notification;
    use phpFCMv1\Recipient;
    
    $client = new Client('service_account.json');
    $recipient = new Recipient();
    $notification = new Notification();
    $config = new Config();
    
    $recipient -> setSingleRecipient('DEVICE_TOKEN');
    $notification -> setNotification('NOTIFICATION_TITLE', 'NOTIFICATION_BODY');
    $config -> setPriority(Config::PRIORITY_HIGH);
    $client -> build($recipient, $notification, null, $config);
    $result = $client -> fire();
  • For independent platform (either Android or iOS)

    // Option Instance for Android
    // Use phpFCMv1\AndroidConfig Class
    $androidConfig = new Config\AndroidConfig();
    $androidConfig -> setPriority(Config\AndroidConfig::PRIORITY_HIGH);
    $client -> build($recipient, $notification, null, $androidConfig);
    
    // Option Instance for iOS (which is APNs header)
    // Use phpFCMv1\APNsCOnfig Class
    $apnsConfig = new APNsConfig();
    $apnsConfig -> setPriority(APNsConfig::PRIORITY_HIGH);
    $client -> build($recipient, $notification, null, $apnsConfig);
    

Future Works

  • Implement simultaneous send (Currently supports single recipient or topic one at a time)
  • Setup Read the Docs
  • Add CI Test
  • Add CodeCov Badge
Comments
  • add parameter to pass data array in the payload

    add parameter to pass data array in the payload

    add the possibility to add the data array to the payload as explained in the official documentation

    https://firebase.google.com/docs/cloud-messaging/migrate-v1#node.js

    opened by rich1990 1
  • Add PHP@5.6 Support

    Add [email protected] Support

    • Removed class constant visibility syntax, which is availaible form [email protected]. See the link
    • Updated composer.json & .travis.yml. Deleted composer.lock
    opened by lkaybob 1
  • Reconfigure test environment variables

    Reconfigure test environment variables

    Impacted by Codecov security issue

    • [x] Turn off Travis CI daily cron job
    • [x] Revoke Travis CI's environment variables
    • [x] Revoke existing test credential for FCM (on Google cloud) & create new test credential
    • [ ] (TBA) Extra actions recommended by Codecov
      • [ ] Add checksum validation (Checksum can be found here)
    • [ ] Put daily cron job back

    Ref: https://about.codecov.io/security-update/

    priority/high 
    opened by lkaybob 0
  • Setup Read the Docs

    Setup Read the Docs

    For better usage, two things could be useful.

    • [ ] Read the Docs on the package ~- [ ] Add examples on Laravel (IF it is possible)~
      • ~Maybe with queue?~
    opened by lkaybob 0
  • Implement manual configuration without JSON file

    Implement manual configuration without JSON file

    There might be a need not to hold JSON file as it is. Some users could holde credential information in a secret (For example, Vault by HashiCorp)

    Spliting credentials configuration would be able to adapt those cases.

    opened by lkaybob 0
Releases(v1.0.2)
Send Firebase push notifications with Laravel php framework.

FCM Notification Channel for Laravel Send Firebase push notifications with Laravel php framework. Installation You can install this package via compos

Ankur Kumar 23 Oct 31, 2022
Larafirebase is a package thats offers you to send push notifications or custom messages via Firebase in Laravel.

Introduction Larafirebase is a package thats offers you to send push notifications or custom messages via Firebase in Laravel. Firebase Cloud Messagin

Kutia Software Company 264 Jan 7, 2023
Standalone PHP library for easy devices notifications push.

NotificationPusher Standalone PHP library for easy devices message notifications push. Feel free to contribute! Thanks. Contributors Cédric Dugat (Aut

Cédric Dugat 1.2k Jan 3, 2023
:computer: Send notifications to your desktop directly from your PHP script

About JoliNotif JoliNotif is a cross-platform PHP library to display desktop notifications. It works on Linux, Windows or MacOS. Requires PHP >= 7.2 (

JoliCode 1.2k Dec 29, 2022
Takes care of Apple push notifications (APNS) in your PHP projects.

Notificato Notificato takes care of push notifications in your PHP projects. Italian: notificato è: participio passato English: notified Why use Notif

Mathijs Kadijk 223 Sep 28, 2022
A PHP Library to easily send push notifications with the Pushwoosh REST Web Services.

php-pushwoosh A PHP Library to easily send push notifications with the Pushwoosh REST Web Services. First sample, creating a Pushwoosh message // Crea

gomoob 63 Sep 28, 2022
Notifications in PHP (notify-send, growl, etc) like that.

#Nod Notifications in PHP (notify-send, growl, etc) like that. ##Examples Letting Nod figure out the best Adapter to use (not recommend ATM, only work

Filipe Dobreira 51 Mar 26, 2019
Bugsnag notifier for the Laravel PHP framework. Monitor and report Laravel errors.

The Bugsnag Notifier for Laravel gives you instant notification of errors and exceptions in your Laravel PHP applications. We support both Laravel and Lumen. Learn more about Laravel error reporting from Bugsnag.

Bugsnag 816 Dec 15, 2022
Push notifications Library for PHP

Push notifications Library for PHP Supported Protocols Protocol Supported Driver Options APNs (Token Based) ✓ APNs\Token APNs\Token\Option APNs (Certi

Norifumi SUNAOKA 3 Dec 14, 2022
Server-side library for working with Expo using PHP

expo-server-sdk-php Server-side library for working with Expo using PHP. If you have any problems with the code in this repository, feel free to open

Cedric Twillie 34 Dec 30, 2022
Takes care of Apple push notifications (APNS) in your PHP projects.

Notificato Notificato takes care of push notifications in your PHP projects. Italian: notificato è: participio passato English: notified Why use Notif

Mathijs Kadijk 223 Sep 28, 2022
An SMS notification channel for the PHP framework Laravel.

Laravel SMS notification channel An SMS notification channel for the PHP framework Laravel. Supported SMS gateways: 46elks Cellsynt Telenor SMS Pro Tw

Andreas 2 Jan 22, 2022
uptime-monitor-app is a powerful, easy to configure uptime monitor written in PHP 7

A PHP application to monitor uptime and ssl certificates uptime-monitor-app is a powerful, easy to configure uptime monitor written in PHP 7. It will

Spatie 214 Dec 11, 2022
Standalone PHP library for easy devices notifications push.

NotificationPusher Standalone PHP library for easy devices message notifications push. Feel free to contribute! Thanks. Contributors Cédric Dugat (Aut

Cédric Dugat 1.2k Jan 3, 2023
Laravel-FCM is an easy to use package working with both Laravel and Lumen for sending push notification with Firebase Cloud Messaging (FCM).

Laravel-FCM Introduction Laravel-FCM is an easy to use package working with both Laravel and Lumen for sending push notification with Firebase Cloud M

Rahul Thapa 2 Oct 16, 2022
Laravel FCM (Firebase Cloud Messaging) Notification Channel

Laravel FCM Notification Laravel FCM (Firebase Cloud Messaging) Notification Channel Use this package to send push notifications via Laravel to Fireba

Vishal Dudhatra 3 Jul 3, 2022
YCOM Impersonate. Login as selected YCOM user 🧙‍♂️in frontend.

YCOM Impersonate Login as selected YCOM user in frontend. Features: Backend users with admin rights or YCOM[] rights, can be automatically logged in v

Friends Of REDAXO 17 Sep 12, 2022
PHP Client and Router Library for Autobahn and WAMP (Web Application Messaging Protocol) for Real-Time Application Messaging

Thruway is an open source client and router implementation of WAMP (Web Application Messaging Protocol), for PHP. Thruway uses an event-driven, non-blocking I/O model (reactphp), perfect for modern real-time applications.

Voryx 662 Jan 3, 2023
A working Firebase http client

PHP library access Firebase RESTful API Installation $ composer require jaredchu/jc-firebase-php Usage Generate a private key in JSON format. Check Fi

Jared Chu 14 Jul 10, 2022
Thruway - an open source client and router implementation of WAMP (Web Application Messaging Protocol), for PHP.

PHP Client and Router Library for Autobahn and WAMP (Web Application Messaging Protocol) for Real-Time Application Messaging

Voryx 661 Nov 14, 2022