PHP code example of redjanym / fcm-bundle

1. Go to this page and download the library: Download redjanym/fcm-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

redjanym / fcm-bundle example snippets


use RedjanYm\FCM\Notification;
use RedjanYm\FCM\Recipient\Device;

// Using the notification factory (recommended)
$factory = $this->container->get('redjan_ym_fcm.notification_factory');
$notification = $factory->createDeviceNotification(
    'device-token-here',
    'Notification Title',
    'Notification Body',
    ['key' => 'value']  // optional data payload
);

// Or manually
$notification = new Notification(
    new Device('device-token-here'),
    'Notification Title',
    'Notification Body'
);

// Send
$client = $this->container->get('redjan_ym_fcm.client');
$response = $client->send($notification);

use RedjanYm\FCM\Notification;
use RedjanYm\FCM\Recipient\Topic;

// Using the notification factory (recommended)
$factory = $this->container->get('redjan_ym_fcm.notification_factory');
$notification = $factory->createTopicNotification(
    'news',
    'Breaking News',
    'Something important happened',
    ['url' => 'https://example.com/article/123']
);

// Or manually
$notification = new Notification(
    new Topic('news'),
    'Breaking News',
    'Something important happened'
);

// Send
$client = $this->container->get('redjan_ym_fcm.client');
$response = $client->send($notification);

$notification->image = 'https://example.com/image.png';
$notification->sound = 'default';
$notification->badge = 1;
$notification->icon = 'ic_notification';
$notification->color = '#FF0000';
$notification->clickAction = 'OPEN_ACTIVITY';
$notification->androidChannelId = 'my_channel';
$notification->androidPriority = 'high';
$notification->apnsPriority = '10';
$notification->ttl = '3600s';
$notification->analyticsLabel = 'campaign_123';

// Extra settings arrays for platform-specific customization
$notification->extraNotificationSettings = ['tag' => 'my-tag'];
$notification->extraAPNSHeadersSettings = ['apns-collapse-id' => 'campaign'];
$notification->webPushHeadersSettings = ['TTL' => '86400'];