Skip to content

Commit 89d49d1

Browse files
Sphynx-HenryAYlittlecodersh
authored andcommitted
Add message revoke (#370)
* Link message revoke function to itchat this is my first uploading code using github, apologize if it caused any inconvenience. * Add message revoke function function added at the end of file, after the position of send * Update core.py
1 parent bb853df commit 89d49d1

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

itchat/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def new_instance():
5151
send_image = originInstance.send_image
5252
send_video = originInstance.send_video
5353
send = originInstance.send
54+
revoke = originInstance.revoke
5455
# components.hotreload
5556
dump_login_status = originInstance.dump_login_status
5657
load_login_status = originInstance.load_login_status

itchat/components/messages.py

+15
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def load_messages(core):
2121
core.send_image = send_image
2222
core.send_video = send_video
2323
core.send = send
24+
core.revoke = revoke
2425

2526
def get_download_fn(core, url, msgId):
2627
def download_fn(downloadDir=None):
@@ -506,3 +507,17 @@ def send(self, msg, toUserName=None, mediaId=None):
506507
else:
507508
r = self.send_msg(msg, toUserName)
508509
return r
510+
511+
def revoke(self, msgId, toUserName, localId=None):
512+
url = '%s/webwxrevokemsg' % self.loginInfo['url']
513+
data = {
514+
'BaseRequest': self.loginInfo['BaseRequest'],
515+
"ClientMsgId": localId or str(time.time() * 1e3),
516+
"SvrMsgId": msgId,
517+
"ToUserName": toUserName}
518+
headers = {
519+
'ContentType': 'application/json; charset=UTF-8',
520+
'User-Agent' : config.USER_AGENT }
521+
r = self.s.post(url, headers=headers,
522+
data=json.dumps(data, ensure_ascii=False).encode('utf8'))
523+
return ReturnValue(rawResponse=r)

itchat/config.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import os, platform
22

3-
VERSION = '1.3.6'
3+
VERSION = '1.3.7'
44
BASE_URL = 'https://login.weixin.qq.com'
55
OS = platform.system() #Windows, Linux, Darwin
66
DIR = os.getcwd()
77
DEFAULT_QR = 'QR.png'
8-
TIMEOUT = (10, 30)
8+
TIMEOUT = (10, 60)
99

1010
USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36'

itchat/core.py

+9
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,15 @@ def send(self, msg, toUserName=None, mediaId=None):
369369
it is defined in components/messages.py
370370
'''
371371
raise NotImplementedError()
372+
def revoke(self, msgId, toUserName, localId=None):
373+
''' revoke message with its and msgId
374+
for options
375+
- msgId: message Id on server
376+
- toUserName: 'UserName' key of friend dict
377+
- localId: message Id at local (optional)
378+
it is defined in components/messages.py
379+
'''
380+
raise NotImplementedError()
372381
def dump_login_status(self, fileDir=None):
373382
''' dump login status to a specific file
374383
for option

0 commit comments

Comments
 (0)