当前位置: 首页 > 后端技术 > Python

Python微信机器人制作教程+源码

时间:2023-03-26 14:54:23 Python

1.环境配置网页版一般人登录不了,闲着模拟电脑登录。记得安装这个模块:pipinstallitchat-uospipinstallitchat2.登录#code登录个人微信账号importitchatitchat.auto_login(hotReload=True)#hotReload=True可以暂时保存登录状态,一定时间内重启注销后未扫码重新登录。3.第一个简单的消息发送监听,比如给文件传输助手发送消息,实时监听,代码:#coding=gbk"""作者:川川@时间:2021/12/2415:59"""importitchatimporttime@itchat.msg_register(itchat.content.TEXT)defreply_msg(msg):print("Receivedamessage:",msg.text)if__name__=='__main__':itchat.auto_login()时间。sleep(5)itchat.send("小助手你好吗",toUserName="filehelper")itchat.run()效果如下:4、指定微信好友发送消息。比如自动给张三发消息,代码如下:#codeloginpersonalWeChataccountimportitchatitchat.auto_login(hotReload=True)#hotReload=True可以暂时保存登录状态,在一定时间内重启退出后无需扫码重新登录的时间。#向指定好友发送消息itchat.auto_login(hotReload=True)friends_list=itchat.get_friends(update=True)users=itchat.search_friends(name=u'张三')userName=users[0]["UserName"]itchat.send('微信机器人正在测试中...',toUserName=userName)效果:5.所有微信群的监控效果如下:(个别备注为马赛克)检测结果:6.公众号监控作用:这个是监听所有的公众号,分配给自己的公众号:串串菜鸟发消息7.定时发消息,比如每天记得提醒一个大懒虫吃饭,中午12点执行每天:#coding=gbk"""作者:川川@时间:2021/12/2416:26群:970353786"""importitchatfromapscheduler.schedulers.blockingimportBlockingScheduler#发送信息defsend_msg():user_info=itchat.search_friends(name='littlebell')iflen(user_info)>0:user_name=user_info[0]['UserName']itchat.send_msg('记得吃饭,小懒虫!',toUserName=user_name)defafter_login():#当前任务每月执行一次每天十二点执行sched.add_job(send_msg,'cron',month='*',day='*',hour='12')sched.start()defafter_logout():sched.shutdown()如果__name__=='__main__':sched=BlockingScheduler()itchat.auto_login(loginCallback=after_login,exitCallback=after_login,hotReload=True)itchat.run()就不演示了,代码是正确的8.微信智能聊天机器人的效果是:9.完整源码公众号:串串菜鸟回复:微信机器人温馨提示!请勿将本教程用于非法内容,仅供娱乐,否则造成任何后果我们概不负责。如果还有什么问题可以在评论区留言或者在文章左侧加我微信联系我或者用公众号留言。10.反馈经过一些小伙伴的反馈,按照我的安装,还是不能正常登录,报错,所以我把我的环境全部打包了(可能有点大,但不碍事)。你只需要将你的安装包换成我的安装包即可。找到你对应安装包的路径。比如随便下载一个模块:复制这个路径,在文件目录下找到:下载文件后,解压覆盖原来的安装包:(也就是把你的覆盖我的)安装包下载:链接:https://pan.baidu.com/s/1J-z_XDaeboJ_IAhvyX4xpw提取码:ibku--sharefrom百度网盘超级会员V3