From 2390397f1bc650b2288d40a1f469eb135326e51f Mon Sep 17 00:00:00 2001 From: nineven Date: Wed, 30 Mar 2022 13:30:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E4=BF=A1web=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E8=B7=B3=E8=BD=AC=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fir_ser/api/views/login_wx.py | 2 +- fir_ser/common/core/sysconfig.py | 10 +++++++++- fir_ser/common/libs/mp/wechat.py | 10 +++++++--- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/fir_ser/api/views/login_wx.py b/fir_ser/api/views/login_wx.py index dbb3beb..f4eaf66 100644 --- a/fir_ser/api/views/login_wx.py +++ b/fir_ser/api/views/login_wx.py @@ -206,7 +206,7 @@ class WeChatWebLoginView(APIView): if info and isinstance(info, dict): info.update({'w_type': 'web', 'to_user': wx_user_info.get('openid')}) set_wx_ticket_login_info_cache(state, info) - return redirect(Config.WEB_DOMAIN) + return redirect(Config.WECHAT_WEB_SUCCESS_REDIRECT_URI) return Response(ret.dict) diff --git a/fir_ser/common/core/sysconfig.py b/fir_ser/common/core/sysconfig.py index dd666dc..5dc71c6 100644 --- a/fir_ser/common/core/sysconfig.py +++ b/fir_ser/common/core/sysconfig.py @@ -64,7 +64,7 @@ class ConfigCacheBase(object): def get_value_from_db(self, key): data = SystemConfigSerializer(SystemConfig.objects.filter(enable=True, key=key).first()).data if re.findall('{{.*%s.*}}' % data['key'], data['value']): - logger.warning(f"get same render key. so get default value") + logger.warning(f"get same render key:{key}. so get default value") data['key'] = '' return data @@ -121,6 +121,14 @@ class ConfigCacheBase(object): def FILE_UPLOAD_DOMAIN(self): return self.get_value('FILE_UPLOAD_DOMAIN', self.API_DOMAIN) + @property + def WECHAT_WEB_SUCCESS_REDIRECT_URI(self): + return self.get_value('WECHAT_WEB_SUCCESS_REDIRECT_URI', self.WEB_DOMAIN) + + @property + def WECHAT_WEB_LOGIN_REDIRECT_DOMAIN(self): + return self.get_value('WECHAT_WEB_LOGIN_REDIRECT_DOMAIN') + class BaseConfCache(ConfigCacheBase): def __init__(self): diff --git a/fir_ser/common/libs/mp/wechat.py b/fir_ser/common/libs/mp/wechat.py index ebc25f4..1a1abc1 100644 --- a/fir_ser/common/libs/mp/wechat.py +++ b/fir_ser/common/libs/mp/wechat.py @@ -6,6 +6,7 @@ import json import logging import urllib +from urllib.parse import quote from hashlib import sha1 import requests @@ -572,9 +573,12 @@ class WxWebLogin(object): :return: """ # url = 'https://app.hehelucky.cn/api/v1/fir/server/wxweb' # 该url是前端页面,用户微信跳转,后端页面也行 - local_storage = LocalStorage(**Config.IOS_PMFILE_DOWNLOAD_DOMAIN) - url = f'{local_storage.get_base_url()}{reverse("mp.web.login")}' - encode_url = urllib.parse.quote(url, safe='/', encoding=None, errors=None) + redirect_domain = Config.WECHAT_WEB_LOGIN_REDIRECT_DOMAIN + if not redirect_domain: + local_storage = LocalStorage(**Config.IOS_PMFILE_DOWNLOAD_DOMAIN) + redirect_domain = local_storage.get_base_url() + url = f'{redirect_domain}{reverse("mp.web.login")}' + encode_url = quote(url, safe='/', encoding=None, errors=None) code_url = f'https://open.weixin.qq.com/connect/oauth2/authorize?appid={self.app_id}&redirect_uri={encode_url}&response_type=code&scope=snsapi_userinfo&state={state}#wechat_redirect ' return code_url