wxpy模块(微信模块)

Bot()

功能

实例化(创建)微信对象

参数


返回值

返回一个微信对象

例子

import wxpy

bot = wxpy.Bot()

微信对象.friends()

功能

获取所有微信好友对象

参数


返回值

所有的微信好友对象(列表类型)

例子

import wxpy

bot = wxpy.Bot()
friends_list = bot.friends()
print(friends_list)

微信好友对象列表.search( keywords )

功能

查询指定名称的好友对象

参数

·keywords:好友微信名称

返回值

返回满足指定名称的好友对象列表

例子

import wxpy

bot = wxpy.Bot()
friend = bot.friends().search('小猿')[0]
print(friend)

微信对象.join()

功能

保持程序运行

参数


返回值

例子

import wxpy

bot = wxpy.Bot()
@bot.register()
def answer(msg):
    msg.reply_image('1.jpg')
bot.embed()

微信对象.logout()

功能

退出当前帐号

参数


返回值

例子

import wxpy

bot = wxpy.Bot()
friends_list = bot.friends()
print(friends_list)
bot.logout()

一些属性

获取好友的昵称 通过好友对象的name属性可以获取好友的昵称:好友对象.name

获取好友的性别 通过好友对象的sex属性可以获取好友的性别:好友对象.sex

获取好友的省份 通过好友对象的province属性可以获取好友的省份:好友对象.province

获取好友的城市 通过好友对象的city属性可以获取好友的城市:好友对象.city

获取消息的类型 通过消息对象的type属性可以获取消息的类型:消息对象.type

wxpy定义的消息类型 文本类型:wxpy.TEXT 图片类型:wxpy.PICTURE 语音类型:wxpy.RECORDING

获取消息的文本内容 通过消息对象的text属性可以获取消息的文本内容:消息对象.text

获取消息中文件的名称 通过消息对象的file_name属性可以获取消息中文件的名称:消息对象.file_name

获取消息发送者的id 通过消息对象中sender对象的user_name属性可以获取消息发送者的id:消息对象.sender.user_name

获取文件传输助手对象 通过微信对象的file_helper可以获取到文件传输助手对象:微信对象.file_helper


好友对象.send( content )

功能

发送文字消息

参数

·content:要发送的文本

返回值

例子

import wxpy

bot = wxpy.Bot()
bot.file_helper.send('hello')
bot.logout()

好友对象.send_image( path )

功能

发送图片消息

参数

·path:要发送的文件的路径

返回值

例子

import wxpy

bot = wxpy.Bot()
bot.file_helper.send_image('1.jpg')
bot.logout()

消息对象.get_file( save_path )

功能

下载消息中的文件

参数

·save_path:文件的保存路径

返回值

例子

import wxpy

bot = wxpy.Bot()
@bot.register()
def answer(msg):
    msg.get_file('1.jpg')
wxpy.embed()

消息对象.reply( text )

功能

回复文本消息

参数

·text:要回复的内容

返回值

例子

import wxpy

bot = wxpy.Bot()
@bot.register()
def answer(msg):
    msg.reply('hello')
wxpy.embed()

消息对象.reply_image( filename )

功能

回复图片消息

参数

·filename:图片名

返回值

例子

import wxpy

bot = wxpy.Bot()
@bot.register()
def answer(msg):
    msg.reply_image('1.jpg')
wxpy.embed()

embed()

功能

保持程序运行

参数


返回值

例子

import wxpy

bot = wxpy.Bot()
@bot.register()
def answer(msg):
    msg.reply_image('1.jpg')
wxpy.embed()