Firebase cloud messaging php

PHP-FCM Documentation¶

PHP-FCM is a PHP HTTP client that makes it easy to send push notifications, manage groups of devices and message topics using Google Firebase Cloud Messaging.

 // Load composer require 'vendor/autoload.php'; // Instantiate the client with the project api_token and sender_id. $client = new \Fcm\FcmClient($apiToken, $senderId); // Instantiate the push notification request object. $notification = new \Fcm\Push\Notification(); // Enhance the notification object with our custom options. $notification ->addRecipient($deviceId) ->setTitle('Hello from php-fcm!') ->setBody('Notification body') ->setColor('#20F037') ->setSound("default") ->setIcon("myIcon.png") ->addData('key', 'value'); // custom sound and custom icon must be in app package // - custom sound file must be in /res/raw/ // - custom icon file must be in drawable resource, if not set, FCM displays launcher icon in app manifest // Send the notification to the Firebase servers for further handling. $client->send($notification); 

Before installing, read the Overview for more information about this project. Read the Quickstart for installation and using the project.

  • Overview
    • Requirements
    • Running the tests
    • License
    • Installing this package
    • Configuring a Firebase account
    • Configuring the project
    • Android Integration
    • iOS Integration
    • Device Info
    • Quirks
    • Notification message to deviceIDs
    • Notification message
    • Notification sending options
    • Notification options
    • Notification DATA options
    • Data Only message
    • Creating a device group
    • Adding devices to a group
    • Removing devices from a group
    • Subscribing to a topic
    • Unsubscribing from a topic
    • Options
    • Setting on instantiation
    • Setting after instantiation
    • http_errors option
    • Creating a new release
    • Automated tests

    © Copyright 2020, Edwin Hoksberg Revision 1971b3d3 .

    Versions latest stable Downloads pdf html epub On Read the Docs Project Home Builds Free document hosting provided by Read the Docs.

    Источник

    Saved searches

    Use saved searches to filter your results more quickly

    You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

    PHP API for Firebase Cloud Messaging from Google

    License

    sngrl/php-firebase-cloud-messaging

    This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

    Name already in use

    A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

    Sign In Required

    Please sign in to use Codespaces.

    Launching GitHub Desktop

    If nothing happens, download GitHub Desktop and try again.

    Launching GitHub Desktop

    If nothing happens, download GitHub Desktop and try again.

    Launching Xcode

    If nothing happens, download Xcode and try again.

    Launching Visual Studio Code

    Your codespace will open once ready.

    There was a problem preparing your codespace, please try again.

    Latest commit

    Git stats

    Files

    Failed to load latest commit information.

    README.md

    PHP Firebase Cloud Messaging

    PHP API for Firebase Cloud Messaging from Google.

    Currently this app server library only supports sending Messages/Notifications via HTTP.

    #Setup Install via Composer:

    composer require sngrl/php-firebase-cloud-messaging 

    Or add this to your composer.json and run «composer update»:

    use sngrl\PhpFirebaseCloudMessaging\Client; use sngrl\PhpFirebaseCloudMessaging\Message; use sngrl\PhpFirebaseCloudMessaging\Recipient\Device; use sngrl\PhpFirebaseCloudMessaging\Notification; $server_key = '_YOUR_SERVER_KEY_'; $client = new Client(); $client->setApiKey($server_key); $client->injectGuzzleHttpClient(new \GuzzleHttp\Client()); $message = new Message(); $message->setPriority('high'); $message->addRecipient(new Device('_YOUR_DEVICE_TOKEN_')); $message ->setNotification(new Notification('some title', 'some body')) ->setData(['key' => 'value']) ; $response = $client->send($message); var_dump($response->getStatusCode()); var_dump($response->getBody()->getContents()); 

    #Send message to multiple Devices

    . $message = new Message(); $message->setPriority('high'); $message->addRecipient(new Device('_YOUR_DEVICE_TOKEN_')); $message->addRecipient(new Device('_YOUR_DEVICE_TOKEN_2_')); $message->addRecipient(new Device('_YOUR_DEVICE_TOKEN_3_')); $message ->setNotification(new Notification('some title', 'some body')) ->setData(['key' => 'value']) ; . 
    use sngrl\PhpFirebaseCloudMessaging\Client; use sngrl\PhpFirebaseCloudMessaging\Message; use sngrl\PhpFirebaseCloudMessaging\Recipient\Topic; use sngrl\PhpFirebaseCloudMessaging\Notification; $server_key = '_YOUR_SERVER_KEY_'; $client = new Client(); $client->setApiKey($server_key); $client->injectGuzzleHttpClient(new \GuzzleHttp\Client()); $message = new Message(); $message->setPriority('high'); $message->addRecipient(new Topic('_YOUR_TOPIC_')); $message ->setNotification(new Notification('some title', 'some body')) ->setData(['key' => 'value']) ; $response = $client->send($message); var_dump($response->getStatusCode()); var_dump($response->getBody()->getContents()); 

    #Send message to multiple Topics

    See Firebase documentation for sending to combinations of multiple topics.

    . $message = new Message(); $message->setPriority('high'); $message->addRecipient(new Topic('_YOUR_TOPIC_')); $message->addRecipient(new Topic('_YOUR_TOPIC_2_')); $message->addRecipient(new Topic('_YOUR_TOPIC_3_')); $message ->setNotification(new Notification('some title', 'some body')) ->setData(['key' => 'value']) // Will send to devices subscribed to topic 1 AND topic 2 or 3 ->setCondition('%s && (%s || %s)') ; . 

    #Subscribe user to the topic

    use sngrl\PhpFirebaseCloudMessaging\Client; $server_key = '_YOUR_SERVER_KEY_'; $client = new Client(); $client->setApiKey($server_key); $client->injectGuzzleHttpClient(new \GuzzleHttp\Client()); $response = $client->addTopicSubscription('_SOME_TOPIC_ID_', ['_FIRST_TOKEN_', '_SECOND_TOKEN_']); var_dump($response->getStatusCode()); var_dump($response->getBody()->getContents()); 

    #Remove user subscription to the topic

    use sngrl\PhpFirebaseCloudMessaging\Client; $server_key = '_YOUR_SERVER_KEY_'; $client = new Client(); $client->setApiKey($server_key); $client->injectGuzzleHttpClient(new \GuzzleHttp\Client()); $response = $client->removeTopicSubscription('_SOME_TOPIC_ID_', ['_FIRST_TOKEN_', '_SECOND_TOKEN_']); var_dump($response->getStatusCode()); var_dump($response->getBody()->getContents()); 

    About

    PHP API for Firebase Cloud Messaging from Google

    Источник

    Saved searches

    Use saved searches to filter your results more quickly

    You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

    A simple php class that allows you to send Firebase Cloud Messaging /fcm notifications from your php

    License

    aotr/firebase-cloud-messaging

    This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

    Name already in use

    A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

    Sign In Required

    Please sign in to use Codespaces.

    Launching GitHub Desktop

    If nothing happens, download GitHub Desktop and try again.

    Launching GitHub Desktop

    If nothing happens, download GitHub Desktop and try again.

    Launching Xcode

    If nothing happens, download Xcode and try again.

    Launching Visual Studio Code

    Your codespace will open once ready.

    There was a problem preparing your codespace, please try again.

    Latest commit

    Git stats

    Files

    Failed to load latest commit information.

    README.md

    A simple php class that allows you to send Firebase Cloud Messaging /fcm notifications from your php

    Firebase Cloud Messaging (FCM) is a cross-platform messaging solution that lets you reliably deliver messages at no cost.

    you will need to make sure your server meets the following requirements: PHP >= 5.3 cURL PHP Extension JSON PHP Extension

    To use this class, simply import PushNotifications.php into your project, and require it then make sure that assign value in Config Array keys in : FIREBASE_API_KEY, APP_NAME, FIREBASE_URL.

    require_once ('PushNotifications.php');

    Simple initialization: make sure the following assign value in Config Array keys in : FIREBASE_API_KEY, APP_NAME, FIREBASE_URL.

    Send notifications to one registration token

    $token = ['ciAXznOu4xx:APA91bF7TctN8-PJgGxSqJQQjaQM0BZE6XQipX-uMO1Jqq6efttxu8V9JVNrDFwOaPUl22M0BTOTDsBHhOShKGv9nEDv1kKMoU6qiEqwDvTk4oPeXXc1qy9n9VeaIoR4vN1wQzj7bqu1']; $body pl-s">Hare Krishna"; $data = ['test'=>'99', 'Test2'=>1947]; $fcm->notification($token, $body, $data);

    or Send notifications with a different title than the APP_NAME constant value

    $token = ['ciAXznOu4xx:APA91bF7TctN8-PJgGxSqJQQjaQM0BZE6PXipX-uMO1Jqq6efttxu9V9JVNrDFwOaPUl22M0BTOTDsBHhOShKGv9nEDv1kKMoU6qiEqwDvTk4oPeXXc1qy9n9VeaIoR4vN1wQzj7bqu1']; $body pl-s">Hare Krishna"; $title = APP_NAME . ' version 1.0' $fcm->notification($token, $body, null, $title);

    or Send notifications with a list of tokens (multiple devices)

    // 8 android devices $token = [ 'ciAXznOu4xx:APA91bF7TctN8-PJgGxSqJQQjaQM0BZE6PXipX-uMO1Jqq6efttxu9V9JVNrDFwOaPUl22M0BTO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M0BTOTDsBHhOShKGv9nEDv1kKMoU6qiEqwDvTk4oPeXXc1qy9n9VeaIoR4vN1wQzj7bqu1', ]; $body pl-s">Hare Krishna"; $data = ['test'=>'99', 'Test2'=>1947]; $fcm->notification($token, $body, $data);

    Send notifications to devices subscribed to a certain topic

    // null indicates no condition for the topic $data = ['test'=>'99', 'Test2'=>1947]; $fcm->topics('testTopics', null, 'Hare Krishna', $data);

    or Send filtered topic notifications with conditions

    // null indicates no condition for the topic $data = ['test'=>'99', 'Test2'=>1947]; $condition pl-s">'testTopics' in topics && ('testTopics1' in topics || 'testTopics2' in topics)"; $body = 'Hare Krishna'; $fcm->topics(null, $condition, $body, $data);

    Where To Look For Further Info

    About

    A simple php class that allows you to send Firebase Cloud Messaging /fcm notifications from your php

    Источник

    Читайте также:  Глобальные стили
Оцените статью