1、實驗環境:win10 + python3 + wxpy 微信版本:6.6.5html
1.一、從官網下載python最新版本並進行安裝。 1.二、進入python安裝目錄Scripts/文件夾下,使用easy_install.exe pip 命令安裝pip 1.三、使用pip install wxpy 命令安裝wxpy
2、源碼文件demo.pypython
#coding=utf-8 from wxpy import * base_bot = Bot(True) # 查找指定羣聊羣聊 , 確保掃碼微信中有 「123」 這個羣 group = base_bot.groups().search('123') # 自動接受新的好友請求 @base_bot.register(msg_types=FRIENDS) def auto_accept_friends(msg): if '加好友' in msg.text.lower(): # 接受好友請求 new_friend = base_bot.accept_friend(msg.card) # new_friend = msg.card.accept() # 向新的好友發送消息 new_friend.send('你好,我是羣聊機器人,回覆"入羣"口令進入羣聊天哦!') # 接收文字消息的裝飾器 @base_bot.register(msg_types=TEXT) def add_into_chatroom(msg): # 接收進羣口令 if msg.text.lower() == '入羣': # use_invitation爲True,發送羣邀請,False則拉進羣聊 group[0].add_members(msg.sender, use_invitation=True) else: # 其餘消息 return u'收到:' + msg.text base_bot.join()
3、實驗效果:
4、注意事項:微信
4.一、須開啓「好友驗證」(因對方加好友時,須要根據驗證關鍵字觸發加好友動做); 4.二、建立好羣聊並命名,且須要加入到「通信錄」 ,不然沒法獲取羣聊;
wxpy官網文檔:http://wxpy.readthedocs.io/zh...spa