雪狼007cn/laravel-jpusher

JPush集成到laravel框架中

dev-master 2018-05-07 11:51 UTC

This package is not auto-updated.

Last update: 2024-09-23 06:53:44 UTC


README

JPush集成到laravel框架中

Latest Stable Version Total Downloads Latest Unstable Version License

目录

安装

Composer

执行以下命令以获取软件包的最新版本

composer require snowwolf007cn/laravel-jpusher

Laravel

>= laravel5.5

ServiceProvider将被自动附加

广播器

配置JPush广播器

将以下代码添加到您的config/broadcasting.php文件下的'connection'

'jpush' => [
    'driver' => 'jpush',
    'app_key' => env('JPUSH_APP_KEY'),
    'master_secret' => env('JPUSH_MASTER_SECRET'),
],

.env文件中填写您的app key和secret

设置受众

受众在laravel中被映射到频道,您可以这样配置频道。

Broadcast::channel('all', function ($user, $id) {
    return true;
});

Broadcast::channel('tag.{tag_name}', function ($user, $id) {
    return true;
});

上述示例为不同的受众配置设置了两个频道,分别是所有标签

添加有效载荷

平台、通知、消息和选项作为数组的有效载荷发送到广播器,将序列化为json并发送到服务器。平台默认为'所有',即。

/**
 * Add payload to broadcast.
 */
public function broadcastWith()
{
    return [
        'message' => [
            'msg_content' => 'Hi,JPush',
            'content_type' => 'text',
            'title' => 'msg',
        ],
    ];
}

有关如何广播事件JPush API的更多信息。