1.1 微信機器人自動回覆消息
一、運行程序,會彈出二維碼,掃描受權後便可實現自動回覆信息 參考01 參考02html
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
#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()
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
#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()