栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

微信网页版 发送消息

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

微信网页版 发送消息

使用微信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)
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/323942.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号