From f8688159e0287b06294c8d1fefabf48f868f9efc Mon Sep 17 00:00:00 2001 From: zzlgreat Date: Thu, 25 Dec 2025 11:44:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E6=A0=87=E8=AE=B0=E7=BA=BFbu?= =?UTF-8?q?g=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app_vx.py | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/app_vx.py b/app_vx.py index 39dab040..ff03fe2d 100644 --- a/app_vx.py +++ b/app_vx.py @@ -935,7 +935,8 @@ def subscription_required(level='pro'): @subscription_required('pro') # 需要 Pro 或 Max 用户 @subscription_required('max') # 仅限 Max 用户 - 注意:此装饰器需要配合 使用 + 注意:返回 HTTP 200 状态码,但 code 字段为 403,以适配前端处理逻辑 + 前端通过 res.code 判断请求是否成功,code==200 为成功,其他为失败 """ from functools import wraps @@ -948,21 +949,28 @@ def subscription_required(level='pro'): is_active = current_info.get('is_active', False) if not is_active: + # 返回 HTTP 200,但 code 为 403,前端会显示 message 提示 return jsonify({ + 'code': 403, 'success': False, - 'error': '您的订阅已过期,请续费后继续使用', + 'message': '您的订阅已过期,请续费后继续使用', 'error_code': 'SUBSCRIPTION_EXPIRED', 'current_subscription': current_type, - 'required_subscription': level - }), 403 + 'required_subscription': level, + 'data': None + }) + level_name = 'Pro' if level == 'pro' else 'Max' + # 返回 HTTP 200,但 code 为 403,前端会显示 message 提示 return jsonify({ + 'code': 403, 'success': False, - 'error': f'此功能需要 {level.upper()} 或更高等级会员', + 'message': f'此功能仅对{level_name}会员开放,请升级会员后使用', 'error_code': 'SUBSCRIPTION_REQUIRED', 'current_subscription': current_type, - 'required_subscription': level - }), 403 + 'required_subscription': level, + 'data': None + }) return f(*args, **kwargs) @@ -975,6 +983,9 @@ def pro_or_max_required(f): """ 快捷装饰器:要求 Pro 或 Max 用户(小程序专用场景) 等同于 @subscription_required('pro') + + 注意:返回 HTTP 200 状态码,但 code 字段为 403,以适配前端处理逻辑 + 前端通过 res.code 判断请求是否成功,code==200 为成功,其他为失败 """ from functools import wraps @@ -984,14 +995,16 @@ def pro_or_max_required(f): current_info = _get_current_subscription_info() current_type = current_info.get('type', 'free') + # 返回 HTTP 200,但 code 为 403,前端会显示 message 提示 return jsonify({ + 'code': 403, 'success': False, - 'error': '小程序功能仅对 Pro 和 Max 会员开放', + 'message': '此功能仅对Pro/Max会员开放,请升级会员后使用', 'error_code': 'MINIPROGRAM_PRO_REQUIRED', 'current_subscription': current_type, 'required_subscription': 'pro', - 'message': '请升级到 Pro 或 Max 会员以使用小程序完整功能' - }), 403 + 'data': None + }) return f(*args, **kwargs) @@ -4380,6 +4393,7 @@ def api_login_email(): # 5. 事件详情-相关标的接口 @app.route('/api/event//related-stocks-detail', methods=['GET']) +@token_required @pro_or_max_required def api_event_related_stocks(event_id): """事件相关标的详情接口 - 仅限 Pro/Max 会员""" @@ -4876,6 +4890,7 @@ def get_minute_chart_data(stock_code): @app.route('/api/event//stock//detail', methods=['GET']) +@token_required @pro_or_max_required def api_stock_detail(event_id, stock_code): """个股详情接口 - 仅限 Pro/Max 会员"""