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

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

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

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

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

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

朋友圈操作

# 获取朋友圈数据
moments = w.get_moments()
if not moments:
    print("没有最新的朋友圈")
else:
    for item in moments:
        print(item)
 
# 朋友圈点赞/取消点赞
w.like_moments(
    moments_id="130000",
    state=True
)
 
# 朋友圈评论
w.comment_moments(
    moments_id="1300000",
    content="我是评论内容"
)
 
# 朋友圈删除评论
w.del_comment_moments(
    moments_id="1300000",
    comment_id="3"
)

发送、接收、转发消息

# 发送文本消息
w.send_text(to_wx="filehelper", msg='你好鸭~')
time.sleep(1)
 
# 发送图片消息
w.send_img(to_wx="filehelper", path=r"C:\Users\Administrator\Desktop\1.png")
time.sleep(1)
 
# 发送卡片链接
w.send_card_link(
    to_wx="filehelper",
    title="我是卡片标题",
    desc="我是卡片描述啊啊啊啊啊啊啊啊啊啊",
    target_url="http://baidu.com",
    img_url="http://img.czdsh.com/Fsc_C6Rz5Sk7sblr_Q4YI0Y9v0zb"
)
 
# 发送其他消息...
 
# 处理消息回调
while True:
    msg = msg_queue.get()
 
    if msg["msg_type"] == 37:
        # 同意添加好友申请
        w.agree_friend(msg_data=msg)
 
    # 收款
    elif msg["msg_type"] == 490:
        is_recv = msg["detail"]["is_recv"]
        if is_recv:
            # 收款
            w.collection(msg_data=msg)
 
    # 保存图片
    elif msg["msg_type"] == 3:
        w.save_img(
            save_path=os.path.join(BASE_DIR, "temp\\1.png"),
            msg_data=msg
        )
 
    # 如果是老板发来的信息
    if msg["wx_id"] == "wxid_xxx":
        # 转发给工作小组
        w.forward_msg("xxxxxx@chatroom", msg["msg_id"])

以下是效果图:

posted @ 2024-01-19 18:38  三水君  阅读(288)  评论(0编辑  收藏  举报