feat: UFO H5 服务号 OAuth 登录与同商户公众号 JSAPI 支付

This commit is contained in:
XingQue
2026-07-30 00:12:37 +08:00
parent 531639731a
commit 148a35f04b
11 changed files with 449 additions and 64 deletions

View File

@@ -14,7 +14,11 @@ from jituan.constants import SUPER_ADMIN_PHONES, ADMIN_ROLE_LABELS, CLUB_ID_DEFA
from jituan.models import Club, AdminAssignment
from jituan.services.admin_context import build_admin_club_context, is_kefu_backend_account, can_manage_admin_assignments
from jituan.services.kefu_menu import build_menu_access_payload
from jituan.services.wechat_login import login_or_register_by_club, refresh_wx_openid_binding
from jituan.services.wechat_login import (
login_or_register_by_club,
login_or_register_by_official_oauth,
refresh_wx_openid_binding,
)
from jituan.services.caiwu_stats import build_caiwu_payload
from jituan.services.szxx_stats import build_szxx_payload
from jituan.services.admin_assignments import (
@@ -79,6 +83,39 @@ class ClubWechatLoginView(APIView):
}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
class ClubWechatOAuthLoginView(APIView):
"""
服务号网页授权登录H5 UniApp
POST /jituan/auth/wechat-oauth-login
body: { code, club_id? }
不改动 wechat-login仅新增本接口。
"""
throttle_classes = [AnonRateThrottle]
permission_classes = [AllowAny]
def post(self, request):
code = (request.data.get('code') or '').strip()
club_id = (request.data.get('club_id') or '').strip() or None
if not code:
return Response({'code': 1, 'msg': '微信授权码不能为空', 'data': None},
status=status.HTTP_400_BAD_REQUEST)
try:
data, err = login_or_register_by_official_oauth(
code, club_id=club_id, client_ip=_client_ip(request),
)
if err:
return Response({'code': 2, 'msg': f'微信登录失败: {err}', 'data': None},
status=status.HTTP_400_BAD_REQUEST)
return Response({'code': 0, 'msg': '登录成功', 'data': data})
except Exception as e:
logger.exception('ClubWechatOAuthLoginView 异常')
return Response({
'code': 99,
'msg': f'登录异常: {type(e).__name__}: {e}',
'data': None,
}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
class ClubWxBindRefreshView(APIView):
"""
已登录用户静默刷新当前小程序 openid 绑定(支付前 AppID/openid 对齐)。