• 微信自动回复


    http://blog.csdn.net/mdpsdhr/article/details/61195817

    #coding=utf-8
    import itchat
    from itchat.content import *
    
    @itchat.msg_register([PICTURE,TEXT])
    def simple_reply(msg):
        if msg['Type'] == TEXT:
            ReplyContent = 'I received message: '+msg['Content']
        if msg['Type'] == PICTURE:
            ReplyContent = 'I received picture: '+msg['FileName']
        itchat.send_msg('nice to meet you',msg['FromUserName'])
    itchat.auto_login()
    itchat.run()
    • 这里注册了两个消息类型,文本和图片(表情),当微信接收到这两个消息时就会进入注册的函数simple_reply,msg是一个字典类型里面包含了消息数据包,有发送者、接收者、消息类型、消息内容等超多的信息
    • itchat要注册消息类型,比如注册了TEXT(itchat.content.text),就会接收文本消息,其他消息不会触发函数。消息类型见库中的content.py文件
    • 消息类型判断,msg[‘Type’]
    • 消息发起者,msg[‘FromUserName’]
    • 消息接收者,msg[‘ToUserName’]
    • 文本消息,msg[‘Content’]
    • 文件名字,msg[‘FileName’],注:如果是自带的表情就会显示表情
    • 发送文件时,文件名字应该是unicode编码(这是python内部默认的编码风格) 
    • 如果想要指定向某人发送信息,
    • itchat.send_msg('nice to meet you',msg['FromUserName'])里面的
      msg['FromUserName']替换成要发送到人的UserName
    • #coding=utf-8
      import itchat
      from itchat.content import *
      
      # @itchat.msg_register([PICTURE,TEXT])
      # def simple_reply(msg):
      #     if msg['Type'] == TEXT:
      #         ReplyContent = 'I received message: '+msg['Content']
      #     if msg['Type'] == PICTURE:
      #         ReplyContent = 'I received picture: '+msg['FileName']
      #     itchat.send_msg('nice to meet you',msg['FromUserName'])
      itchat.auto_login(hotReload=True)
      #itchat.run()
      friends_info = itchat.get_friends(update=True)
      for i in friends_info:
          print(i)  #打印每个好友的信息
      itchat.send_msg('nice to meet you','******')

      上面的程序可打印出每个好友的信息

  • 相关阅读:
    关于分布式系统中雷同集群技术及原理,你知道多少?
    如何在PHP中进行会话处理?
    PHP的isset()、is_null、empty()使用总结
    Mycatweb的介绍与搭建
    企业如何部署开源邮箱系统?
    企业如何选择合适的邮箱系统?
    Ansible原理与安装部署
    gRPC的简介与实例详解
    高效的性能测试工具-wrk
    轻松玩转windows之wamp开发环境部署
  • 原文地址:https://www.cnblogs.com/xqnq2007/p/8232873.html
Copyright © 2020-2023  润新知