push-notification / push-notification-php-library
向android|ios设备发送推送通知,支持APNs、FCM
v1.4
2023-10-14 09:40 UTC
Requires
- php: >=5.6
- guzzlehttp/guzzle: ^6.3
- vlucas/phpdotenv: ^2.4.0
README
一个用于简单设备消息推送通知的独立PHP库。
欢迎贡献!
安装
composer require push-notification/push-notification-php-library
composer dump-autoload -o
此仓库使用PSR-0自动加载。使用composer安装后,如有需要,请调整自动加载配置或包含vendor/autoload.php到您的index.php中。
要求
- PHP 5.6+
- PHP Curl和OpenSSL模块
支持
- APNS (Apple)
- GCM (Android) 和 FCM (Android)
设置
-
在.env中设置您的提供商(Apn, Fcm)的设置(确保已将.env.example重命名为.env并填写所有要求)
-
到.env文件的路径:您需要在
src/PushNotification/Setting中设置$path变量到.env文件
如何使用
include_once "vendor/autoload.php"; use PushNotification\Service\PushService; $data = array( 'device' => array( 'name' => '', // Android or AppleIOS 'token' => '', // device token | user token , if you want to send to apple device you have to fill this 'id' => 'unique id here'), 'message' => array( 'action' => 'test', 'title' => 'this is test title', 'targets' => array(''), // if you want to use Fcm you can inclue array of targets 'body' => 'this is body', 'type' => '', // AndroidMessages or IOSMessages 'data' => array('type' => 'testType')) ); $response = PushService::getInstance()->send($data);
Android
include_once "vendor/autoload.php"; use PushNotification\Service\PushService; $data = array( 'device' => array( 'name' => 'Android', 'token' => '', 'id' => 'some id here '), 'message' => array( 'action' => 'test', 'title' => 'this is test title', 'targets' => array('token1', 'token2', 'token3'), 'body' => 'this is body', 'type' => 'AndroidMessages', 'data' => array('type' => 'testType')) ); $response = PushService::getInstance()->send($data); print_r($response);
IOS
include_once "vendor/autoload.php"; use PushNotification\Service\PushService; $data = array( 'device' => array( 'name' => 'AppleIOS', 'token' => 'token', 'id' => 'BECDSx'), 'message' => array( 'action' => 'test', 'title' => 'this is test title', 'targets' => array(), 'body' => 'this is body', 'type' => 'IOSMessages', 'data' => array('type' => 'testType')) ); $response = PushService::getInstance()->send($data); print_r($response);