微信發送功能:
import itchat itchat.auto_login(enableCmdQR=True, hotReload=True) #登陸 二維碼 to_name1 = itchat.search_friends(name='微信的名字或備注名字') print(to_name1) #itchat.send('你好~', toUserName=to_name1[0]['UserName']) #發送文字 file_img = '../test.PNG' itchat.send_image(file_img,toUserName=to_name1[0]['UserName']) #發送圖片 file_text = '../test.PNG' itchat.send_file(file_text,toUserName=to_name1[0]['UserName']) #發送文件
微信自動回復:
#coding=utf8 import itchat import time # 自動回復 # 封裝好的裝飾器,當接收到的消息是Text,即文字消息 @itchat.msg_register('Text') def text_reply(msg): # 當消息不是由自己發出的時候 if not msg['FromUserName'] == myUserName: # 發送一條提示給文件助手 # 回復給好友 return u'&***自動回復***&\n啦啦啦啦啦啦\n。。。。。' #return u'hhh' if __name__ == '__main__': itchat.auto_login(hotReload=True)
微信定時發送:
import itchat from apscheduler.schedulers.blocking import BlockingScheduler import time # 發送信息 def send_msg(): user_info = itchat.search_friends(name='cookie') if len(user_info) > 0: user_name = user_info[0]['UserName'] itchat.send_msg('test22!', toUserName=user_name) def send_msg1(): user_info = itchat.search_friends(name='區鈞亮') if len(user_info) > 0: user_name = user_info[0]['UserName'] itchat.send_msg('臭弟弟,起床學習啦', toUserName=user_name) def after_login(): print("test") for i in range(0,30): sched.add_job(send_msg, 'cron', year=2020, month=12, day=11, hour=16, minute=21, second=i) print("test") sched.start() def after_logout(): sched.shutdown() if __name__ == '__main__': sched = BlockingScheduler() itchat.auto_login( hotReload=True,loginCallback=after_login, exitCallback=after_login) itchat.run()
微信遙控電腦功能:
import itchat from itchat.content import * import os @itchat.msg_register(TEXT) #如果接收的是文字 def text_reply(msg): #reply_text = msg.text.replace('嗎?','!') #替換 if msg.text == "打開微信": #遙控打開微信 cmd = 'start D:\weixin\WeChat\WeChat.exe' # res = os.popen(cmd) # output_str = res.read() # 獲得輸出字符串 # print(output_str) os.system(cmd) return "已經打開!" return "未配置指令,無法識別" itchat.auto_login(enableCmdQR=True, hotReload=True) itchat.run()