zoukankan      html  css  js  c++  java
  • itchat监听微信撤回消息

    import itchat
    from itchat.content import *
    import re
    msg_infomation = {}
    # 监听发送消息
    @itchat.msg_register([TEXT])
    def handle_receive_msg(msg):
        print(msg)
        msg_from = itchat.search_friends(userName=msg["FromUserName"])["NickName"]
        print(msg_from)
        # 获取元素中需要的信息
        msg_time = msg["CreateTime"]
        msg_id = msg["MsgId"]
        msg_content = msg["Text"]
        # 把消息放入全局字典当中
        msg_infomation.update(
            {msg_id:{
                "msg_from":msg_from,
                "msg_time":msg_time,
                "msg_content":msg_content
            }
            }
        )
        print(msg_infomation)
    # 监听撤回消息
    @itchat.msg_register([NOTE])
    def infomation(msg):
        print(msg)
        content = msg.get("Content")
        print(content)
        if "撤回了一条消息" in content:
            print(1, content)
            old_msg_id = re.search("<msgid>(.*?)</msgid>", msg["Content"]).group(1)
            print(old_msg_id)
            print(msg_infomation.get(old_msg_id))
    # 微信登录操作
    itchat.auto_login(hotReload=True)
    # 保证程序一直运行
    itchat.run()
    
    # 课后作业:把未完成的完成
  • 相关阅读:
    lombok的介绍及使用
    java后端导入excel将数据写入数据库
    java后端导出excel表格
    eclipse maven打war包
    java后端树形菜单使用递归方法
    mybatis一对多查询
    @transactional作用和事务
    zookeeper安装
    Solr单机版安装
    jstat 简介(2)
  • 原文地址:https://www.cnblogs.com/zhangboblogs/p/10108584.html
Copyright © 2011-2022 走看看