1.重构websocket连接

This commit is contained in:
2026-05-27 10:28:39 +08:00
parent a7c2a29764
commit 8f5ba977a4
12 changed files with 1101 additions and 144 deletions

View File

@@ -6,6 +6,7 @@ use app\common\controller\Backend;
use app\common\library\admin\WebSocketConfigHelper;
use app\common\service\GameLiveService;
use app\common\service\GameRecordService;
use app\common\service\GameWebSocketAuthHelper;
use support\Response;
use Webman\Http\Request as WebmanRequest;
@@ -67,9 +68,19 @@ class Live extends Backend
'auto.spin.progress',
];
$adminId = $this->auth ? (int) ($this->auth->id ?? 0) : 0;
$adminWs = GameWebSocketAuthHelper::issueAdminWsToken($adminId);
$baseWsUrl = WebSocketConfigHelper::wsUrl($request);
$wsUrl = WebSocketConfigHelper::appendTokensToWsUrl($baseWsUrl, [
'admin_ws_token' => (string) ($adminWs['token'] ?? ''),
]);
return $this->success('', [
'name' => 'ws.admin.live',
'ws_url' => WebSocketConfigHelper::wsUrl($request),
'ws_url' => $wsUrl,
'ws_base_url' => $baseWsUrl,
'admin_ws_token' => (string) ($adminWs['token'] ?? ''),
'admin_ws_token_ttl' => (int) ($adminWs['ttl'] ?? 0),
'connect_tip' => 'The admin live page auto-subscribes topics for status, draw result and payout events.',
'subscribe_topics' => $topics,
'sample_messages' => [

View File

@@ -6,6 +6,7 @@ namespace app\admin\controller\test;
use app\common\controller\Backend;
use app\common\library\admin\WebSocketConfigHelper;
use app\common\service\GameWebSocketAuthHelper;
use app\common\service\GameWebSocketPayloadHelper;
use support\Response;
use Webman\Http\Request as WebmanRequest;
@@ -43,9 +44,19 @@ class GameCurrentStatus extends Backend
$oddsPushTopics = GameWebSocketPayloadHelper::ODDS_PUSH_TOPICS;
$testPlayerOdds = GameWebSocketPayloadHelper::adminTestPlayerOddsSnapshot();
$adminId = $this->auth ? (int) ($this->auth->id ?? 0) : 0;
$adminWs = GameWebSocketAuthHelper::issueAdminWsToken($adminId);
$baseWsUrl = WebSocketConfigHelper::wsUrl($request);
$wsUrl = WebSocketConfigHelper::appendTokensToWsUrl($baseWsUrl, [
'admin_ws_token' => (string) ($adminWs['token'] ?? ''),
]);
return $this->success('', [
'name' => 'ws.period',
'ws_url' => WebSocketConfigHelper::wsUrl($request),
'ws_url' => $wsUrl,
'ws_base_url' => $baseWsUrl,
'admin_ws_token' => (string) ($adminWs['token'] ?? ''),
'admin_ws_token_ttl' => (int) ($adminWs['ttl'] ?? 0),
'connect_tip' => '连接成功后将自动订阅下列主题。真实业务仅在有玩家下注/结算时推送赔率;本页联调会在订阅后额外推送带 is_test/preview 的演示帧(见下方测试玩家赔率)。',
'subscribe_topics' => $subscribeTopics,
'odds_push_topics' => $oddsPushTopics,