preneesh/yii2-firebase-notifications

从 Yii2 应用程序发送 Firebase 通知

dev-master 2020-05-12 09:27 UTC

This package is not auto-updated.

Last update: 2024-09-25 06:52:46 UTC


README

从 Yii2 应用程序发送 Firebase 通知

==

从 Yii2 应用程序发送 Firebase 通知 此扩展允许向单个用户发送 Firebase 通知,以提供特定更新。

安装

安装此扩展的首选方式是通过 composer

运行以下命令之一

php composer.phar require --prefer-dist preneesh/yii2-firebase-notifications "dev-master"

"preneesh/yii2-firebase-notifications": "dev-master"

将以下内容添加到您的 composer.json 文件的 require 部分。

用法

扩展安装完成后,只需在代码中简单使用即可

使用此扩展需要 Firebase 云消息服务器密钥,该密钥可以从 Firebase 控制台获取 -> 项目概述 -> 设置 -> 云消息

use preneesh\FirebaseNotifications\Notification;

$service = new Notification('YOUR_KEY');

$message = array();
$message['title']= "New Offer";
$message['body']= "New Year offer for the all products";

#unique token to be captured from android app and stored against user for sending notification to specific user
$tokens = "d-Uh6MC1eTk:APA91bHjvSR3BDjfBqt4-ZkPbu69aije4HCzcKqvIpcBJof8Zc7z8jVeVb1WLGEjfgd6POBfW-qGUcSsESiOAOKbFnOHt_m1rk-deElMgIsojS7gpF7trgYmsLjrxICsZg7LRgPXyn6b-eqCk9nE";

$service->send($tokens,$message);