You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何构造Pusher GET请求获取所有PRESENCE频道user_count?求CURL示例

Pusher PRESENCE频道user_count获取方案

可直接运行的CURL请求示例

请先将请求中的占位符替换为你Pusher应用的对应配置值:

  • YOUR_PUSHER_CLUSTER:Pusher应用所属集群,例如ap1、us-east-1
  • YOUR_APP_ID:Pusher控制台获取的应用ID
  • YOUR_APP_KEY:Pusher应用公钥
  • CURRENT_UNIX_TIMESTAMP:当前10位Unix时间戳(与Pusher服务器时间差不能超过5分钟)
  • GENERATED_AUTH_SIGNATURE:按下方规则生成的请求签名
curl "https://YOUR_PUSHER_CLUSTER.pusher.com/apps/YOUR_APP_ID/channels?filter_by_prefix=presence-&info=user_count&auth_key=YOUR_APP_KEY&auth_timestamp=CURRENT_UNIX_TIMESTAMP&auth_version=1.0&auth_signature=GENERATED_AUTH_SIGNATURE"

签名生成规则

签名使用HMAC-SHA256算法生成,规则如下:

  1. 拼接签名字符串,格式为 请求方法\n请求路径\n排序后的所有查询参数字符串,示例结构:
GET
/apps/YOUR_APP_ID/channels
auth_key=YOUR_APP_KEY&auth_timestamp=CURRENT_UNIX_TIMESTAMP&auth_version=1.0&filter_by_prefix=presence-&info=user_count
  1. 以你的Pusher应用私钥为密钥,对上述字符串做HMAC-SHA256加密,得到的十六进制结果就是auth_signature的值

Laravel 更简便实现方案(无需手动拼请求)

由于你使用Laravel技术栈,直接使用官方Pusher SDK可跳过签名、请求构造等繁琐步骤:

  1. 安装官方SDK:
composer require pusher/pusher-php-server
  1. 确保config/broadcasting.php中已配置好Pusher相关参数,调用示例代码:
$pusher = new Pusher\Pusher(
    config('broadcasting.connections.pusher.key'),
    config('broadcasting.connections.pusher.secret'),
    config('broadcasting.connections.pusher.app_id'),
    ['cluster' => config('broadcasting.connections.pusher.options.cluster')]
);
$channelsData = $pusher->get_channels([
    'filter_by_prefix' => 'presence-',
    'info' => 'user_count'
]);
// $channelsData->channels 即为所有带user_count的PRESENCE频道列表

内容的提问来源于stack exchange,提问作者ArcticMediaRyan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.29 17:45:03