• 微信自动回复


    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','******')

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

  • 相关阅读:
    (转)乐观的并发策略——基于CAS的自旋
    mysql避免插入重复数据
    Java_Web使用简单的批处理操作
    Java中jar命令详解
    使用文档注释(javadoc)
    APP和WEB元素定位方法
    RF(二)RF常用库介绍
    RF(一)RF的安装步骤
    javascript匿名函数及闭包深入理解及应用
    javascript简介
  • 原文地址:https://www.cnblogs.com/xqnq2007/p/8232873.html
Copyright © 2020-2023  润新知