diff --git a/.env-example b/.env-example index 6002299..300874d 100644 --- a/.env-example +++ b/.env-example @@ -39,3 +39,7 @@ GAME_HOT_CACHE_QUEUE_CONSUMER_BATCH = 80 # 移动端接口鉴权(/api/v1/authToken) AUTH_TOKEN_SECRET = 564d14asdasd113e46542asd6das1a2a + +# Webman Push:浏览器实际连接的 WS 基址(不含 /app/)。HTTPS 后台须用 wss://,与 Nginx 反代 3131 一致 +# 示例:PUSH_WEBSOCKET_CLIENT_URL = wss://zihua-api.yuliao666.top +PUSH_WEBSOCKET_CLIENT_URL = diff --git a/app/admin/controller/game/Live.php b/app/admin/controller/game/Live.php index 5411bc4..31b9e6d 100644 --- a/app/admin/controller/game/Live.php +++ b/app/admin/controller/game/Live.php @@ -3,6 +3,7 @@ namespace app\admin\controller\game; use app\common\controller\Backend; +use app\common\library\admin\PushChannelConfigHelper; use app\common\service\GameLiveService; use support\Response; use Webman\Http\Request as WebmanRequest; @@ -44,12 +45,8 @@ class Live extends Backend return $response; } - $ws = (string) config('plugin.webman.push.app.websocket'); - $ws = str_replace('websocket://', 'ws://', $ws); - $ws = str_replace('0.0.0.0', '127.0.0.1', $ws); - return $this->success('', [ - 'url' => $ws, + 'url' => PushChannelConfigHelper::wsBaseUrl(), 'app_key' => (string) config('plugin.webman.push.app.app_key'), 'channel' => 'game-live', 'event' => 'bet-updated', diff --git a/app/common/library/admin/PushChannelConfigHelper.php b/app/common/library/admin/PushChannelConfigHelper.php index 46dc5cf..6ab94ce 100644 --- a/app/common/library/admin/PushChannelConfigHelper.php +++ b/app/common/library/admin/PushChannelConfigHelper.php @@ -11,12 +11,27 @@ final class PushChannelConfigHelper { public static function wsBaseUrl(): string { + $client = trim((string) config('plugin.webman.push.app.websocket_client')); + if ($client !== '') { + return self::normalizeClientWsBase($client); + } + $ws = (string) config('plugin.webman.push.app.websocket'); $ws = str_replace('websocket://', 'ws://', $ws); return str_replace('0.0.0.0', '127.0.0.1', $ws); } + private static function normalizeClientWsBase(string $url): string + { + $url = rtrim(trim($url), '/'); + if (str_starts_with($url, 'websocket://')) { + return str_replace('websocket://', 'ws://', $url); + } + + return $url; + } + public static function appKey(): string { return (string) config('plugin.webman.push.app.app_key'); diff --git a/config/plugin/webman/push/app.php b/config/plugin/webman/push/app.php index 08595ad..0354a52 100644 --- a/config/plugin/webman/push/app.php +++ b/config/plugin/webman/push/app.php @@ -3,6 +3,8 @@ return [ 'enable' => true, 'websocket' => 'websocket://0.0.0.0:3131', 'api' => 'http://0.0.0.0:3232', + /** 浏览器连接的 WebSocket 基址(不含 /app/)。生产/前后端分离必填,如 wss://api.example.com */ + 'websocket_client' => env('PUSH_WEBSOCKET_CLIENT_URL', ''), 'app_key' => '6d0af5971ad191f2dc8a500885cb79c7', 'app_secret' => 'c457f0be89cd48d481b37f16c0a97f5f', 'channel_hook' => 'http://127.0.0.1:7979/plugin/webman/push/hook',