diff --git a/itchat/__init__.py b/itchat/__init__.py index 56cac98..4beec48 100644 --- a/itchat/__init__.py +++ b/itchat/__init__.py @@ -3,7 +3,7 @@ import time from .client import client from . import content # this is for creating pyc -__version__ = '1.1.17' +__version__ = '1.1.18' __client = client() HOT_RELOAD = False @@ -58,6 +58,7 @@ def get_batch_contract(groupUserName): return __client.update_chatroom(groupUser # <<< # if toUserName is set to None, msg will be sent to yourself +def send_raw_msg(msgType, content, toUserName): return __client.send_raw_msg(msgType, content, toUserName) def send_msg(msg = 'Test Message', toUserName = None): return __client.send_msg(msg, toUserName) def send_file(fileDir, toUserName): return __client.send_file(fileDir, toUserName) def send_video(fileDir, toUserName): return __client.send_video(fileDir, toUserName) diff --git a/itchat/client.py b/itchat/client.py index d5dcb76..0afd0e5 100644 --- a/itchat/client.py +++ b/itchat/client.py @@ -539,21 +539,24 @@ class client(object): in msg['Content'] or msg['Content'].endswith(atFlag)) - def send_msg(self, msg ='Test Message', toUserName = None): + def send_raw_msg(self, msgType, content, toUserName): url = '%s/webwxsendmsg'%self.loginInfo['url'] payloads = { 'BaseRequest': self.loginInfo['BaseRequest'], 'Msg': { - 'Type': 1, - 'Content': msg, + 'Type': msgType, + 'Content': content, 'FromUserName': self.storageClass.userName, 'ToUserName': (toUserName if toUserName else self.storageClass.userName), 'LocalID': int(time.time()), 'ClientMsgId': int(time.time()), }, } headers = { 'ContentType': 'application/json; charset=UTF-8' } - r = self.s.post(url, data = json.dumps(payloads, ensure_ascii = False).encode('utf8'), headers = headers) - return r.json()['BaseResponse']['Ret'] == 0 + r = self.s.post(url, data=json.dumps(payloads, ensure_ascii=False).encode('utf8'), headers=headers) + return r.json() + def send_msg(self, msg='Test Message', toUserName=None): + r = self.send_raw_msg(1, msg, toUserName) + return r['BaseResponse']['Ret'] == 0 def __upload_file(self, fileDir, isPicture = False, isVideo = False): if not tools.check_file(fileDir): return url = self.loginInfo.get('fileUrl', self.loginInfo['url']) + \