码迷,mamicode.com
首页 > 微信 > 详细

itchat发送微信消息

时间:2020-03-29 23:55:32      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:b2b   friend   localtime   二维   com   重载   type   register   nbsp   

1.1 微信机器人自动回复消息

  1、运行程序,会弹出二维码,扫描授权后即可实现自动回复信息 参考01  参考02

技术图片
#coding=utf8
import itchat, time
from itchat.content import *

@itchat.msg_register([TEXT, MAP, CARD, NOTE, SHARING])
def text_reply(msg):
    itchat.send(%s: %s % (msg[Type], msg[Text]), msg[FromUserName])

@itchat.msg_register([PICTURE, RECORDING, ATTACHMENT, VIDEO])
def download_files(msg):
    msg[Text](msg[FileName])
    return @%s@%s % ({Picture: img, Video: vid}.get(msg[Type], fil), msg[FileName])

@itchat.msg_register(FRIENDS)
def add_friend(msg):
    itchat.add_friend(**msg[Text]) # 该操作会自动将新好友的消息录入,不需要重载通讯录
    itchat.send_msg(Nice to meet you!, msg[RecommendInfo][UserName])

@itchat.msg_register(TEXT, isGroupChat=True)
def text_reply(msg):
    if msg[isAt]:
        itchat.send(u@%s\u2005I received: %s % (msg[ActualNickName], msg[Content]), msg[FromUserName])

itchat.auto_login(True)
itchat.run()
微信自动回复
技术图片
#coding=utf8
import itchat,time

# 自动回复
# 封装好的装饰器,当接收到的消息是Text,即文字消息
@itchat.msg_register(Text)
def text_reply(msg):
    # 当消息不是由自己发出的时候
    if not msg[FromUserName] == myUserName:
        # 发送一条提示给文件助手
        itchat.send_msg(u"[%s]收到好友@%s 的信息:%s\n" %
                        (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(msg[CreateTime])),
                         msg[User][NickName],
                         msg[Text]), filehelper)
        # 回复给好友
        return u[自动回复]您好,我现在有事不在,一会再和您联系。\n已经收到您的的信息:%s\n % (msg[Text])

if __name__ == __main__:
    itchat.auto_login()

    # 获取自己的UserName
    myUserName = itchat.get_friends(update=True)[0]["UserName"]
    itchat.run()
微信自动回复方法2

 

itchat发送微信消息

标签:b2b   friend   localtime   二维   com   重载   type   register   nbsp   

原文地址:https://www.cnblogs.com/jiaxinzhu/p/12595940.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!