From 19709c7da38e538e998c965ff460dbe329b5cde8 Mon Sep 17 00:00:00 2001 From: youngS Date: Tue, 7 Sep 2021 20:28:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=8E=B7=E5=8F=96=E5=BE=AE?= =?UTF-8?q?=E4=BF=A1token=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fir_ser/api/utils/mp/wechat.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/fir_ser/api/utils/mp/wechat.py b/fir_ser/api/utils/mp/wechat.py index 4c461d1..bea1f92 100644 --- a/fir_ser/api/utils/mp/wechat.py +++ b/fir_ser/api/utils/mp/wechat.py @@ -16,11 +16,12 @@ from api.utils.mp.utils import WxMsgCryptBase logger = logging.getLogger(__name__) wx_login_info = THIRDLOGINCONF.wx_official -def format_req_json(j_data,func,*args,**kwargs): - if j_data.get("errcode")==40001 or 'invalid credential' in j_data.get('errmsg',''): + +def format_req_json(j_data, func, *args, **kwargs): + if j_data.get("errcode") == 40001 or 'invalid credential' in j_data.get('errmsg', ''): logger.error(f"error j_data {j_data}") sync_wx_access_token(True) - return func(*args,**kwargs)[1] + return func(*args, **kwargs)[1] return j_data @@ -35,7 +36,7 @@ def sync_wx_access_token(force=False): return access_token_info -def get_wx_access_token_cache(c_count=1,): +def get_wx_access_token_cache(c_count=1, ): if c_count > 10: return '' wx_access_token_key = CACHE_KEY_TEMPLATE.get("wx_access_token_key") @@ -101,7 +102,7 @@ def make_wx_login_qrcode(scene_str='web.login', expire_seconds=600): "action_info": {"scene": {"scene_str": scene_str}}} req = requests.post(t_url, json=data) if req.status_code == 200: - return True, format_req_json(req.json(),make_wx_login_qrcode,scene_str,expire_seconds) + return True, format_req_json(req.json(), make_wx_login_qrcode, scene_str, expire_seconds) logger.error(f"make wx login qrcode failed {req.status_code} {req.text}") return False, req.text @@ -110,7 +111,7 @@ def get_userinfo_from_openid(open_id): t_url = f'https://api.weixin.qq.com/cgi-bin/user/info?access_token={get_wx_access_token_cache()}&openid={open_id}&lang=zh_CN' req = requests.get(t_url) if req.status_code == 200: - return True, format_req_json(req.json(),get_userinfo_from_openid,open_id) + return True, format_req_json(req.json(), get_userinfo_from_openid, open_id) logger.error(f"get userinfo from openid failed {req.status_code} {req.text}") return False, req.text