微信网页版 发送消息

使用微信wxpy 模块进行 消息发送

代码需要使用 python 3.6 版本 高版本python 不支持 wxpy 模块
使用微信号需要可以正常登录微信网页版

将需要发送消息 以一定格式写入文件中 有程序进行发送给对应好友

代码功能
实时检测 同目录下 send.txt 文件 内容 当send.txt 文件有写入时 符合格式 message_type message_search message 发送消息给对应 好友或群组 例如
friend 好友名称 消息内容发送消息给对应好友因分割符为空格消息内容中不能带空格
或者
group 群组名称 消息内容发送消息给对应群组因分割符为空格消息内容中不能带空格

send_wxpy.py

import time
import wxpy
bot = wxpy.Bot(cache_path=True)
bot.enable_puid('wxpy_puid.pkl')
print('登录成功')
while True:
    with open('send.txt', 'r', encoding='UTF-8') as f:
        data = f.read()
    print(data)
    if not data == '':
        message_type = data.split()[0]
        message_search = data.split()[1]
        message = data.split()[2]
        print('message_type = %s' % message_type)
        print('message_search = %s' % message_search)
        print('message = %s' % message)
        if message_type == 'group':
            print('给 %s 群发送消息' % message_search)
            send_groups = bot.groups().search(message_search)[0]
            send_groups.send(message)
            print('发送消息 成功')
        elif message_type == 'friend':
            print('给 %s 好友发送消息' % message_search)
            send_friends = bot.friends().search(message_search)[0]
            send_friends.send(message)
            print('发送消息 成功')
        else:
            print('message_type 错误')
    with open('send.txt', 'w') as f:
        f.write('')
    time.sleep(1)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值