fix: 手机号认证按俱乐部 wx_appid 换 token,修复星之界 40013

This commit is contained in:
XingQue
2026-06-25 01:11:32 +08:00
parent 4714e2259b
commit cca53bbc96
2 changed files with 71 additions and 31 deletions

View File

@@ -9,8 +9,45 @@ logger = logging.getLogger(__name__)
WX_TOKEN_CACHE_KEY = 'wx_mini_access_token'
def invalidate_weixin_mini_access_token():
cache.delete(WX_TOKEN_CACHE_KEY)
def invalidate_weixin_mini_access_token(club_id=None):
if club_id:
cache.delete(f'{WX_TOKEN_CACHE_KEY}:{club_id}')
else:
cache.delete(WX_TOKEN_CACHE_KEY)
def get_club_mini_access_token(club_id=None, *, force_refresh=False):
"""
按俱乐部读取 wx_appid/wx_secret 获取 access_token多小程序上线必需
xq 缺配置时回退 settings其它俱乐部读 club 表。
"""
from jituan.constants import CLUB_ID_DEFAULT
from jituan.services.club_resolver import get_club_wx_credentials
club_id = club_id or CLUB_ID_DEFAULT
cache_key = f'{WX_TOKEN_CACHE_KEY}:{club_id}'
if not force_refresh:
token = cache.get(cache_key)
if token:
return token
if force_refresh:
cache.delete(cache_key)
appid, secret, _ = get_club_wx_credentials(club_id)
if not appid or not secret:
logger.error('俱乐部 %s 微信配置缺失: wx_appid/wx_secret 未设置', club_id)
return None
token, expires_in = _fetch_stable_token(appid, secret, force_refresh)
if not token:
token, expires_in = _fetch_legacy_token(appid, secret)
if token:
ttl = max(60, int(expires_in or 7200) - 200)
cache.set(cache_key, token, ttl)
return token
def get_weixin_mini_access_token(*, force_refresh=False):