# -*- coding: utf-8 -*- import itchat#安装pip install itchat import os#用cmd系统指令 from PIL import ImageGrab#截屏pip install pillow import cv2#摄像头pip install opencv-python @itchat.msg_register(['Text']) def message(msg): print(msg) ToUserName=msg['ToUserName'] data=msg['Text'] if ToUserName=='filehelper': if data=='关机': shutdown() if data=='截屏': screen() if data=='拍照': photo() def shutdown(): os.system('shutdown /s /t 0') def screen(fileName='screen.png'): im=ImageGrab.grab(fileName='screen.png') im.save(fileName) itchat.send_image(fileNmae,'filehelper') def photo(fileName='screen.png'): cap=cv2.VideoCapture(0)#读第一个摄像头 ret,img=cap.read() if ret: cv2.imwrite(fileName,img) itchat.send_image(fileName,'filehelper') else: itchat.send('摄像头不能用','filehelper') cap.release #登入并保存登入状态,实现第一次运行时扫码,一定时间内再次运行就不用扫码了,手机微信上将显示:网页微信已登入..... itchat.auto_login(hotReload=True) itchat.run()