Closed helexy22 closed 4 years ago
每当机器人接收到消息时,会自动执行以下两个步骤
实现:使用微信网页端实现,注意微信网页登陆有诸多限制,容易被暂停登陆。图灵机器人也存在同样的问题。 使用 https://chp.shadiao.app/api.php 库:wxpy 参考链接:wxpy: 用 Python 玩微信 — wxpy 0.3.9.8 文档
实现代码:
import requests from wxpy import * bot=Bot() kuakua_url= "https://chp.shadiao.app/api.php" my_friend=bot.friends().search('好友名')[0] #打印 my_friend 对象中的文本和图片 @bot.register(my_friend,[TEXT,PICTURE]) def auto_reply(msg): kuakua=requests.get(kuakua_url) # 获取消息的对象 print(msg.raw['ActualNickName']) return format(msg.raw[kuakua.text]) # 堵塞线程,并进入 Python 命令行 embed()
进一步自动回复群里的@消息,忽略其他
from wxpy import * bot = Bot() # 定位公司群 company_group = ensure_one(bot.groups().search('公司微信群')) # 定位老板 boss = ensure_one(company_group.search('老板大名')) # 将老板的消息转发到文件传输助手 @bot.register(company_group) def forward_boss_message(msg): if msg.member == boss: msg.forward(bot.file_helper, prefix='老板发言') # 堵塞线程 embed()
限制网页端登录,导致通知分发失败
消息处理
每当机器人接收到消息时,会自动执行以下两个步骤
实现:使用微信网页端实现,注意微信网页登陆有诸多限制,容易被暂停登陆。图灵机器人也存在同样的问题。 使用 https://chp.shadiao.app/api.php 库:wxpy 参考链接:wxpy: 用 Python 玩微信 — wxpy 0.3.9.8 文档
实现代码:
进一步自动回复群里的@消息,忽略其他
例如,将公司群中的老板消息转发出来: