webup / laravel-push
连接Laravel应用与webup/push实例的桥梁
v1.1.0
2023-06-16 09:39 UTC
Requires
- php: >=7.2
- guzzlehttp/guzzle: ^6.3 || ^7
This package is auto-updated.
Last update: 2024-09-16 12:52:27 UTC
README
本包作为Laravel应用与webup/push实例之间的桥梁。
安装
使用Composer安装包
$ composer require webup/laravel-push
在环境变量中配置基本URI
将环境变量PUSH_API_BASE_URI
设置为webup/push的URI。
请注意,默认情况下webup/push监听端口3000
。
在config/services.php中配置服务
'push_api' => [ 'base_uri' => env('PUSH_API_BASE_URI'), 'app_name' => env('PUSH_API_APP_NAME') ]
如何使用Token作业
AssignToken
Webup\LaravelPush\Jobs\Token\AssignToken
可以从控制器或任何需要的类中直接调用。为此,您必须在类中导入作业,使用以下use
语句:
use Webup\LaravelPush\Jobs\Token\AssignToken;
然后,您可以执行dispatch_now()
,同时指定一个id
,该id用于标识与Token关联的用户/设备/其他内容,以及包含以下内容的array
:
- the
token
(设备的FCM推送令牌) - the
platform
(iOS或Android,分别对应1和2) - 设备的
language
代码。
例如
dispatch_now(new AssignToken( auth()->user()->id, // In this case, user to whom the token is assigned [ 'token' => $push_token, // The device's FCM push token 'platform' => $device_type, // iOS (1) or Android (2) 'language' => 'fr', // The device's language code ] ));
RemoveToken
Webup\LaravelPush\Jobs\Token\RemoveToken
与AssignToken的工作方式完全相同,但其目的是从数据库中删除令牌。