首页 > 技术文章 > 微信利用小号和大号的好友聊天(基于wxpy库)

zhujunsheng 2019-05-10 17:06 原文

# 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()

推荐阅读