Push notifications Library for PHP

Overview

Push notifications Library for PHP

Latest License PHP Test codecov


Supported Protocols

Protocol Supported Driver Options
APNs (Token Based) APNs\Token APNs\Token\Option
APNs (Certificate Based) APNs\Certificate APNs\Certificate\Option
APNs (Binary Provider)
FCM (HTTP v1) FCM\V1 FCM\V1\Option
FCM (Legacy JSON) FCM\Json FCM\Json\Option
FCM (Legacy Plain Text) FCM\PlainText FCM\PlainText\Option
FCM (XMPP)

Installation

composer require sunaoka/push-notifications-php

Basic Usage

For example, in the case of APNs Token Based.

<?php

use Sunaoka\PushNotifications\Drivers\APNs;
use Sunaoka\PushNotifications\Pusher;

$payload = [
    'aps' => [
        'alert' => [
            'title' => 'Game Request',
            'body'  => 'Bob wants to play poker',
        ],
    ],
];

$options = new APNs\Token\Option();
$options->payload = $payload;
$options->authKey = '/path/to/key.p8';
$options->keyId = 'ABCDE12345';
$options->teamId = 'ABCDE12345';
$options->topic = 'com.example.app';

$driver = new APNs\Token($options);

$pusher = new Pusher();
$feedback = $pusher->to('Device token')->send($driver);

$result = $feedback->isSuccess('Device token');
if (! $result) {
    echo $feedback->failure('Device token');
    // BadDeviceToken
}

How to specify options

There are two ways to specify the option.

$options = new APNs\Token\Option();
$options->payload = $payload;
$options->authKey = '/path/to/key.p8';
$options->keyId = 'ABCDE12345';
$options->teamId = 'ABCDE12345';
$options->topic = 'com.example.app';

or

$options = new APNs\Token\Option([
    'payload' => $payload,
    'authKey' => '/path/to/key.p8',
    'keyId'   => 'ABCDE12345',
    'teamId'  => 'ABCDE12345',
    'topic'   => 'com.example.app',
]);

Multicast message

Specify an array of device tokens in Pusher::to(). Then, you can distribute to multiple devices.

$pusher = new Pusher();
$feedback = $pusher->to([
    'Device token 1',
    'Device token 2',
    'Device token 3',
])->send($driver);

How to switch between the production and development environments (only APNs)

This is specified as an argument when creating an instance of Pusher.

// Development environment (default)
$pusher = new Pusher(false);
// Production environment
$pusher = new Pusher(true);

Feedback

The return value of Pusher::send() is a Feedback object.

With the Feedback object, you can determine whether the notification succeeded or failed.

$pusher = new Pusher();
$feedback = $pusher->to('Device token')->send($driver);

$result = $feedback->isSuccess('Device token');
if ($result) {
    echo $feedback->success('Device token');
    // 01234567-0123-0123-0123-01234567890A
} else {
    echo $feedback->failure('Device token');
    // BadDeviceToken
}

HTTP Request Option

You can specify Guzzle Request Options as a driver option.

$options = new APNs\Token\Option();
$options->httpOptions = [
    'connect_timeout' => 3.14
    'timeout'         => 3.14,
    'debug'           => true,
];

More examples

More examples can be found in the examples directory.

You might also like...
This package makes it easy to send web push notifications with Laravel.

Web push notifications channel for Laravel This package makes it easy to send web push notifications with Laravel. Installation You can install the pa

ApnsPHP: Apple Push Notification & Feedback Provider
ApnsPHP: Apple Push Notification & Feedback Provider

ApnsPHP: Apple Push Notification & Feedback Provider A full set of open source PHP classes to interact with the Apple Push Notification service for th

A very lightweight library to handle notifications the smart way.
A very lightweight library to handle notifications the smart way.

NAMSHI | Notificator Notificator is a very simple and lightweight library to handle notifications the smart way. It took inspiration from other librar

:computer: Send notifications to your desktop directly from your PHP script
: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 (

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

Sends notifications via one or more channels (email, SMS, ...).

Notifier Component The Notifier component sends notifications via one or more channels (email, SMS, ...). Resources Documentation Contributing Report

Laravel Security Notifications

This package adds security notifications to warn your users when significant security events occur so that they aren't the next victim of an attacker.

Laravel package to launch toast notifications.
Laravel package to launch toast notifications.

Laravel package to launch toast notifications. This package provides assistance when using toast notifications. Using the iziTOAST package, which allo

Laravel Subscribable Notifications

Laravel Subscribable Notifications This package allows you to subscribe your app Users to your app Notifications and dispatch them without specifying

Releases(1.0.3)
  • 1.0.3(Oct 14, 2021)

  • 1.0.2(Oct 13, 2021)

    Full Changelog: https://github.com/sunaoka/push-notifications-php/compare/1.0.1...1.0.2

    Added

    • Added DriverOption::httpOptions (Guzzle Request Options)

    Fixed

    • Fixed a bug that APNs by using token failed
    Source code(tar.gz)
    Source code(zip)
  • 1.0.1(Oct 13, 2021)

    Full Changelog: https://github.com/sunaoka/push-notifications-php/compare/1.0.0...1.0.1

    Changed

    • No longer need file:// prefix for APNs\Token\Option::authKey
    Source code(tar.gz)
    Source code(zip)
  • 1.0.0(Oct 13, 2021)

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
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
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
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
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
Send push notifications to apple devices (iPhone, iPad, iPod).

Apple Apn Push Send push notifications to apple devices (iPhone, iPad, iPod). Support authenticators: Certificate Json Web Token Supported protocols:

Vitaliy Zhuk 157 Dec 1, 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
Push Notifications using Laravel

laravel-push-notification Push Notifications using Laravel PushNotification::send(['deviceToken1', 'deviceToken2',..], 'Notification Message', 'Action

Webelight Solutions 26 Jul 22, 2022
Laravel package to enable sending push notifications to devices

Laravel Push Notification Package to enable sending push notifications to devices Installation Update your composer.json file to include this package

Davi Nunes 1.2k Sep 27, 2022
WebPush can be used to send notifications to endpoints which server delivers Web Push

WebPush can be used to send notifications to endpoints which server delivers Web Push notifications as described in the Web Push protocol. As it is standardized, you don't have to worry about what server type it relies on.

null 1.5k Jan 7, 2023