您的位置:首页 > 移动开发 > 微信开发

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

2020-03-08 15:26 477 查看

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

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
) #开启缓存,不必每次都扫码
[/code]
# 给机器人自己发送消息
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') 

  

如果要发送给指定好友
[/code]
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)

  

最后要保持程序不自动结束
[/code]
embed()

  

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





[/code]

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

  • 点赞
  • 收藏
  • 分享
  • 文章举报
anda9661 发布了0 篇原创文章 · 获赞 0 · 访问量 322 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐