八小時學會用Python實現微信機器人功能(圖文詳解)

烟雨青岚
發布: 2020-06-20 14:14:11
轉載
3678 人瀏覽過

八小時學會用Python實現微信機器人功能(圖文詳解)

#八小時學會用Python實作微信機器人功能(圖文詳解)

微信,一個日活10億的超級app,不僅在國內社交獨領風騷,在國外社交也同樣佔有一席之地,今天我們要講述如何用Python來產生一個微信機器人,突然想起魯迅先生曾經說過的一句話:
八小時學會用Python實現微信機器人功能(圖文詳解)
因為是微信機器人系列的第一篇文章,所以豬哥會特別詳細的講解每一地方,盡量讓每個想學習的同學都能順順利利的開始,下面就讓我們一起來做有趣的事吧!
八小時學會用Python實現微信機器人功能(圖文詳解)一、專案介紹

#1.微信庫選擇

python關於開發微信的函式庫主要有itchatwxpy,而wxpy底層是呼叫的itchat,所以如果你只是要使用的話建議使用wxpy庫,它比其他的庫都要優雅,更面向對象,而且深度整合了圖靈機器人小i機器人;而itchat擴展性更好,如果你想自己開發一個自己的微信庫那建議選itchat

2.實現原則

我相信有不少同學使用過微信的網頁版,而wxpy(底層使用itchat )函式庫就是模擬登入網頁端,然後呼叫微信的api實作操作的,我們可以查看itchat原始碼發現。
八小時學會用Python實現微信機器人功能(圖文詳解)
八小時學會用Python實現微信機器人功能(圖文詳解)
總之大家記住,目前wxpyitchat都是模擬網頁版微信來操作的

3.圖靈機器人

既然可以模擬網頁微信了,那又如何做到自動回覆呢?這裡我們就使用到了圖靈機器人,大家可以在他們的官網(http://www.tuling123.com)免費註冊帳號,然後申請一個免費的機器人,每個人最多免費申請五個機器人。
八小時學會用Python實現微信機器人功能(圖文詳解)
我會在專案程式碼中給一個預設的apikey,讓大家不用下載就可以嘗試,但是還是建議自己去申請,因為這個預設的apikey有呼叫次數限制,況且這算是一筆免費的財富呢!

4.整體流程

為了方便大家理解,豬哥為大家畫了一個時序圖
八小時學會用Python實現微信機器人功能(圖文詳解)

#二、專案程式碼

先來張專案結構圖壓壓驚:
八小時學會用Python實現微信機器人功能(圖文詳解)

##1.下載專案

豬哥已經把專案放在了GitHub上,群組有小夥伴回饋不會使用github,這裡我就詳細講一下如何從github上下載專案。

注意:github與git不是同一個東西,github是全球最大的同性戀交友論壇,在這裡我們不比顏值與財富,只比誰的項目

star多,star越多表示你越吸引同性的喜歡與愛慕,連你的同事也會愛上你!而git是專案管理工具,github上的專案就是用git來管理,專案管理工具另一派係是svn。

八小時學會用Python實現微信機器人功能(圖文詳解)
First find the project you need to download, then click Clone or download, and then click the copy button on the right. The address of Brother Zhu’s project is: https: //github.com/pig6/wxrobot
八小時學會用Python實現微信機器人功能(圖文詳解)
Then open your pycharm and selectCSV->Checkout from version control->git, and then paste the project link you just copied.
八小時學會用Python實現微信機器人功能(圖文詳解)
八小時學會用Python實現微信機器人功能(圖文詳解)
Finally, pycharm may prompt you whether to open in a new window or in the current window. Brother Zhu is generally used to opening in a new window (New Window), which can avoid multiple projects. Creates confusion while developing.

2. Download wxpy library

After downloading the project, because the necessary library wxpy is not installed, pycharm may There will be the following prompt, then we can click install.
八小時學會用Python實現微信機器人功能(圖文詳解)
If no installation library prompt appears, we can add it in Setting->Project->Project Interpreter wxpyLibrary.
八小時學會用Python實現微信機器人功能(圖文詳解)
Or use the following command to download the wxpy library. If you are using pip3, replace the pip below.

pip install -U wxpy -i “https://pypi.doubanio.com/simple/”

3. Run the project

You can press the green triangle button in the upper right corner, or you can right-click the project and click 八小時學會用Python實現微信機器人功能(圖文詳解).
八小時學會用Python實現微信機器人功能(圖文詳解)
After 八小時學會用Python實現微信機器人功能(圖文詳解)ning, a login QR code will pop up. Scan it with WeChat on your mobile phone and click OK to log in to chat with your friends.
八小時學會用Python實現微信機器人功能(圖文詳解)

First of all, thank you for your patience in reading. Considering that there are many students with no basic knowledge, the article is a bit long.

This article is reproduced from: https://blog.csdn.net/u014044812/article/details/89406010

Recommended tutorial: "python tutorial"

以上是八小時學會用Python實現微信機器人功能(圖文詳解)的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:csdn.net
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!