update pay ui

This commit is contained in:
2025-12-10 11:43:56 +08:00
parent 2482b01b00
commit 45339902aa
2 changed files with 42 additions and 8 deletions

View File

@@ -4,12 +4,41 @@
import type { Exchange } from '../types'; import type { Exchange } from '../types';
/** WebSocket 服务地址 */ /**
export const WS_CONFIG: Record<Exchange, string> = { * 获取 WebSocket 配置
* - 生产环境 (HTTPS): 通过 Nginx 代理使用 wss://
* - 开发环境 (HTTP): 直连 ws://
*/
const getWsConfig = (): Record<Exchange, string> => {
// 服务端渲染或测试环境使用默认配置
if (typeof window === 'undefined') {
return {
SSE: 'ws://49.232.185.254:8765',
SZSE: 'ws://222.128.1.157:8765',
};
}
const isHttps = window.location.protocol === 'https:';
const host = window.location.host;
if (isHttps) {
// 生产环境:通过 Nginx 代理
return {
SSE: `wss://${host}/ws/sse`, // 上交所 - Nginx 代理
SZSE: `wss://${host}/ws/szse`, // 深交所 - Nginx 代理
};
}
// 开发环境:直连
return {
SSE: 'ws://49.232.185.254:8765', // 上交所 SSE: 'ws://49.232.185.254:8765', // 上交所
SZSE: 'ws://222.128.1.157:8765', // 深交所 SZSE: 'ws://222.128.1.157:8765', // 深交所
};
}; };
/** WebSocket 服务地址 */
export const WS_CONFIG: Record<Exchange, string> = getWsConfig();
/** 心跳间隔 (ms) */ /** 心跳间隔 (ms) */
export const HEARTBEAT_INTERVAL = 30000; export const HEARTBEAT_INTERVAL = 30000;

View File

@@ -2,8 +2,12 @@
* 实时行情 Hook * 实时行情 Hook
* 管理上交所和深交所 WebSocket 连接,获取实时行情数据 * 管理上交所和深交所 WebSocket 连接,获取实时行情数据
* *
* 上交所 (SSE): ws://49.232.185.254:8765 - 需主动订阅,提供五档行情 * 连接方式:
* 深交所 (SZSE): ws://222.128.1.157:8765 - 自动推送,提供十档行情 * - 生产环境 (HTTPS): 通过 Nginx 代理使用 wss:// (如 wss://valuefrontier.cn/ws/sse)
* - 开发环境 (HTTP): 直连 ws://
*
* 上交所 (SSE): 需主动订阅,提供五档行情
* 深交所 (SZSE): 自动推送,提供十档行情
*/ */
import { useState, useEffect, useRef, useCallback } from 'react'; import { useState, useEffect, useRef, useCallback } from 'react';
@@ -402,7 +406,8 @@ export const useRealtimeQuote = (codes: string[] = []): UseRealtimeQuoteReturn =
}, []); }, []);
const createConnection = useCallback((exchange: Exchange) => { const createConnection = useCallback((exchange: Exchange) => {
// 检查是否是 HTTPS 页面尝试连接 ws://Mixed Content // 防御性检查:确保 HTTPS 页面不会意外连接 ws://Mixed Content 安全错误
// 正常情况下 WS_CONFIG 会自动根据协议返回正确的 URL这里是备用保护
const isHttps = typeof window !== 'undefined' && window.location.protocol === 'https:'; const isHttps = typeof window !== 'undefined' && window.location.protocol === 'https:';
const wsUrl = WS_CONFIG[exchange]; const wsUrl = WS_CONFIG[exchange];
const isInsecureWs = wsUrl.startsWith('ws://'); const isInsecureWs = wsUrl.startsWith('ws://');
@@ -410,7 +415,7 @@ export const useRealtimeQuote = (codes: string[] = []): UseRealtimeQuoteReturn =
if (isHttps && isInsecureWs) { if (isHttps && isInsecureWs) {
logger.warn( logger.warn(
'FlexScreen', 'FlexScreen',
`${exchange} WebSocket 连接被跳过HTTPS 页面无法连接不安全的 ws:// 端点` `${exchange} WebSocket 配置错误HTTPS 页面尝试连接 ws:// 端点,请检查 Nginx 代理配置`
); );
return; return;
} }