From 89d49d157a3ee5b3ddb99bdf029af78f1d6ea792 Mon Sep 17 00:00:00 2001 From: Henry Au-Yeung Ho Nam Date: Mon, 29 May 2017 09:54:27 +0800 Subject: [PATCH] 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 --- itchat/__init__.py | 1 + itchat/components/messages.py | 15 +++++++++++++++ itchat/config.py | 4 ++-- itchat/core.py | 9 +++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/itchat/__init__.py b/itchat/__init__.py index dfc19acd..256fc721 100644 --- a/itchat/__init__.py +++ b/itchat/__init__.py @@ -51,6 +51,7 @@ def new_instance(): send_image = originInstance.send_image send_video = originInstance.send_video send = originInstance.send +revoke = originInstance.revoke # components.hotreload dump_login_status = originInstance.dump_login_status load_login_status = originInstance.load_login_status diff --git a/itchat/components/messages.py b/itchat/components/messages.py index 8f00bab1..b0f10b20 100644 --- a/itchat/components/messages.py +++ b/itchat/components/messages.py @@ -21,6 +21,7 @@ def load_messages(core): core.send_image = send_image core.send_video = send_video core.send = send + core.revoke = revoke def get_download_fn(core, url, msgId): def download_fn(downloadDir=None): @@ -506,3 +507,17 @@ def send(self, msg, toUserName=None, mediaId=None): else: r = self.send_msg(msg, toUserName) return r + +def revoke(self, msgId, toUserName, localId=None): + url = '%s/webwxrevokemsg' % self.loginInfo['url'] + data = { + 'BaseRequest': self.loginInfo['BaseRequest'], + "ClientMsgId": localId or str(time.time() * 1e3), + "SvrMsgId": msgId, + "ToUserName": toUserName} + headers = { + 'ContentType': 'application/json; charset=UTF-8', + 'User-Agent' : config.USER_AGENT } + r = self.s.post(url, headers=headers, + data=json.dumps(data, ensure_ascii=False).encode('utf8')) + return ReturnValue(rawResponse=r) diff --git a/itchat/config.py b/itchat/config.py index f174c644..173f77ac 100644 --- a/itchat/config.py +++ b/itchat/config.py @@ -1,10 +1,10 @@ import os, platform -VERSION = '1.3.6' +VERSION = '1.3.7' BASE_URL = 'https://login.weixin.qq.com' OS = platform.system() #Windows, Linux, Darwin DIR = os.getcwd() DEFAULT_QR = 'QR.png' -TIMEOUT = (10, 30) +TIMEOUT = (10, 60) 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' diff --git a/itchat/core.py b/itchat/core.py index ba384ced..2b39d933 100644 --- a/itchat/core.py +++ b/itchat/core.py @@ -369,6 +369,15 @@ def send(self, msg, toUserName=None, mediaId=None): it is defined in components/messages.py ''' raise NotImplementedError() + def revoke(self, msgId, toUserName, localId=None): + ''' revoke message with its and msgId + for options + - msgId: message Id on server + - toUserName: 'UserName' key of friend dict + - localId: message Id at local (optional) + it is defined in components/messages.py + ''' + raise NotImplementedError() def dump_login_status(self, fileDir=None): ''' dump login status to a specific file for option