使用wxpy来实现自动发送消息统计微信好友信息的功能

发送消息太频繁会出现禁言消息

1:导入wxpy模块

pip install wxpy
pip3 install wxpy #二者选一

  

调用模块

# 导入模块
from wxpy import *
# 初始化机器人,扫码登陆
bot = Bot()
bot = Bot(console_qr=True) #如果是在服务器不能弹出二维码,可以选择使用这个,可以改True为1,2,3 来改变图案的大小
bot = Bot(
cache_path=True) #开启缓存,不必每次都扫码
# 给机器人自己发送消息
bot.self.send('Hello World!')
# 给文件传输助手发送消息
bot.file_helper.send('Hello World!')

wxpy同时也包括了发送不同类型消息的方法,通过这些方法我们可以发送各种不同类型的消息。以下是文档给出的样例使用方式:  

# 发送文本
my_friend.send('Hello, WeChat!')
# 发送图片
my_friend.send_image('my_picture.png')
# 发送视频
my_friend.send_video('my_video.mov')
# 发送文件
my_friend.send_file('my_file.zip')
# 以动态的方式发送图片
my_friend.send('@img@my_picture.png') 

  

如果要发送给指定好友
my_friend = bot.friends().search('cjkk')[0]  #这个将my_firend定义成cjkk这个用户

  

监听并给指定好友回复消息

# 回复 my_friend 发送的消息
@bot.register(my_friend)
def reply_my_friend(msg):
    return 'received: {} ({})'.format(msg.text, msg.type)

  

最后要保持程序不自动结束
embed()

  

附上官方文档链接:功能实在太多了
http://wxpy.readthedocs.io/





转载于:https://www.cnblogs.com/jixiaoleng4/p/9118751.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值