def send_raw_msg(self, raw_type, raw_content, uri=None, msg_ext=None): """ 以原始格式发送其他类型的消息。 :param int raw_type: 原始的整数消息类型 :param str raw_content: 原始的消息内容 :param str uri: 请求路径,默认为 '/webwxsendmsg' :param dict msg_ext: 消息的扩展属性 (会被更新到 `Msg` 键中) :rtype: :class:`wxpy.SentMessage` 例如,发送好友或公众号的名片:: my_friend.send_raw_msg( # 名片的原始消息类型 raw_type=42, # 注意 `username` 在这里应为微信 ID,且被发送的名片必须为自己的好友 raw_content='<msg username="******" nickname="wxpy 机器人"/>' ) """ logger.info('sending raw msg to {}'.format(self)) uri = uri or '/webwxsendmsg' from wxpy.utils import BaseRequest req = BaseRequest(self.bot, uri=uri) msg = { 'Type': raw_type, 'Content': raw_content, 'FromUserName': self.bot.self.user_name, 'ToUserName': self.user_name, 'LocalID': int(time.time() * 1e4), 'ClientMsgId': int(time.time() * 1e4), } if msg_ext: msg.update(msg_ext) req.data.update({'Msg': msg, 'Scene': 0}) # noinspection PyUnresolvedReferences return req.post(), { 'raw_type': raw_type, 'raw_content': raw_content, 'uri': uri, 'msg_ext': msg_ext, }
def send_raw_msg(self, raw_type, raw_content, uri=None, msg_ext=None): """ 以原始格式发送其他类型的消息。 :param int raw_type: 原始的整数消息类型 :param str raw_content: 原始的消息内容 :param str uri: 请求路径,默认为 '/webwxsendmsg' :param dict msg_ext: 消息的扩展属性 (会被更新到 `Msg` 键中) :rtype: :class:`wxpy.SentMessage` 例如,好友名片:: from wxpy import * bot = Bot() @bot.register(msg_types=CARD) def reply_text(msg): msg.chat.send_raw_msg(msg.raw['MsgType'], msg.raw['Content']) """ logger.info('sending raw msg to {}'.format(self)) uri = uri or '/webwxsendmsg' from wxpy.utils import BaseRequest req = BaseRequest(self.bot, uri=uri) msg = { 'Type': raw_type, 'Content': raw_content, 'FromUserName': self.bot.self.user_name, 'ToUserName': self.user_name, 'LocalID': int(time.time() * 1e4), 'ClientMsgId': int(time.time() * 1e4), } if msg_ext: msg.update(msg_ext) req.data.update({'Msg': msg, 'Scene': 0}) # noinspection PyUnresolvedReferences return req.post(), { 'raw_type': raw_type, 'raw_content': raw_content, 'uri': uri, 'msg_ext': msg_ext, }
def recall(self): """ 撤回本条消息 (应为 2 分钟内发出的消息) """ logger.info('recalling msg:\n{}'.format(self)) from wxpy.utils import BaseRequest req = BaseRequest(self.bot, '/webwxrevokemsg') req.data.update({ "ClientMsgId": self.local_id, "SvrMsgId": str(self.id), "ToUserName": self.receiver.user_name, }) # noinspection PyUnresolvedReferences return req.post()
def mark_as_read(self): """ 消除当前聊天对象的未读提示小红点 """ from wxpy.utils import BaseRequest req = BaseRequest( bot=self.bot, # itchat 中的 pass_ticket 已经预先编码了 uri='/webwxstatusnotify?pass_ticket={}'.format( self.bot.core.loginInfo['pass_ticket'])) req.data.update({ 'ClientMsgId': int(time.time() * 1000), 'Code': 1, 'FromUserName': self.bot.self.user_name, 'ToUserName': self.user_name, }) logger.debug('marking {} as read'.format(self)) return req.request('POST')
def mark_as_read(self): """ 消除当前聊天对象的未读提示小红点 """ from wxpy.utils import BaseRequest req = BaseRequest( bot=self.bot, # itchat 中的 pass_ticket 已经预先编码了 uri='/webwxstatusnotify?pass_ticket={}'.format(self.bot.core.loginInfo['pass_ticket']) ) req.data.update({ 'ClientMsgId': int(time.time() * 1000), 'Code': 1, 'FromUserName': self.bot.self.user_name, 'ToUserName': self.user_name, }) logger.debug('marking {} as read'.format(self)) return req.request('POST')