kozhindev / expo-server-sdk-php
PHP 用于处理 Expo 推送通知的服务端库
1.4.0
2021-08-24 05:25 UTC
Requires
- php: >=7.0
- ext-curl: *
- ext-json: *
This package is not auto-updated.
Last update: 2024-09-18 02:16:17 UTC
README
PHP 用于处理 Expo 推送通知的服务端库
使用方法
- 在项目中引入该包
composer require kozhindev/exponent-server-sdk-php
- 在 PHP 文件中
require_once __DIR__.'/vendor/autoload.php'; $token = 'ExponentPushToken[unique]'; $expo = new \ExponentPhpSDK\Expo(); // Build the notification data $notification = ['body' => 'Hello World!']; // Notify a token (or several tokens) with a notification $expo->notify([$token], $notification);
可以通过提供 JSON 对象将数据添加到通知中。例如
// Build the notification data $notification = ['body' => 'Hello World!', 'data'=> json_encode(array('someData' => 'goes here'))];
额外安全措施
如果您在 Expo 控制台(如这里所述)中设置了增强安全,则需要将授权令牌附加到每个推送请求中
// ... // Bootup an expo instance $expo = \ExponentPhpSDK\Expo::normalSetup(); // Fetch your access token from where you stored it $accessToken = 'your_expo_access_token'; // The access token will be attached to every push request you make hereafter $expo->setAccessToken($accessToken); // Notify an interest with a notification $expo->notify([$channelName], $notification);