├── MySmartPC.png ├── README.md ├── config.py ├── myChat.py ├── myChatService.py ├── mySqlite.py ├── test.db └── test.py /MySmartPC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chinasilva/MySmartPc/58eb9cd44042ccf7208b99f43309902c824808e2/MySmartPC.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |  2 | ![mahua](MySmartPC.png) 3 | 4 | ## MySmartPC是什么? 5 | 利用微信文件助手,进行语音或者文字控制电脑,做任何想做的事情 6 | 7 | 8 | ## MySmartPC目前有哪些功能? 9 | 10 | * 电脑屏幕截屏,并发送到手机 11 | * 使用摄像头拍照,并发送到手机 12 | * 输入文字打开浏览器进行百度 13 | * 语音打开浏览器进行百度 14 | * 手动打开电脑软件(需要在配置文件中进行位置配置) 15 | * 语音打开电脑软件(需要在配置文件中进行位置配置) 16 | * 启用语音助手,关闭语音助手 17 | * 使用cmd命令进行电脑操作 18 | 19 | 20 | ##有问题反馈 21 | 在使用中有任何问题,欢迎反馈给我,可以用以下联系方式跟我交流 22 | 23 | * 邮件(www476369545@qq.com) 24 | * QQ: 476369545 25 | 26 | ## 需要下载的包 pip install itchat,pypiwin32,opencv-python,pydub 27 | 28 | * itchat 29 | * win32api 30 | * cv2 31 | * pydub -------------------------------------------------------------------------------- /config.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | dis=[{'ID': 1, 'PROGRAM_PATH': 'D:/WeChat/WeChat.exe', 'PROGRAM_NAME': '微信'}, 4 | {'ID': 2,'PROGRAM_PATH':'D:/VSCode-win32-1.12.2/Code.exe','PROGRAM_NAME':'微软2018'}, 5 | {'ID': 3, 'PROGRAM_PATH': 'D:/QQ/bin/QQ.exe', 'PROGRAM_NAME': 'QQ'}, 6 | {'ID': 4, 'PROGRAM_PATH': 'D:/钉钉/DingDing/main/current/DingTalk.exe', 'PROGRAM_NAME': '钉钉'}, 7 | {'ID': 5, 'PROGRAM_PATH': 'D:/钉钉/DingDing/main/current/DingTalk.exe', 'PROGRAM_NAME': '丁丁'}, 8 | {'ID': 6, 'PROGRAM_PATH': 'D:/Evernote/Evernote.exe', 'PROGRAM_NAME': '印象笔记'}, 9 | {'ID': 7, 'PROGRAM_PATH': '', 'PROGRAM_NAME': 'EXCEL'}] -------------------------------------------------------------------------------- /myChat.py: -------------------------------------------------------------------------------- 1 | #encoding:utf8 2 | import itchat 3 | import os 4 | import time 5 | import subprocess 6 | import string 7 | # import xunfei 8 | import pydub 9 | import win32api 10 | import re 11 | import sqlite3 12 | from itchat.content import * 13 | from aip import AipSpeech 14 | from PIL import ImageGrab 15 | import cv2 #如果使用opencv的话可以远程拍照 16 | from config import dis as myProgramConfig 17 | 18 | APP_ID = '10760089' 19 | API_KEY = 'xE18GKvn5jGokZgSPMHx81Aq' 20 | SECRET_KEY = 'b10eecLu5padR82T49VNpBlSBxM45Rb0' 21 | 22 | sendMsg = u"[消息助手]:暂时无法回复" #自动回复内容 23 | usageMsg = u"使用方法:\n1.运行CMD命令\n2.获取一张图片:cap\n3.启用消息助手:ast\n4.关闭消息助手:astc\n"+"5.0.截屏:scr\n"+"5.百度:bd XXX\n"+u"6.语音(百度XXX)\n7.语音(打开XXX)" 24 | 25 | 26 | 27 | 28 | flag = 0 #消息助手开关 29 | filename ="备份.txt" 30 | myfile = open(filename,'a') 31 | 32 | @itchat.msg_register('Text') #注册文本消息 33 | 34 | def text_replytext_reply(msg): #心跳程序 35 | global flag 36 | message = msg['Text'] #接收文本消息 37 | fromName =msg['FromUserName'] #发送方 38 | toName = msg['ToUserName'] #接收方 39 | print('消息:',message,'发送方',fromName) 40 | if toName == "filehelper": 41 | if message[0]+message[1] =="bd": 42 | keyword = message.strip(message[0]+message[1]+message[2]) 43 | win32api.ShellExecute(0, 'open', "http://www.baidu.com/s?wd=" + keyword, '', '', 1) # 打开网页 44 | # driver.get("http://www.baidu.com/s?wd=" + keyword) 45 | if message=="scr":#截屏给手机 46 | im = ImageGrab.grab() 47 | im.save('screenshot.png') 48 | itchat.send('@img@%s'%u'screenshot.png','filehelper') 49 | return 50 | if message == "cap": #远程拍照并发送到手机 51 | cap=cv2.VideoCapture(0) 52 | ret,img =cap.read() 53 | cv2.imwrite("weixinTemp.jpg",img) 54 | itchat.send('@img@%s'%u'weixinTemp.jpg','filehelper') 55 | cap.release() 56 | return 57 | if message[0]+message[1]+message[2] == "cmd": #远程执行cmd命令 58 | os.system(message.strip(message[0]+message[1]+message[2]+message[3])) #远程执行cmd命令,可以实现关机 59 | return 60 | if message == "ast": 61 | flag = 1 62 | itchat.send("消息助手已开启","filehelper") 63 | return 64 | if message == "astc": 65 | flag = 0 66 | itchat.send("消息助手已关闭","filehelper") 67 | return 68 | elif flag==1: 69 | itchat.send(sendMsg,fromName) 70 | myfile.write(message) #保存消息内容 71 | myfile.write("\n") 72 | myfile.flush() 73 | 74 | 75 | @itchat.msg_register([PICTURE, RECORDING, ATTACHMENT, VIDEO]) 76 | def download_files(msg): 77 | global flag 78 | message = msg['Text'] #接收语音消息 79 | fromName =msg['FromUserName'] #发送方 80 | toName = msg['ToUserName'] #接收方 81 | 82 | if toName == "filehelper": 83 | msg['Text'](r'./Recording/'+ msg['FileName']) #下载文件 84 | client = AipSpeech(APP_ID, API_KEY, SECRET_KEY) 85 | # 将mp3格式转换为wav 86 | sound = pydub.AudioSegment.from_mp3(r'./Recording/'+msg['FileName']) 87 | sound.export(r'./Recording/'+msg['FileName'], format="wav") 88 | 89 | response=client.asr(getFileContent(r'./Recording/'+msg['FileName']), 'wav', 8000, { 90 | 'lan': 'zh',}) 91 | # 识别正确 92 | if response["err_no"]==0: 93 | words=response['result'] 94 | if len(words)>0: 95 | word=words[0] 96 | # 去标点 97 | word=re.sub("[\s+\.\!\/_,$%^*(+\"\']+|[+——!,。?、~@#¥%……&*()]", '', word) 98 | itchat.send(word + '\n' + '[消息助手]', "filehelper") 99 | print (response) 100 | # word = re.sub(r, '', word) 101 | print (word) 102 | # 百度搜索 103 | if word[0:2] == '百度': 104 | print (123) 105 | word = word[2:] 106 | win32api.ShellExecute(0, 'open', "http://www.baidu.com/s?wd=" + word, '', '', 1) # 打开网页 107 | return 108 | if '打开' in word: 109 | word=word[2:] 110 | # 从Sqlite取值 111 | # programConfig=getSqlite() 112 | programConfig=myProgramConfig 113 | for dic in programConfig: 114 | if word == dic['PROGRAM_NAME']: 115 | win32api.ShellExecute(0, 'open',dic['PROGRAM_PATH'], '', '', 1) # 打开对应配置下的程序 116 | itchat.send('程序名:'+dic['PROGRAM_NAME']+'\n'+'程序位置:'+dic['PROGRAM_PATH']+'\n'+'[消息助手]', "filehelper") 117 | return 118 | 119 | else: 120 | itchat.send("识别错误","filehelper") 121 | 122 | elif flag==1: 123 | itchat.send(sendMsg,fromName) 124 | myfile.write(message) #保存消息内容 125 | myfile.write("\n") 126 | myfile.flush() 127 | 128 | # 读取文件 129 | def getFileContent(filePath): 130 | with open(filePath, 'rb') as fp: 131 | return fp.read() 132 | 133 | # 从Sqlite中读取配置的程序名称,返回字典类型 134 | def getSqlite(): 135 | conn = sqlite3.connect('test.db') 136 | conn.row_factory = dict_factory 137 | c = conn.cursor() 138 | cursor = c.execute("SELECT ID, PROGRAM_NAME,PROGRAM_PATH from PROGRAM_CONFIG") 139 | dics=cursor.fetchall() 140 | conn.close() 141 | return dics 142 | # 查询结果保存在字典类型中 143 | def dict_factory(cursor, row): 144 | d = {} 145 | for idx, col in enumerate(cursor.description): 146 | d[col[0]] = row[idx] 147 | return d 148 | 149 | def main(): 150 | itchat.auto_login(hotReload=True) 151 | itchat.send(usageMsg,"filehelper") 152 | itchat.run() 153 | if __name__ == '__main__': 154 | main() 155 | -------------------------------------------------------------------------------- /myChatService.py: -------------------------------------------------------------------------------- 1 | #encoding=utf-8 2 | import win32serviceutil 3 | import win32service 4 | import win32event 5 | import win32timezone 6 | import myChat 7 | import os 8 | 9 | class PythonService(win32serviceutil.ServiceFramework): 10 | _svc_name_ = 'PythonService' #服务名称 11 | _svc_display_name_ = 'myChatService' 12 | _svc_description_ = '我的智能电脑' 13 | 14 | 15 | def __init__(self,args): 16 | win32serviceutil.ServiceFramework.__init__(self,args) 17 | self.hWaitStop = win32event.CreateEvent(None,0,0,None) 18 | self.logger = self._getLogger() 19 | self.run = True 20 | 21 | def _getLogger(self): 22 | import inspect 23 | import logging 24 | logger = logging.getLogger(u'我的智能电脑') 25 | this_file = inspect.getfile(inspect.currentframe()) 26 | dirpath = os.path.abspath(os.path.dirname(this_file)) 27 | handler = logging.FileHandler(os.path.join(dirpath,'service.log')) 28 | formatter = logging.Formatter('%(asctime)s %(name)-12s %(levelname)-8s %(message)s') 29 | handler.setFormatter(formatter) 30 | logger.addHandler(handler) 31 | logger.setLevel(logging.INFO) 32 | return logger 33 | 34 | def SvcDoRun(self): 35 | self.logger.info('service is run...') 36 | while self.run: 37 | myChat.main() 38 | 39 | 40 | def SvcStop(self): 41 | self.logger.info('service is stop.') 42 | self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) 43 | win32event.SetEvent(self.hWaitStop) 44 | self.run = False 45 | 46 | if __name__ == '__main__': 47 | import sys 48 | import servicemanager 49 | if len(sys.argv) == 1: 50 | try: 51 | evtsrc_dll = os.path.abspath(servicemanager.__file__) 52 | servicemanager.PrepareToHostSingle(PythonService) 53 | servicemanager.Initialize('PythonService',evtsrc_dll) 54 | servicemanager.StartServiceCtrlDispatcher() 55 | except win32service.error as details: 56 | import winerror 57 | if details == winerror.ERROR_FAILED_SERVICE_CONTROLLER_CONNECT: 58 | win32serviceutil.usage() 59 | else: 60 | win32serviceutil.HandleCommandLine(PythonService) -------------------------------------------------------------------------------- /mySqlite.py: -------------------------------------------------------------------------------- 1 | import sqlite3 2 | 3 | conn = sqlite3.connect('test.db') 4 | print ("打开数据库成功") 5 | # 创建表 6 | # c = conn.cursor() 7 | # c.execute('''CREATE TABLE PROGRAM_CONFIG 8 | # (ID INT PRIMARY KEY NOT NULL, 9 | # PROGRAM_NAME TEXT NOT NULL, 10 | # PROGRAM_PATH TEXT NOT NULL 11 | # );''') 12 | # print ("表创建成功"); 13 | # conn.commit() 14 | # conn.close() 15 | 16 | 17 | # 插入表 18 | # 19 | # c = conn.cursor() 20 | # 21 | # c.execute("INSERT INTO PROGRAM_CONFIG (ID,PROGRAM_NAME,PROGRAM_PATH) \ 22 | # VALUES (1, '微信', 'D:/WeChat/WeChat.exe' )"); 23 | # 24 | # c.execute("INSERT INTO PROGRAM_CONFIG (ID,PROGRAM_NAME,PROGRAM_PATH) \ 25 | # VALUES (2, 'VS2010','')"); 26 | # 27 | # c.execute("INSERT INTO PROGRAM_CONFIG (ID,PROGRAM_NAME,PROGRAM_PATH) \ 28 | # VALUES (3, 'VSCODE','D:/VS Code/Microsoft VS Code/Code.exe' )"); 29 | # 30 | # c.execute("INSERT INTO PROGRAM_CONFIG (ID,PROGRAM_NAME,PROGRAM_PATH) \ 31 | # VALUES (4, '钉钉', '' )"); 32 | # 33 | # c.execute("INSERT INTO PROGRAM_CONFIG (ID,PROGRAM_NAME,PROGRAM_PATH) \ 34 | # VALUES (5, 'ORACLE', '' )"); 35 | # 36 | # c.execute("INSERT INTO PROGRAM_CONFIG (ID,PROGRAM_NAME,PROGRAM_PATH) \ 37 | # VALUES (6, 'OFFICE', '' )"); 38 | # 39 | # c.execute("INSERT INTO PROGRAM_CONFIG (ID,PROGRAM_NAME,PROGRAM_PATH) \ 40 | # VALUES (7, 'EXCEL', '' )"); 41 | # 42 | # conn.commit() 43 | # print ("数据插入成功"); 44 | # conn.close() 45 | 46 | 47 | # # 查询表 48 | # c = conn.cursor() 49 | # cursor = c.execute("SELECT ID, PROGRAM_NAME,PROGRAM_PATH from PROGRAM_CONFIG") 50 | # # for row in cursor: 51 | # # print ("ID = ", row[0]) 52 | # # print ("PROGRAM_NAME = ", row[1]) 53 | # # print ("PROGRAM_PATH = ", row[2],"\n") 54 | # 55 | # print ("查询成功"); 56 | # conn.close() 57 | 58 | # 更新表 59 | # c = conn.cursor() 60 | # c.execute("UPDATE PROGRAM_CONFIG set PROGRAM_NAME = '',PROGRAM_PATH='' where ID=1") 61 | # conn.commit() 62 | # cursor = c.execute("SELECT ID, PROGRAM_NAME,PROGRAM_PATH from PROGRAM_CONFIG") 63 | # for row in cursor: 64 | # print ("ID = ", row[0]) 65 | # print ("PROGRAM_NAME = ", row[1]) 66 | # print ("PROGRAM_PATH = ", row[2],"\n") 67 | # conn.close() 68 | 69 | # 查询结果保存在字典类型中 70 | def dict_factory(cursor, row): 71 | d = {} 72 | for idx, col in enumerate(cursor.description): 73 | d[col[0]] = row[idx] 74 | return d 75 | con = sqlite3.connect('test.db') #打开在内存里的数据库 76 | con.row_factory = dict_factory 77 | cur = con.cursor() 78 | print (123) 79 | cur.execute("SELECT ID, PROGRAM_NAME,PROGRAM_PATH from PROGRAM_CONFIG") 80 | conn.close() 81 | dics=cur.fetchall() 82 | for dic in dics: 83 | if u'微信'==dic['PROGRAM_NAME']: 84 | print (1) 85 | 86 | 87 | 88 | # print (cur.fetchone()["PROGRAM_PATH"]) -------------------------------------------------------------------------------- /test.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chinasilva/MySmartPc/58eb9cd44042ccf7208b99f43309902c824808e2/test.db -------------------------------------------------------------------------------- /test.py: -------------------------------------------------------------------------------- 1 | # import pydub 2 | # sound = pydub.AudioSegment.from_mp3("Recording/180128-222450.mp3") 3 | # sound.export("Recording/180128-222450.wav", format="wav") 4 | 5 | # import win32api 6 | # # win32api.ShellExecute(0, 'open', 'notepad.exe', '', '', 0) # 后台执行 7 | # # win32api.ShellExecute(0, 'open', 'notepad.exe', '', '', 1) # 前台打开 8 | # # win32api.ShellExecute(0, 'open', 'notepad.exe', '1.txt', '', 1) # 打开文件 9 | # win32api.ShellExecute(0, 'open', 'http://www.sohu.com', '', '', 1) # 打开网页 10 | # # win32api.ShellExecute(0, 'open', 'D:\\Opera.mp3', '', '', 1) # 播放视频 11 | # # win32api.ShellExecute(0, 'open', 'D:\\hello.py', '', '', 1) # 运行程序 12 | 13 | import myChat 14 | 15 | myChat.main() --------------------------------------------------------------------------------