update pay ui
This commit is contained in:
24
app.py
24
app.py
@@ -180,10 +180,13 @@ app = Flask(__name__)
|
||||
verification_codes = {}
|
||||
|
||||
# ============ 微信登录 Session 管理(Redis 存储,支持多进程) ============
|
||||
# Redis 客户端配置
|
||||
redis_client = redis.Redis(host='localhost', port=6379, db=0, decode_responses=True)
|
||||
# Redis 连接配置(支持环境变量覆盖,与 Flask-Session 共享配置)
|
||||
_REDIS_HOST = os.environ.get('REDIS_HOST', 'localhost')
|
||||
_REDIS_PORT = int(os.environ.get('REDIS_PORT', 6379))
|
||||
redis_client = redis.Redis(host=_REDIS_HOST, port=_REDIS_PORT, db=0, decode_responses=True)
|
||||
WECHAT_SESSION_EXPIRE = 300 # Session 过期时间(5分钟)
|
||||
WECHAT_SESSION_PREFIX = "wechat_session:"
|
||||
print(f"📦 微信登录 Redis 配置: {_REDIS_HOST}:{_REDIS_PORT}/db=0")
|
||||
|
||||
|
||||
def set_wechat_session(state, data):
|
||||
@@ -290,11 +293,13 @@ app.config['SECRET_KEY'] = os.environ.get('FLASK_SECRET_KEY', 'vf_production_sec
|
||||
|
||||
# ============ Redis Session 配置(支持多进程/多 Worker)============
|
||||
# 使用 Redis 存储 session,确保多个 Gunicorn worker 共享 session
|
||||
# 复用前面定义的 _REDIS_HOST 和 _REDIS_PORT
|
||||
app.config['SESSION_TYPE'] = 'redis'
|
||||
app.config['SESSION_REDIS'] = redis.Redis(host='localhost', port=6379, db=1) # 使用 db=1,与微信 session 的 db=0 分开
|
||||
app.config['SESSION_REDIS'] = redis.Redis(host=_REDIS_HOST, port=_REDIS_PORT, db=1) # db=1 用于 session
|
||||
app.config['SESSION_PERMANENT'] = True
|
||||
app.config['SESSION_USE_SIGNER'] = True # 对 session cookie 签名,提高安全性
|
||||
app.config['SESSION_KEY_PREFIX'] = 'vf_session:' # session key 前缀
|
||||
print(f"📦 Flask Session 配置: {_REDIS_HOST}:{_REDIS_PORT}/db=1")
|
||||
# ============ Redis Session 配置结束 ============
|
||||
|
||||
# Cookie 配置 - 重要:HTTPS 环境必须设置 SECURE=True
|
||||
@@ -412,20 +417,27 @@ _async_mode = _detect_async_mode()
|
||||
print(f"📡 Flask-SocketIO async_mode: {_async_mode}")
|
||||
|
||||
# Redis 消息队列 URL(支持多 Worker 之间的消息同步)
|
||||
SOCKETIO_MESSAGE_QUEUE = 'redis://localhost:6379/2' # 使用 db=2,与 session 和微信 session 分开
|
||||
# 注意:如果只用单 Worker,可以不配置 message_queue
|
||||
SOCKETIO_MESSAGE_QUEUE = os.environ.get('SOCKETIO_REDIS_URL', 'redis://localhost:6379/2')
|
||||
|
||||
# 检测是否需要启用消息队列(多 Worker 模式需要)
|
||||
_use_message_queue = os.environ.get('SOCKETIO_USE_QUEUE', 'false').lower() == 'true'
|
||||
|
||||
socketio = SocketIO(
|
||||
app,
|
||||
cors_allowed_origins=["http://localhost:3000", "http://127.0.0.1:3000", "http://localhost:5173",
|
||||
"https://valuefrontier.cn", "http://valuefrontier.cn"],
|
||||
async_mode=_async_mode,
|
||||
message_queue=SOCKETIO_MESSAGE_QUEUE, # 启用 Redis 消息队列,支持多 Worker
|
||||
message_queue=SOCKETIO_MESSAGE_QUEUE if _use_message_queue else None,
|
||||
logger=True,
|
||||
engineio_logger=False,
|
||||
ping_timeout=120, # 心跳超时时间(秒),客户端120秒内无响应才断开
|
||||
ping_interval=25 # 心跳检测间隔(秒),每25秒发送一次ping
|
||||
)
|
||||
print(f"✅ Flask-SocketIO 已配置 Redis 消息队列,支持多 Worker")
|
||||
if _use_message_queue:
|
||||
print(f"✅ Flask-SocketIO 已配置 Redis 消息队列: {SOCKETIO_MESSAGE_QUEUE}")
|
||||
else:
|
||||
print(f"📡 Flask-SocketIO 单 Worker 模式(无消息队列)")
|
||||
|
||||
|
||||
@login_manager.user_loader
|
||||
|
||||
Reference in New Issue
Block a user