You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 satır
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()