package-of-yii / pusher
Yii2 的 Pusher 包装器。
dev-master
2019-01-27 09:19 UTC
Requires
- php: >=5.5.0
- pusher/pusher-php-server: ^3.3
This package is auto-updated.
Last update: 2024-09-27 21:58:15 UTC
README
Yii2 的 Pusher 扩展。
yii2-pusher 的维护、重构和组织版本,原地址为 yii2-pusher
简化了与 Yii2 集成 Pusher 的过程。
官方文档
将此配置添加到您的配置文件中。
'pusher' => [
'class' => 'POYii\Pusher\Pusher',
'appId' => 'YOUR_APP_ID',
'appKey' => 'YOUR_APP_KEY',
'appSecret' => 'YOUR_APP_SECRET',
'options' => ['encrypted' => true, 'cluster' => 'YOUR_APP_CLUSTER']
],
您可以在 Pusher 控制台 中创建新的应用程序(如果尚未创建)。将 appID、appKey、appSecret 和 appCluster 添加到上述配置中。
使用示例
PHP
Yii::$app->pusher->push('my-channel', 'my_event', 'hello world');
前端
<!DOCTYPE html>
<head>
<title>Pusher Test</title>
<script src="https://js.pusher.com/4.3/pusher.min.js"></script>
<script>
// Enable pusher logging - don't include this in production
Pusher.logToConsole = true;
var pusher = new Pusher('YOUR_APP_KEY', {
cluster: 'eu',
forceTLS: true
});
var channel = pusher.subscribe('my-channel');
channel.bind('my-event', function(data) {
alert(JSON.stringify(data));
});
</script>
</head>
<body>
<h1>Pusher Test</h1>
<p>
Try publishing an event to channel <code>my-channel</code>
with event name <code>my-event</code>.
</p>
</body>
许可协议
Yii Pusher 包软件遵循 MIT 许可协议。