微信利用小号和大号的好友聊天(基于wxpy库)

本文介绍如何使用Python库WxPy实现微信消息在两个账号之间的自动转发。通过设置Bot并利用缓存和控制台二维码登录,可以实现从一个微信账号接收消息并转发到另一个账号的功能。此应用监听特定联系人的文本消息,接收到的消息会立即转发给指定的朋友。
# encoding=utf-8
from wxpy import *
bot = Bot(cache_path=True, console_qr=False)
# 启用 puid 属性,并指定 puid 所需的映射数据保存/载入路径
mymine = bot.friends().search('小号')[0]
mymine.send('开始')
myfriend= bot.friends().search('徐谦')[0]
xinxi = ''
xinxi2 = ''
@bot.register(mymine, TEXT)
def print_msg1(msg1):
global xinxi
print(msg1)#打印小号的信息
#xinxi.append(msg1.text)
#xinxi = msg1.text#变量赋值
myfriend.send(msg1.text)#给朋友发送小号的信息
@bot.register(myfriend, TEXT)
def print_msg2(msg2):
global xinxi2
print(msg2)#打印朋友回复的信息
xinxi2 = msg2.text #把朋友的信息赋值给xinxi2变量
#myfriend.send(msg2.text)发送对方的信息给对方
mymine.send(xinxi2)#给我的小号发送变量xinxi2
@bot.register(Group, TEXT)
def print_msg(msg3):
print(msg3)
bot.join()

转载于:https://www.cnblogs.com/zhujunsheng/p/10845489.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值