socketbus / socketbus-php
此包的最新版本(v1.0.1)没有可用的许可信息。
v1.0.1
2021-01-06 21:05 UTC
Requires
- php: >=5.3.0
- guzzlehttp/guzzle: ^6.0|^7.0.1
Requires (Dev)
- phpunit/phpunit: ^10.0@dev
- vlucas/phpdotenv: ^5.2@dev
This package is auto-updated.
Last update: 2024-09-07 05:08:42 UTC
README
SocketBus PHP 库
入门指南
- 创建账户 -
- 最低要求 -
- 安装库 -
composer require socketbus/socketbus-php
- 使用库 -
创建 SocketBus 实例
require 'vendor/autoload.php'; use SocketBus\SocketBus; $config = [ 'app_id' => 's-1-J2PCu8g8sAejZeXx', 'secret' => 'cdKBpcruwYQ96kvIaYiorbTFxRDCbVfj' ]; $socketBus = new SocketBus($config);
端到端加密
为了确保数据安全,您可以在“应用 > 设置”下启用端到端加密。此设置与选项 custom_encryption_key
结合使用,对有效负载进行加密,并在认证用户收到加密的有效负载时在客户端解密。
$config = [ 'app_id' => 's-1-J2PCu8g8sAejZeXx', 'secret' => 'cdKBpcruwYQ96kvIaYiorbTFxRDCbVfj', 'custom_encryption_key' => 'my-unique-key' ];
认证
定义通道类型
$channelName = $request->channel_name; if ($socketBus->isChannelPrivate($channelName)) { // The channel is private } if ($socketBus->isChannelPresence($channelName)) { // The channel is presence } if ($socketBus->isChannelPublic($channelName)) { // The channel is public }
私有认证
$socketId = $request->socket_id; $channelName = $request->channel_name; if (/** verifies if user can access the request channel */) { // returns the token to the client return [ 'auth' => $socketbus->auth($socketId, $channelName) ]; }
存在认证
$socketId = $request->socket_id; $channelName = $request->channel_name; $userId = /** gets the current user id */; if (/** verifies if user can access the request channel */) { // returns the data return $socketbus->authPresence($socketId, $channelName, $userId, true); }
广播
$payload = [ 'type' => 'cupcake', 'flavor' => 'sweet' ]; $sockebus->broadcast('food-observer', 'new-food', $payload);
资源
API 文档 - 查看完整文档
相关项目
SocketBus Laravel 库 - Laravel 库