forked from vincenting/weChat-python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.py
59 lines (54 loc) · 1.57 KB
/
client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# coding=utf-8
__author__ = 'Vincent Ting'
from base import BaseClient
class Client(BaseClient):
def sendTextMsg(self, sendTo, content):
"""
给用户发送文字内容,成功返回True,使用时注意两次发送间隔,不能少于2s
:param sendTo:
:param content:
:return:
"""
msg = self._sendMsg(sendTo, {
'type': 1,
'content': content
})
return msg == 'ok'
def sendImgMsg(self, sendTo, img):
"""
主动推送图片信息
:param sendTo:
:param img:图片文件路径
:return:
"""
file_id = self._uploadImg(img)
msg = self._sendMsg(sendTo, {
'type': 2,
'content': '',
'fid': file_id,
'fileid': file_id
})
self._delImg(file_id)
return msg == 'ok'
def sendAppMsg(self, sendTo, title, content, img, digest='', sourceurl=''):
"""
主动推送图文
:param sendTo:
:param title: 标题
:param content: 正文,允许html
:param img:
:param digest: 摘要
:param sourceurl: 来源地址
:return:
"""
file_id = self._uploadImg(img)
self._addAppMsg(title, content, file_id, digest, sourceurl)
app_msg_id = self._getAppMsgId()
msg = self._sendMsg(sendTo, {
'type': 10,
'fid': app_msg_id,
'appmsgid': app_msg_id
})
self._delImg(file_id)
self._delAppMsg(app_msg_id)
return msg == 'ok'