pusher / pusher-push-notifications
2.0
2022-08-09 21:07 UTC
Requires
- php: >=8.0
- ext-mbstring: *
- firebase/php-jwt: ^6.0
- guzzlehttp/guzzle: ^7.0
Requires (Dev)
- doctrine/instantiator: 1.4.0
- overtrue/phplint: ^4.0 || ^5.0
- phpunit/phpunit: ^9.0
- symfony/yaml: ^5.0 || ^6.0
README
Pusher Beams 的 PHP SDK
用于通过 Pusher Beams 发布通知的 PHP 服务器库。
有关更多信息,请参阅https://docs.pusher.com/beams/reference/server-sdk-php。
注意:此库需要 PHP 8.0 或更高版本
安装
获取 Composer,然后获取 pusher/pusher-push-notifications
Composer 包
$ composer require pusher/pusher-push-notifications
此 SDK 依赖于 JSON PHP 模块。
使用
为您的实例配置 SDK
<?php require __DIR__ . '/vendor/autoload.php'; $pushNotifications = new \Pusher\PushNotifications\PushNotifications(array( "instanceId" => "YOUR_INSTANCE_ID_HERE", "secretKey" => "YOUR_SECRET_HERE", ));
向设备兴趣发布
您可以使用 设备兴趣 向订阅设备组广播通知
$publishResponse = $pushNotifications->publishToInterests( ["donuts"], [ "apns" => [ "aps" => [ "alert" => "Hello!", ], ], "fcm" => [ "notification" => [ "title" => "Hello!", "body" => "Hello, world!", ], ], ] ); echo("Published with Publish ID: " . $publishResponse->publishId . "\n");
带数据的设备兴趣发布
您可以使用 设备兴趣 向订阅设备组广播带有一些数据的通知
$publishResponse = $pushNotifications->publishToInterests( ["donuts"], [ "apns" => [ "aps" => [ "alert" => "Hello!", ], ], "fcm" => [ "notification" => [ "title" => "Hello!", "body" => "Hello, world!", ], "data" => [ "name" => "adam", "type" => "user", ], ], ] ); echo("Published with Publish ID: " . $publishResponse->publishId . "\n");
向认证用户发布
使用 认证用户 安全地向您的应用程序的个别用户发送通知
$publishResponse = $pushNotifications->publishToUsers( ["user-0001"], [ "apns" => [ "aps" => [ "alert" => "Hello!", ], ], "fcm" => [ "notification" => [ "title" => "Hello!", "body" => "Hello, world!", ], ], ] ); echo("Published with Publish ID: " . $publishResponse->publishId . "\n");