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