update pay ui
This commit is contained in:
42
app.py
42
app.py
@@ -3571,6 +3571,28 @@ def register_with_email():
|
||||
return jsonify({'success': False, 'error': '注册失败,请重试'}), 500
|
||||
|
||||
|
||||
def _safe_http_get(url, params=None, timeout=10):
|
||||
"""安全的 HTTP GET 请求(绕过 eventlet DNS 问题)
|
||||
|
||||
Eventlet 的 greendns 可能无法解析某些域名,使用 tpool 在原生线程中执行请求
|
||||
"""
|
||||
def _do_request():
|
||||
return requests.get(url, params=params, timeout=timeout)
|
||||
|
||||
try:
|
||||
# 检查是否在 eventlet 环境中
|
||||
import eventlet
|
||||
if hasattr(eventlet, 'is_monkey_patched') and eventlet.is_monkey_patched('socket'):
|
||||
# 使用 tpool 在原生线程中执行,绕过 eventlet 的 DNS
|
||||
from eventlet import tpool
|
||||
return tpool.execute(_do_request)
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
# 非 eventlet 环境,直接请求
|
||||
return _do_request()
|
||||
|
||||
|
||||
def get_wechat_access_token(code, appid=None, appsecret=None):
|
||||
"""通过code获取微信access_token
|
||||
|
||||
@@ -3588,16 +3610,20 @@ def get_wechat_access_token(code, appid=None, appsecret=None):
|
||||
}
|
||||
|
||||
try:
|
||||
response = requests.get(url, params=params, timeout=10)
|
||||
print(f"🔄 正在获取微信 access_token... (appid={params['appid'][:8]}...)")
|
||||
response = _safe_http_get(url, params=params, timeout=15)
|
||||
data = response.json()
|
||||
|
||||
if 'errcode' in data:
|
||||
print(f"WeChat access token error: {data}")
|
||||
print(f"❌ WeChat access token error: {data}")
|
||||
return None
|
||||
|
||||
print(f"✅ 成功获取 access_token: openid={data.get('openid', 'N/A')}")
|
||||
return data
|
||||
except Exception as e:
|
||||
print(f"WeChat access token request error: {e}")
|
||||
print(f"❌ WeChat access token request error: {type(e).__name__}: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
return None
|
||||
|
||||
|
||||
@@ -3611,12 +3637,13 @@ def get_wechat_userinfo(access_token, openid):
|
||||
}
|
||||
|
||||
try:
|
||||
response = requests.get(url, params=params, timeout=10)
|
||||
print(f"🔄 正在获取微信用户信息... (openid={openid})")
|
||||
response = _safe_http_get(url, params=params, timeout=15)
|
||||
response.encoding = 'utf-8' # 明确设置编码为UTF-8
|
||||
data = response.json()
|
||||
|
||||
if 'errcode' in data:
|
||||
print(f"WeChat userinfo error: {data}")
|
||||
print(f"❌ WeChat userinfo error: {data}")
|
||||
return None
|
||||
|
||||
# 确保nickname字段的编码正确
|
||||
@@ -3629,9 +3656,12 @@ def get_wechat_userinfo(access_token, openid):
|
||||
print(f"Nickname encoding error: {e}, using default")
|
||||
data['nickname'] = '微信用户'
|
||||
|
||||
print(f"✅ 成功获取用户信息: nickname={data.get('nickname', 'N/A')}")
|
||||
return data
|
||||
except Exception as e:
|
||||
print(f"WeChat userinfo request error: {e}")
|
||||
print(f"❌ WeChat userinfo request error: {type(e).__name__}: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
return None
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user