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)

发送、接收、转发消息

# 发送文本消息
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)
 
            # 退款
            # w.refund(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"])

以下是效果图:

在这里插入图片描述

  • 14
    点赞
  • 143
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值