使用wxpy來實現自動發送消息統計微信好友信息的功能


發送消息太頻繁會出現禁言消息

1:導入wxpy模塊

pip install wxpy
pip3 install wxpy #二者選一

  

調用模塊

# 導入模塊
from wxpy import *
# 初始化機器人,掃碼登陸
bot = Bot()
bot = Bot(console_qr=True) #如果是在服務器不能彈出二維碼,可以選擇使用這個,可以改True為1,2,3 來改變圖案的大小
bot = Bot(
cache_path=True) #開啟緩存,不必每次都掃碼
# 給機器人自己發送消息
bot.self.send('Hello World!')
# 給文件傳輸助手發送消息
bot.file_helper.send('Hello World!')

wxpy同時也包括了發送不同類型消息的方法,通過這些方法我們可以發送各種不同類型的消息。以下是文檔給出的樣例使用方式:  

# 發送文本
my_friend.send('Hello, WeChat!')
# 發送圖片
my_friend.send_image('my_picture.png')
# 發送視頻
my_friend.send_video('my_video.mov')
# 發送文件
my_friend.send_file('my_file.zip')
# 以動態的方式發送圖片
my_friend.send('@img@my_picture.png') 

  

如果要發送給指定好友
my_friend = bot.friends().search('cjkk')[0]  #這個將my_firend定義成cjkk這個用戶

  

監聽並給指定好友回復消息

# 回復 my_friend 發送的消息
@bot.register(my_friend)
def reply_my_friend(msg):
    return 'received: {} ({})'.format(msg.text, msg.type)

  

最后要保持程序不自動結束
embed()

  

附上官方文檔鏈接:功能實在太多了
http://wxpy.readthedocs.io/






免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM