Skip to content

Commit

Permalink
Add message revoke (littlecodersh#370)
Browse files Browse the repository at this point in the history
* Link message revoke function to itchat
* Add message revoke function
* Update core.py
  • Loading branch information
Sphynx-HenryAY authored and littlecodersh committed May 29, 2017
1 parent bb853df commit 52eb3ce
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions itchat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions itchat/components/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
4 changes: 2 additions & 2 deletions itchat/config.py
Original file line number Diff line number Diff line change
@@ -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'
9 changes: 9 additions & 0 deletions itchat/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 52eb3ce

Please sign in to comment.