From e0d4c4beff4fb717b65863ff6bf800358b7c6901 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Fri, 19 Apr 2024 16:28:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20base=20wxmp,=20wx=E6=97=A0=E9=9C=80?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E5=9C=A8conf=E6=8C=87=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/utils/wx.py | 13 +++++++------ apps/utils/wxmp.py | 12 ++++++------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/apps/utils/wx.py b/apps/utils/wx.py index 350a7cfb..4945aeff 100644 --- a/apps/utils/wx.py +++ b/apps/utils/wx.py @@ -22,11 +22,12 @@ class WxClient: 微信公众号相关 """ - def __init__(self, app_id=settings.WX_APPID, - app_secret=settings.WX_APPSECRET) -> None: - if settings.WX_ENABLED: - self.app_id = app_id - self.app_secret = app_secret + def __init__(self, app_id='', + app_secret='') -> None: + self.wx_enabled = getattr(settings, 'WX_ENABLED', False) + if self.wx_enabled: + self.app_id = app_id if app_id else getattr(settings, 'WX_APPID', False) + self.app_secret = app_secret if app_id else getattr(settings, 'WX_APPSECRET', False) self.isRuning = True self.token = None # 普通token self.t = None # 线程 @@ -58,7 +59,7 @@ class WxClient: def request(self, url: str, method: str, params=dict(), json=dict(), timeout=10, file_path_rela=None, raise_exception=True): - if not settings.WX_ENABLED: + if not self.wx_enabled: raise ParseError('微信公众号未启用') self.log = {"requested_at": now(), "id": uuid.uuid4(), "path": url, "method": method, "params": params, "body": json, "target": "wx", "result": 10} diff --git a/apps/utils/wxmp.py b/apps/utils/wxmp.py index f73df0ad..efd5cf6d 100644 --- a/apps/utils/wxmp.py +++ b/apps/utils/wxmp.py @@ -20,17 +20,17 @@ class WxmpClient: 微信小程序相关 """ - def __init__(self, app_id=settings.WXMP_APPID, - app_secret=settings.WXMP_APPSECRET) -> None: + def __init__(self, app_id='', app_secret='') -> None: + self.wxmp_enabled = getattr(settings, 'WXMP_ENABLED', False) self.app_id, self.app_secret = None, None - if settings.WXMP_ENABLED: - self.app_id = app_id - self.app_secret = app_secret + if self.wxmp_enabled: + self.app_id = app_id if app_id else getattr(settings, 'WXMP_APPID', False) + self.app_secret = app_secret if app_secret else getattr(settings, 'WXMP_APPSECRET', False) self.log = {} def request(self, url: str, method: str, params=dict(), json=dict(), timeout=10, file_path_rela=None, raise_exception=True): - if not settings.WX_ENABLED: + if not self.wxmp_enabled: raise ParseError('微信小程序未启用') self.log = {"requested_at": now(), "id": uuid.uuid4(), "path": url, "method": method, "params": params, "body": json, "target": "wx", "result": 10}