当前位置:   article > 正文

2024年最新的Python操控微信教程_python控制微信

python控制微信

自从微信禁止网页版登陆之后,itchat 库实现的功能也就都不能用了,那现在 Python 还能操作微信吗?答案是:可以!

在Github上有一个项目叫《WeChatPYAPI》可以使用 Python 对微信进行操控。简单来说,它是通过逆向PC端微信来实现对微信的操控,使用Python封装后调用更加简单!

Github地址:https://github.com/mrsanshui/WeChatPYAPI

码云地址:https://gitee.com/mrsanshui/WeChatPYAPI

拉取(好友/群/公众号)等列表

  1. # 拉取列表(好友/群/公众号等)
  2. # 好友列表:pull_type = 1
  3. # 群列表:pull_type = 2
  4. # 公众号列表:pull_type = 3
  5. # 其他:pull_type = 4
  6. data = w.pull_list(pull_type=1)
  7. print(data)
  8. # 获取群成员列表
  9. data = w.get_chat_room_members(to_chat_room="xxx@chatroom")
  10. print(data)

朋友圈操作

  1. # 获取朋友圈数据
  2. moments = w.get_moments()
  3. if not moments:
  4. print("没有最新的朋友圈")
  5. else:
  6. for item in moments:
  7. print(item)
  8. # 朋友圈点赞/取消点赞
  9. w.like_moments(
  10. moments_id="130000",
  11. state=True
  12. )
  13. # 朋友圈评论
  14. w.comment_moments(
  15. moments_id="1300000",
  16. content="我是评论内容"
  17. )
  18. # 朋友圈删除评论
  19. w.del_comment_moments(
  20. moments_id="1300000",
  21. comment_id="3"
  22. )

发送、接收、转发消息

  1. # 发送文本消息
  2. w.send_text(to_wx="filehelper", msg='你好鸭~')
  3. time.sleep(1)
  4. # 发送图片消息
  5. w.send_img(to_wx="filehelper", path=r"C:\Users\Administrator\Desktop\1.png")
  6. time.sleep(1)
  7. # 发送卡片链接
  8. w.send_card_link(
  9. to_wx="filehelper",
  10. title="我是卡片标题",
  11. desc="我是卡片描述啊啊啊啊啊啊啊啊啊啊",
  12. target_url="http://baidu.com",
  13. img_url="http://img.czdsh.com/Fsc_C6Rz5Sk7sblr_Q4YI0Y9v0zb"
  14. )
  15. # 发送其他消息...
  16. # 处理消息回调
  17. while True:
  18. msg = msg_queue.get()
  19. if msg["msg_type"] == 37:
  20. # 同意添加好友申请
  21. w.agree_friend(msg_data=msg)
  22. # 收款
  23. elif msg["msg_type"] == 490:
  24. is_recv = msg["detail"]["is_recv"]
  25. if is_recv:
  26. # 收款
  27. w.collection(msg_data=msg)
  28. # 保存图片
  29. elif msg["msg_type"] == 3:
  30. w.save_img(
  31. save_path=os.path.join(BASE_DIR, "temp\\1.png"),
  32. msg_data=msg
  33. )
  34. # 如果是老板发来的信息
  35. if msg["wx_id"] == "wxid_xxx":
  36. # 转发给工作小组
  37. w.forward_msg("xxxxxx@chatroom", msg["msg_id"])

以下是效果图:

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小桥流水78/article/detail/766201
推荐阅读
相关标签
  

闽ICP备14008679号