__init__.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # -*- coding: utf-8 -*-
  2. from __future__ import absolute_import, unicode_literals
  3. from wechatpy.client.base import BaseWeChatClient
  4. from wechatpy.enterprise.client import api
  5. class WeChatClient(BaseWeChatClient):
  6. API_BASE_URL = 'https://qyapi.weixin.qq.com/cgi-bin/'
  7. agent = api.WeChatAgent()
  8. appchat = api.WeChatAppChat()
  9. batch = api.WeChatBatch()
  10. chat = api.WeChatChat()
  11. department = api.WeChatDepartment()
  12. jsapi = api.WeChatJSAPI()
  13. material = api.WeChatMaterial()
  14. media = api.WeChatMedia()
  15. menu = api.WeChatMenu()
  16. message = api.WeChatMessage()
  17. misc = api.WeChatMisc()
  18. oauth = api.WeChatOAuth()
  19. service = api.WeChatService()
  20. shakearound = api.WeChatShakeAround()
  21. tag = api.WeChatTag()
  22. user = api.WeChatUser()
  23. external_contact = api.WeChatExternalContact()
  24. def __init__(self, corp_id, secret, access_token=None,
  25. session=None, timeout=None, auto_retry=True):
  26. super(WeChatClient, self).__init__(
  27. corp_id, access_token, session, timeout, auto_retry
  28. )
  29. self.corp_id = corp_id
  30. self.secret = secret
  31. @property
  32. def access_token_key(self):
  33. return '{0}_{1}_access_token'.format(self.corp_id, self.secret[:10])
  34. def fetch_access_token(self):
  35. """ Fetch access token"""
  36. return self._fetch_access_token(
  37. url='https://qyapi.weixin.qq.com/cgi-bin/gettoken',
  38. params={
  39. 'corpid': self.corp_id,
  40. 'corpsecret': self.secret
  41. }
  42. )