zoukankan      html  css  js  c++  java
  • 微信自动回复

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

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

  • 相关阅读:
    中国黑客传说:游走在黑暗中的精灵
    智能硬件安全入门
    迈克菲:2016年的八大网络安全威胁
    走进科学之WAF(Web Appllication Firewall)篇
    从对SAE的一次授权安全评估浅谈云安全
    沟通的艺术,心理学与生活,学会提问
    知道创宇研发技能表v3.0
    SYN Cookie的原理和实现
    1043. 输出PATest(20)
    1042. 字符统计(20)
  • 原文地址:https://www.cnblogs.com/xqnq2007/p/8232873.html
Copyright © 2011-2022 走看看