python使用itchat實現手機控制電腦,pythonitchat

來源:互聯網
上載者:User

python使用itchat實現手機控制電腦,pythonitchat

本文執行個體為大家分享了python使用itchat實現手機控制電腦的具體代碼,供大家參考,具體內容如下

1.準備材料

首先電腦上需要安裝了python,安裝了opencv更好(非必需)

如果安裝了opencv的話,在opencv的python目錄下找到cv2.pyd,將該檔案放到python的庫搜尋路徑就可以匯入了

然後下載itchat:github

2.開始使用

下載了itchat後解壓(建議先閱讀該檔案夾下的docs),然後在該檔案夾下執行cmd命令來安裝itchat庫:

python setup.py install

接著可以執行demo程式:

#encoding:utf8import itchatimport osimport time#import cv2 #如果使用opencv的話可以遠程拍照sendMsg = u"[訊息助手]:暫時無法回複" #自動回複內容usageMsg = u"使用方法:\n1.運行CMD命令:cmd xxx (xxx為命令)\n-例如關機命令:\ncmd shutdown -s -t 0 \n2.擷取一張圖片:cap\n3.啟用訊息助手(預設關閉):ast\n4.關閉訊息助手:astc"@itchat.msg_register('Text') #註冊簡訊def text_reply(msg): #心跳程式 global flag message = msg['Text'] #接收簡訊 fromName =msg['FromUserName'] #發送方 toName = msg['ToUserName'] #接收方 if toName == "filehelper":  if message == "cap": #遠程拍照並發送到手機   #cap=cv2.VideoCapture(0)   #ret,img =cap.read()   #cv2.imwrite("weixinTemp.jpg",img)   #itchat.send('@img@%s'%u'weixinTemp.jpg','filehelper')   #cap.release()  if message[0]+message[1]+message[2] == "cmd": #遠程執行cmd命令    os.system(message.strip(message[0]+message[1]+message[2]+message[3])) #遠程執行cmd命令,可以實現關機  if message == "ast":   flag = 1   itchat.send("訊息助手已開啟","filehelper")  if message == "astc":   flag = 0   itchat.send("訊息助手已關閉","filehelper") elif flag==1:  itchat.send(sendMsg,fromName)  myfile.write(message) #儲存訊息內容  myfile.write("\n")  myfile.flush()flag = 0 #訊息助手開關nowTime = time.localtime()filename =str(nowTime.tm_mday)+str(nowTime.tm_hour)+str(nowTime.tm_min)+str(nowTime.tm_sec)+".txt"myfile = open(filename,'w')if __name__ == '__main__': itchat.auto_login() itchat.send(usageMsg,"filehelper") itchat.run()

執行成功的話它會跳出一個二維碼,使用掃碼登入,然後就可以在手機通過的手機小幫手遠程操作電腦了,使用opencv的目的是實現遠程拍照,在以上的demo中已經將相關代碼注釋了。

其他:可以使用itchat實現機器人等有趣的功能,github中有較為詳細的指導;如果想開機啟動的話可以在任務計劃裡建立一個任務。

以上就是本文的全部內容,希望對大家的學習有所協助,也希望大家多多支援幫客之家。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.