定制 zandor300/fcmframework 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

zandor300/fcmframework

Composer 安装命令:

composer require zandor300/fcmframework

包简介

PHP framework for Firebase push notifications interaction

README 文档

README

PHP framework for easy interaction with the Apple Push Notification Service.

Install

composer require zandor300/fcmframework

Usage

Obtain Firebase service account file

To obtain the Firebase service account file, follow these steps:

  1. Go to the Firebase Console.
  2. Select your project.
  3. Click on the gear icon next to "Project Overview" and select "Project settings".
  4. Navigate to the "Service accounts" tab.
  5. Click on "Generate new private key".
  6. Confirm by clicking "Generate key".

A JSON file containing your service account credentials will be downloaded. Save this file securely, as it will be used to authenticate your server with Firebase.

Creating FCM object.

use FCMFramework;

use FCMFramework\FCM;

$fcm = null;
try {
    $serviceAccountFilePath = "";
    $fcm = new FCM($serviceAccountFilePath);
} catch (FCMException $e) {
    echo "Error: " . $e->getMessage();
    // Handle exception
}

Creating a basic notification

$notification = new FCMNotification();

$notification->setTitle("Example Notification");
$notification->setBody("This is an example notification!");

Creating a token object in React Native

import messaging from "@react-native-firebase/messaging";
import { PermissionsAndroid } from "react-native";

// Request notification permission
try {
    await PermissionsAndroid.request(
        PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS,
    );
    checkNotificationPermission();
} catch (err) {
    console.warn(err);
}

(async () => {
    await checkNotificationPermission();
    if (isNotificationPermissionGranted) {
        saveTokenToDatabase();
    }
    }
)();

// Check notification permission
const granted = await PermissionsAndroid.check(
    PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS,
);
setIsNotificationPermissionGranted(granted);

// Create token
const token = await messaging().getToken();

Sending the notification

global $fcm;
try {
    $fcm->sendFCMNotification($notification, $this->getFCMToken());
} catch(FCMDeviceTokenInactive $e) {
    $this->delete();
}

统计信息

  • 总下载量: 1.75k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2025-08-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固