EdwinHoksberg / php-fcm

A PHP library for sending Firebase Cloud Messages and managing user topic subscriptions, device groups and devices.
https://php-fcm.readthedocs.io/
MIT License
68 stars 32 forks source link

Looking for contributors to upgrade this project to HTTP v1 #67

Open rolinger opened 2 months ago

rolinger commented 2 months ago

If anyone wants to migrate/upgrade this API please have at it. It is light and nimble but is going to require a decent amount of rewrites to support the HTTP v1 API - the Legacy FCM api that this repository interfaces with is now retired and not supported anymore.

For the moment, I am moving to "firebase-php" as it is an active and fully supported HTTP v1 interface. I don't need all the extra stuff from firebase-php, yet I also do not have the time to recode this php-fcm repo.

kw-pr commented 1 month ago

Yes, same her.

Install the laravel version:

composer require kreait/laravel-firebase

Generate and download the private key .json: https://firebase-php.readthedocs.io/en/7.15.0/setup.html#google-service-account

I published the config:

php artisan vendor:publish --provider="Kreait\Laravel\Firebase\ServiceProvider" --tag=config

and copied the array from the private key .json into config/firebase.php.

See: https://github.com/kreait/laravel-firebase?tab=readme-ov-file#credentials-with-arrays

Now you are good to go:

use Kreait\Firebase\Exception\FirebaseException;
use Kreait\Firebase\Exception\MessagingException;
use Kreait\Firebase\Messaging\AndroidConfig;
use Kreait\Firebase\Messaging\CloudMessage;

$config = AndroidConfig::fromArray([
    'ttl' => '3600s',
    'priority' => 'normal',
    'notification' => [
        'title' => '$GOOG up 1.43% on the day',
        'body' => '$GOOG gained 11.80 points to close at 835.67, up 1.43% on the day.',
        'icon' => 'stock_ticker_update',
        'color' => '#f45342',
        'sound' => 'default',
    ],
]);

$cloudMessage = CloudMessage::withTarget('token', $token);
$cloudMessage = $cloudMessage->withAndroidConfig($config);

See also https://firebase-php.readthedocs.io/en/7.15.0/cloud-messaging.html#adding-target-platform-specific-configuration

rolinger commented 1 month ago

The most I might ever get around to contributing to is this repository: https://github.com/lkaybob/php-fcm-v1

Its JUST the cloud messaging...so its light compared to the full firebase-php I listed above...but I am almost done with my full fireabase-php migration; so once I am done with that I don't see me working on more FCM stuff anytime soon.