{"id":37004779,"url":"https://github.com/jackchang1025/bbin-websocket-client","last_synced_at":"2026-01-14T00:38:55.897Z","repository":{"id":312067205,"uuid":"1046182701","full_name":"jackchang1025/bbin-websocket-client","owner":"jackchang1025","description":"一个基于 Hyperf WebSocket Client 的 BBIN WebSocket 客户端，支持事件驱动、消息解析、心跳处理与简单投注消息封装","archived":false,"fork":false,"pushed_at":"2025-08-28T10:05:53.000Z","size":39,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-28T16:41:09.242Z","etag":null,"topics":["baccarat","bbin","websocket"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jackchang1025.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-28T10:05:49.000Z","updated_at":"2025-08-28T10:17:57.000Z","dependencies_parsed_at":"2025-08-28T16:56:19.772Z","dependency_job_id":null,"html_url":"https://github.com/jackchang1025/bbin-websocket-client","commit_stats":null,"previous_names":["jackchang1025/bbin-websocket-client"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/jackchang1025/bbin-websocket-client","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jackchang1025%2Fbbin-websocket-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jackchang1025%2Fbbin-websocket-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jackchang1025%2Fbbin-websocket-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jackchang1025%2Fbbin-websocket-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jackchang1025","download_url":"https://codeload.github.com/jackchang1025/bbin-websocket-client/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jackchang1025%2Fbbin-websocket-client/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28406520,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T21:51:37.118Z","status":"ssl_error","status_checked_at":"2026-01-13T21:45:14.585Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["baccarat","bbin","websocket"],"created_at":"2026-01-14T00:38:55.783Z","updated_at":"2026-01-14T00:38:55.877Z","avatar_url":"https://github.com/jackchang1025.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"BBIN WebSocket Client（PHP）\n\n一个基于 Hyperf WebSocket Client 的 BBIN WebSocket 客户端，支持事件驱动、消息解析、心跳处理与简单投注消息封装。\n\n- 命名空间：`Weijiajia\\\\BbinWebSocketClient`\n- 运行时依赖：`ext-swoole` (\u003e=5.0)\n- PHP 版本：\u003e= 8.2\n\n安装\n```bash\ncomposer require weijiajia/bbin-websocket-client\n```\n\n开发环境若暂时没有安装 Swoole，可在安装阶段忽略平台要求，但运行时仍需在具备 Swoole 的环境中执行：\n```bash\ncomposer install --ignore-platform-req=ext-swoole\n```\n\n推荐在 Docker 中使用官方 Swoole 运行时执行示例/测试：\n```bash\ndocker run --rm -it -v $PWD:/app -w /app --network host swoole/swoole:php8.3 php -v\n```\n\n快速开始\n```php\n\u003c?php\n\nrequire __DIR__ . '/vendor/autoload.php';\n\nuse Weijiajia\\\\BbinWebSocketClient\\\\WebsocketClient;\nuse Weijiajia\\\\BbinWebSocketClient\\\\WebsocketMessage;\nuse Weijiajia\\\\BbinWebSocketClient\\\\BetMessage;\nuse Weijiajia\\\\BbinWebSocketClient\\\\LotteryResult;\n\n$client = new WebsocketClient('wss://example.com/fxLive/fxLB?gameType=h5multi3');\n\n$client-\u003eonOpen(function (WebsocketClient $client) {\n    echo \"websocket connect success\\n\";\n});\n\n$client-\u003eonMessage(function (WebsocketClient $client, WebsocketMessage $message) {\n    // 全量消息广播\n});\n\n$client-\u003eonPing(function (WebsocketClient $client, WebsocketMessage $message) {\n    // 按协议回 pong（示例协议为原样发回）\n    $client-\u003epush($message-\u003edata());\n});\n\n$client-\u003eon('ready', function (WebsocketClient $client) {\n    $client-\u003epush([\n        'lang' =\u003e 'cn',\n        'vType' =\u003e 'wss',\n        'site' =\u003e '1',\n        'sid' =\u003e 'REPLACE_ME',\n        'action' =\u003e 'hallLogin',\n    ]);\n});\n\n$client-\u003eon('onHallLogin', function (WebsocketClient $client) {\n    $client-\u003epush([\n        'dev' =\u003e [\n            'rd' =\u003e 'fx', 'ua' =\u003e 'UA', 'os' =\u003e 'Windows 10', 'dpr' =\u003e 1, 'pl' =\u003e 'H5',\n        ],\n        'lang' =\u003e 'cn', 'vType' =\u003e 'wss', 'vtMode' =\u003e true,\n        'subscription' =\u003e ['example'],\n        'action' =\u003e 'login',\n        'sid' =\u003e 'REPLACE_ME',\n    ]);\n});\n\n$client-\u003eon('onUpdateGameInfo', function (WebsocketClient $client, WebsocketMessage $message) {\n    $message-\u003egameInfo()-\u003eeach(function (LotteryResult $lotteryResult) {\n        echo $lotteryResult-\u003egetDeckNumber() . PHP_EOL;\n    });\n\n    $bet = new BetMessage();\n    $bet-\u003ebetBanker(20);\n    $bet-\u003egameCode = '57';\n    $bet-\u003egameType = '3001';\n    $bet-\u003eroundSerial = 643386079;\n    $bet-\u003esid = 'REPLACE_ME';\n    $client-\u003ebet($bet);\n});\n\n$client-\u003eon('onBet', function (WebsocketClient $client, WebsocketMessage $message) {\n    var_dump($message-\u003edata());\n});\n\n$client-\u003eonError(function (WebsocketClient $client, \\\\Throwable $e) {\n    var_dump($e-\u003egetMessage());\n});\n\n$client-\u003eonClose(function () {\n    echo \"websocket close\\n\";\n});\n\n$client-\u003estart();\n```\n\n事件模型\n- 通用事件：`on(string $event, callable $callback)`\n- 语义化事件：`onOpen` / `onMessage` / `onPing` / `onError` / `onClose`\n\nAPI 说明\nWebsocketClient\n- `__construct(string $host, array $headers = [])`\n- `start(): void`、`stop(): void`、`close(): void`\n- `push(array $data, int $opcode = WEBSOCKET_OPCODE_TEXT, ?int $flags = null): bool`\n- `bet(BetMessage $betMessage): bool`\n\nWebsocketMessage\n- `static fromPayload(string $payload): self`\n- `data(): array`、`isPing(): bool`、`action(): ?string`\n- `assertNoProtocolError(): void`\n- `gameInfo(): Collection\u003cLotteryResult\u003e`\n\nLotteryResult（部分）\n- `getDeckNumber()`、`getLastDeckNumber()`、`getNumber()`\n- `getTransformationResult()`、`checkLotteryResults()`\n\nBetMessage\n- `betBanker(int $amount)` / `betPlayer(int $amount)`（最低 20）\n- 设置 `gameType`, `gameCode`, `roundSerial`, `sid`\n- `data(): array`\n\n运行与示例\n```bash\nphp src/example/WebsocketClient.php\n```\n\n在 Docker 中运行示例：\n```bash\ndocker run --rm -it -v $PWD:/app -w /app --network host \\\n  swoole/swoole:php8.3 php src/example/WebsocketClient.php\n```\n\n测试\n```bash\ncomposer install -n --prefer-dist\nvendor/bin/pest --exclude-group=integration\nvendor/bin/pest --group=integration\n```\n\n常见问题\n- `Class \"Swoole\\\\Coroutine\\\\Http\\\\Client\" not found`：缺少 `ext-swoole`\n- `连接失败: ...` 后跟 `websocket close`：检查 host 与网络\n- JSON 解码异常：查看 `error` 事件输出\n\n许可证：MIT\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjackchang1025%2Fbbin-websocket-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjackchang1025%2Fbbin-websocket-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjackchang1025%2Fbbin-websocket-client/lists"}