用户接口#
- class wechatpy.client.api.WeChatUser(client=None)[源代码]#
- change_openid(from_appid, openid_list)[源代码]#
微信公众号主体变更迁移用户 openid
详情请参考 http://kf.qq.com/faq/170221aUnmmU170221eUZJNf.html
- 参数
from_appid – 原公众号的 appid
openid_list – 需要转换的openid,这些必须是旧账号目前关注的才行,否则会出错;一次最多100个
- 返回
转换后的 openid 信息列表
- get(user_id, lang='zh_CN')[源代码]#
获取用户基本信息(包括UnionID机制)
- 参数
user_id – 普通用户的标识,对当前公众号唯一
lang – 返回国家地区语言版本,zh_CN 简体,zh_TW 繁体,en 英语
- 返回
返回的 JSON 数据包
使用示例:
>>> from wechatpy import WeChatClient >>> >>> client = WeChatClient('appid', 'secret') >>> user = client.user.get('openid')
- get_batch(user_list)[源代码]#
批量获取用户基本信息 开发者可通过该接口来批量获取用户基本信息。最多支持一次拉取100条。
- 参数
user_list – user_list,支持“使用示例”中两种输入格式
- 返回
用户信息的 list
使用示例:
>>> from wechatpy import WeChatClient >>> >>> client = WeChatClient('appid', 'secret') >>> users = client.user.get_batch(['openid1', 'openid2']) >>> users = client.user.get_batch([ >>> {'openid': 'openid1', 'lang': 'zh-CN'}, >>> {'openid': 'openid2', 'lang': 'en'}, >>> ])
opendid: 必填,用户的标识,对当前公众号唯一 lang: 非必填,国家地区语言版本,zh_CN 简体,zh_TW 繁体,en 英语,默认为zh-CN
- get_followers(first_user_id=None)[源代码]#
获取一页用户列表(当关注用户过多的情况下,这个接口只会返回一部分用户)
详情请参考 https://developers.weixin.qq.com/doc/offiaccount/User_Management/Getting_a_User_List.html
- 参数
first_user_id – 可选。第一个拉取的 OPENID,不填默认从头开始拉取
- 返回
返回的 JSON 数据包
使用示例:
>>> from wechatpy import WeChatClient >>> >>> client = WeChatClient('appid', 'secret') >>> followers = client.user.get_followers()
- get_group_id(user_id)[源代码]#
⚠️已废弃 获取用户所在分组 ID
详情请参考 http://mp.weixin.qq.com/wiki/0/56d992c605a97245eb7e617854b169fc.html
- 参数
user_id – 用户 ID
- 返回
用户所在分组 ID
使用示例:
from wechatpy import WeChatClient client = WeChatClient('appid', 'secret') group_id = client.user.get_group_id('openid')
- iter_followers(first_user_id=None)[源代码]#
获取所有的用户openid列表
详情请参考 https://developers.weixin.qq.com/doc/offiaccount/User_Management/Getting_a_User_List.html
- 返回
返回一个迭代器,可以用for进行循环,得到openid
使用示例:
>>> from wechatpy import WeChatClient >>> >>> client = WeChatClient('appid', 'secret') >>> for openid in client.user.iter_followers(): >>> print(openid)
- update_remark(user_id, remark)[源代码]#
设置用户备注名
详情请参考 https://developers.weixin.qq.com/doc/offiaccount/User_Management/Configuring_user_notes.html
- 参数
user_id – 用户标识
remark – 新的备注名,长度必须小于30字符
- 返回
返回的 JSON 数据包
使用示例:
>>> from wechatpy import WeChatClient >>> >>> client = WeChatClient('appid', 'secret') >>> client.user.update_remark('openid', 'Remark')