您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

22 行
893B

  1. import threading
  2. import time
  3. from wechatpy.enterprise import WeChatClient
  4. class WechatComAppClient(WeChatClient):
  5. def __init__(self, corp_id, secret, access_token=None, session=None, timeout=None, auto_retry=True):
  6. super(WechatComAppClient, self).__init__(corp_id, secret, access_token, session, timeout, auto_retry)
  7. self.fetch_access_token_lock = threading.Lock()
  8. def fetch_access_token(self): # 重载父类方法,加锁避免多线程重复获取access_token
  9. with self.fetch_access_token_lock:
  10. access_token = self.session.get(self.access_token_key)
  11. if access_token:
  12. if not self.expires_at:
  13. return access_token
  14. timestamp = time.time()
  15. if self.expires_at - timestamp > 60:
  16. return access_token
  17. return super().fetch_access_token()