zandor300/fcmframework
最新稳定版本:1.1.1
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:
- Go to the Firebase Console.
- Select your project.
- Click on the gear icon next to "Project Overview" and select "Project settings".
- Navigate to the "Service accounts" tab.
- Click on "Generate new private key".
- 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();
}
统计信息
- 总下载量: 610
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2025-08-20