拓展动作
拓展动作
拓展
获取公众号列表action: wx.get_public_account_list
无
list[map[string, string]],每个元素为一个公众号的信息,包含以下字段:
字段名 | 数据类型 | 说明 |
---|---|---|
user_id | string | 公众号的wxid |
user_name | string | 公众号的名称 |
wx_number | string | 公众号的微信号 |
{
"action": "wx.get_public_account_list",
"params": {}
}
{
"status": "ok",
"retcode": 0,
"data": [
{
"user_id": "gh_3c884a361561",
"user_name": "微信支付",
"wx_number": "xxxx",
},
{
"user_id": "gh_3c884a361561",
"user_name": "微信支付",
"wx_number": "xxxx",
}
],
"message": ""
}
from nonebot.adapters.onebot.v12 import Bot, MessageSegment
from nonebot import get_bot
async def test():
bot = get_bot()
public_account_list = await bot.call_api("wx.get_public_account_list")
拓展
关注公众号action: wx.follow_public_account
字段名 | 数据类型 | 说明 |
---|---|---|
user_id | string | 公众号的wxid |
无
{
"action": "wx.follow_public_account",
"params": {
"user_id": "gh_3c884a361561"
}
}
{
"status": "ok",
"retcode": 0,
"data": null,
"message": ""
}
from nonebot.adapters.onebot.v12 import Bot, MessageSegment
from nonebot import get_bot
async def test():
bot = get_bot()
await bot.call_api("wx.follow_public_account", user_id="gh_3c884a361561")
拓展
通过备注搜索联系人action: wx.search_contact_by_remark
字段名 | 数据类型 | 说明 |
---|---|---|
remark | string | 联系人的备注 |
与 get_user_info
一致。
{
"action": "wx.search_contact_by_remark",
"params": {
"remark": "小明"
}
}
{
"status": "ok",
"retcode": 0,
"data": {
"user_id": "1234567",
"user_name": "nb2",
"user_displayname": "",
"user_remark": "",
"wx.avatar": "https://wx.qlogo.cn/mmhead/ver_1/xxx/0",
"wx.wx_number": "nb2",
"wx.nation": "中国",
"wx.province": "广东",
"wx.city": "深圳"
},
"message": ""
}
from nonebot.adapters.onebot.v12 import Bot, MessageSegment
from nonebot import get_bot
async def test():
bot = get_bot()
user_info = await bot.call_api("wx.search_contact_by_remark", remark="小明")
拓展
通过微信号搜索联系人action: wx.search_contact_by_wxnumber
字段名 | 数据类型 | 说明 |
---|---|---|
wx_number | string | 联系人的微信号 |
与 get_user_info
一致。
{
"action": "wx.search_contact_by_wxnumber",
"params": {
"wx_number": "nb2"
}
}
{
"status": "ok",
"retcode": 0,
"data": {
"user_id": "1234567",
"user_name": "nb2",
"user_displayname": "",
"user_remark": "",
"wx.avatar": "https://wx.qlogo.cn/mmhead/ver_1/xxx/0",
"wx.wx_number": "nb2",
"wx.nation": "中国",
"wx.province": "广东",
"wx.city": "深圳"
},
"message": ""
}
from nonebot.adapters.onebot.v12 import Bot, MessageSegment
from nonebot import get_bot
async def test():
bot = get_bot()
user_info = await bot.call_api("wx.search_contact_by_wxnumber", wx_number="xiaoming")
拓展
通过昵称搜索联系人action: wx.search_contact_by_nickname
字段名 | 数据类型 | 说明 |
---|---|---|
nickname | string | 联系人的昵称 |
与 get_user_info
一致。
{
"action": "wx.search_contact_by_nickname",
"params": {
"nickname": "小明"
}
}
{
"status": "ok",
"retcode": 0,
"data": {
"user_id": "1234567",
"user_name": "nb2",
"user_displayname": "",
"user_remark": "",
"wx.avatar": "https://wx.qlogo.cn/mmhead/ver_1/xxx/0",
"wx.wx_number": "nb2",
"wx.nation": "中国",
"wx.province": "广东",
"wx.city": "深圳"
},
"message": ""
}
from nonebot.adapters.onebot.v12 import Bot, MessageSegment
from nonebot import get_bot
async def test():
bot = get_bot()
user_info = await bot.call_api("wx.search_contact_by_nickname", nickname="小明")
拓展
检测好友状态action: wx.check_friend_status
字段名 | 数据类型 | 说明 |
---|---|---|
user_id | string | 联系人的wxid |
返回int
,状态如下:
0x00
: Unknown0xB0
: 被删除0xB1
: 是好友0xB2
: 已拉黑0xB5
: 被拉黑
{
"action": "wx.check_friend_status",
"params": {
"user_id": "1234567"
}
}
{
"status": "ok",
"retcode": 0,
"data": 0,
"message": ""
}
from nonebot.adapters.onebot.v12 import Bot, MessageSegment
from nonebot import get_bot
async def test():
bot = get_bot()
status = await bot.call_api("wx.check_friend_status", user_id="1234567")
拓展
获取数据库句柄和表信息action: wx.get_db_info
无
返回为一个dict
,key为数据库名,value为database
数据库列表如下:
数据库名 | 数据类型 | 说明 |
---|---|---|
MicroMsg.db | database | 微信数据库 |
ChatMsg.db | database | 聊天记录数据库 |
Misc.db | database | 其他数据库 |
Media.db | database | 媒体数据库 |
Emotion.db | database | 表情数据库 |
FunctionMsg.db | database | 功能数据库 |
PublicMsg.db | database | 公众号数据库 |
PublicMsgMedia.db | database | 公众号媒体数据库 |
MediaMSG0.db | database | 媒体数据库 |
MSG0.db | database | 聊天记录数据库 |
OpenIMContact.db | database | OpenIM数据库 |
OpenIMMsg.db | database | OpenIM数据库 |
OpenIMMedia.db | database | OpenIM数据库 |
Sns.db | database | 朋友圈数据库 |
Favorite.db | database | 收藏数据库 |
database定义如下:
字段名 | 数据类型 | 说明 |
---|---|---|
Handle | int | 数据库句柄 |
tables | dict | 表信息 |
tables定义如下:
字段名 | 数据类型 | 说明 |
---|---|---|
name | string | 表名 |
tbl_name | string | 表名 |
root_page | int | 根页 |
sql | string | 建表语句 |
{
"action": "wx.get_db_info",
"params": {}
}
{
"status": "ok",
"retcode": 0,
"data": {
"MicroMsg.db": {
"Handle": 92852680,
"tables": [
{
"name": "OpLog",
"tbl_name": "OpLog",
"root_page": "5",
"sql": "CREATE TABLE OpLog(ID INTEGER PRIMARY KEY,CMDItemBuffer BLOB)"
},
{
"name": "AppInfo",
"tbl_name": "AppInfo",
"root_page": "9",
"sql": "CREATE TABLE AppInfo(InfoKey TEXT PRIMARY KEY,AppId TEXT,Version INT,IconUrl TEXT,StoreUrl TEXT,WatermarkUrl TEXT,HeadImgBuf BLOB,Name TEXT,Description TEXT,Name4EnUS TEXT,Description4EnUS TEXT,Name4ZhTW TEXT,Description4ZhTW TEXT)"
}
]
},
"MicroMsg.db": {
"Handle": 92852680,
"tables": [
{
"name": "OpLog",
"tbl_name": "OpLog",
"root_page": "5",
"sql": "CREATE TABLE OpLog(ID INTEGER PRIMARY KEY,CMDItemBuffer BLOB)"
},
{
"name": "AppInfo",
"tbl_name": "AppInfo",
"root_page": "9",
"sql": "CREATE TABLE AppInfo(InfoKey TEXT PRIMARY KEY,AppId TEXT,Version INT,IconUrl TEXT,StoreUrl TEXT,WatermarkUrl TEXT,HeadImgBuf BLOB,Name TEXT,Description TEXT,Name4EnUS TEXT,Description4EnUS TEXT,Name4ZhTW TEXT,Description4ZhTW TEXT)"
}
]
}
},
"message": ""
}
from nonebot.adapters.onebot.v12 import Bot, MessageSegment
from nonebot import get_bot
async def test():
bot = get_bot()
db = await bot.call_api("wx.get_db_info")
拓展
执行SQL语句action: wx.execute_sql
字段名 | 数据类型 | 说明 |
---|---|---|
handle | int | 数据库句柄 |
sql | string | SQL语句 |
sql的响应
{
"action": "wx.execute_sql",
"params": {
"handle": 92852680,
"sql": "select * from AppInfo"
}
}
{
"status": "ok",
"retcode": 0,
"data":
{
"InfoKey": "com.tencent.mm",
"AppId": "wx7fa037cc7dfabad5",
"Version": 0,
"IconUrl": "http://weixin.qq.com/cgi-bin/readtemplate?t=weixin_faq&lang=zh_CN&faq=faq_1_1",
"StoreUrl": "http://weixin.qq.com/cgi-bin/readtemplate?t=weixin_faq&lang=zh_CN&faq=faq_1_1",
"WatermarkUrl": "http://weixin.qq.com/cgi-bin/readtemplate?t=weixin_faq&lang=zh_CN&faq=faq_1_1",
"HeadImgBuf": null,
"Name": "微信",
"Description": "微信",
"Name4EnUS": "WeChat",
"Description4EnUS": "WeChat",
"Name4ZhTW": "微信",
"Description4ZhTW": "微信"
},
"message": ""
}
from nonebot.adapters.onebot.v12 import Bot, MessageSegment
from nonebot import get_bot
async def test():
bot = get_bot()
db = await bot.call_api("wx.get_db_info")
for db_name, db_info in db.items():
if db_name == "MicroMsg.db":
sql = await bot.call_api("wx.execute_sql", handle=db_info["Handle"], sql="select * from AppInfo")
print(sql)
拓展
备份数据库action: wx.backup_db
注意
file_path
需要填写绝对路径+保存的文件名
由于Com通信只能在主线程,所以此操作会卡事件循环,导致Client无法响应其他请求,所以此Action不要经常使用
字段名 | 数据类型 | 说明 |
---|---|---|
handle | int | 数据库句柄 |
file_path | string | 文件路径 |
无
{
"action": "wx.backup_db",
"params": {
"handle": 92852680,
"file_path": "C:\\Users\\Administrator\\Desktop\\test.db"
}
}
{
"status": "ok",
"retcode": 0,
"data": null,
"message": ""
}
from nonebot.adapters.onebot.v12 import Bot, MessageSegment
from nonebot import get_bot
async def test():
bot = get_bot()
db = await bot.call_api("wx.get_db_info")
for db_name, db_info in db.items():
if db_name == "MicroMsg.db":
await bot.call_api("wx.backup_db", handle=db_info["Handle"], file_path="C:\\Users\\Administrator\\Desktop\\test.db")
拓展
通过好友请求action: wx.accept_friend
字段名 | 数据类型 | 说明 |
---|---|---|
v3 | string | v3数据,通过 wx.friend_request 事件获得 |
v4 | string | v4数据,通过 wx.friend_request 事件获得 |
无
{
"action": "wx.accept_friend",
"params": {
"v3": "v3数据",
"v4": "v4数据"
}
}
{
"status": "ok",
"retcode": 0,
"data": null,
"message": ""
}
from nonebot.adapters.onebot.v12 import Bot, MessageSegment
from nonebot import get_bot
async def test():
bot = get_bot()
await bot.call_api("wx.accept_friend", v3="v3数据", v4="v4数据")
拓展
获取微信版本action: wx.get_wechat_version
无
string
: 微信版本
{
"action": "wx.get_wechat_version",
"params": {}
}
{
"status": "ok",
"retcode": 0,
"data": "3.7.0.30",
"message": ""
}
from nonebot.adapters.onebot.v12 import Bot, MessageSegment
from nonebot import get_bot
async def test():
bot = get_bot()
version = await bot.call_api("wx.get_wechat_version")
print(version)
拓展
设置微信版本号action: wx.set_wechat_version
自定义微信版本号,一定程度上防止自动更新
微信版本号格式类似为3.7.0.26
字段名 | 数据类型 | 说明 |
---|---|---|
version | string | 微信版本号 |
无
{
"action": "wx.set_wechat_version",
"params": {
"version": "3.7.0.26"
}
}
{
"status": "ok",
"retcode": 0,
"data": null,
"message": ""
}
from nonebot.adapters.onebot.v12 import Bot, MessageSegment
from nonebot import get_bot
async def test():
bot = get_bot()
await bot.call_api("wx.set_wechat_version", version="3.7.0.26")
拓展
删除好友action: wx.delete_friend
字段名 | 数据类型 | 说明 |
---|---|---|
user_id | string | 好友wxid |
无
{
"action": "wx.delete_friend",
"params": {
"user_id": "wxid_xxxxx"
}
}
{
"status": "ok",
"retcode": 0,
"data": null,
"message": ""
}
from nonebot.adapters.onebot.v12 import Bot, MessageSegment
from nonebot import get_bot
async def test():
bot = get_bot()
await bot.call_api("wx.delete_friend", user_id="wxid_xxxxx")
拓展
修改好友或群聊备注action: wx.set_remark
字段名 | 数据类型 | 说明 |
---|---|---|
user_id | string | 好友或群聊wxid |
remark | string | 备注 |
无
{
"action": "wx.set_remark",
"params": {
"user_id": "wxid_xxxxx",
"remark": "备注"
}
}
{
"status": "ok",
"retcode": 0,
"data": null,
"message": ""
}
from nonebot.adapters.onebot.v12 import Bot, MessageSegment
from nonebot import get_bot
async def test():
bot = get_bot()
await bot.call_api("wx.set_remark", user_id="wxid_xxxxx", remark="备注")
拓展
设置群公告action: wx.set_group_announcement
注意权限
请确认具有相关权限再调用。
字段名 | 数据类型 | 说明 |
---|---|---|
group_id | string | 群聊wxid |
announcement | string | 公告 |
无
{
"action": "wx.set_group_announcement",
"params": {
"group_id": "wxid_xxxxx",
"announcement": "公告"
}
}
{
"status": "ok",
"retcode": 0,
"data": null,
"message": ""
}
from nonebot.adapters.onebot.v12 import Bot, MessageSegment
from nonebot import get_bot
async def test():
bot = get_bot()
await bot.call_api("wx.set_group_announcement", group_id="wxid_xxxxx", announcement="公告")
拓展
设置群昵称action: wx.set_group_nickname
字段名 | 数据类型 | 说明 |
---|---|---|
group_id | string | 群聊 ID |
nickname | string | 昵称 |
无
{
"action": "wx.set_group_nickname",
"params": {
"group_id": "wxid_xxxxx",
"nickname": "昵称"
}
}
{
"status": "ok",
"retcode": 0,
"data": null,
"message": ""
}
from nonebot.adapters.onebot.v12 import Bot, MessageSegment
from nonebot import get_bot
async def test():
bot = get_bot()
await bot.call_api("wx.set_group_nickname", group_id="wxid_xxxxx", nickname="昵称")
拓展
获取群成员昵称action: wx.get_groupmember_nickname
字段名 | 数据类型 | 说明 |
---|---|---|
group_id | string | 群聊 ID |
user_id | string | 群成员 ID |
str
: 群成员昵称
{
"action": "wx.get_groupmember_nickname",
"params": {
"group_id": "wxid_xxxxx",
"user_id": "wxid_xxxxx"
}
}
{
"status": "ok",
"retcode": 0,
"data": "昵称",
"message": ""
}
from nonebot.adapters.onebot.v12 import Bot, MessageSegment
from nonebot import get_bot
async def test():
bot = get_bot()
nickname = await bot.call_api("wx.get_groupmember_nickname", group_id="wxid_xxxxx", user_id="wxid_xxxxx")
拓展
删除群成员action: wx.delete_groupmember
注意权限
请确认具有相关权限再调用。
字段名 | 数据类型 | 说明 |
---|---|---|
group_id | string | 群聊 ID |
user_list | str/list[str] | 群成员 ID,支持列表删除 |
无
{
"action": "wx.delete_groupmember",
"params": {
"group_id": "wxid_xxxxx",
"user_list": "wxid_xxxxx"
}
}
{
"status": "ok",
"retcode": 0,
"data": null,
"message": ""
}
from nonebot.adapters.onebot.v12 import Bot, MessageSegment
from nonebot import get_bot
async def test():
bot = get_bot()
await bot.call_api("wx.delete_groupmember", group_id="wxid_xxxxx", user_list="wxid_xxxxx")
拓展
添加群成员action: wx.add_groupmember
注意权限
请确认具有相关权限再调用。
字段名 | 数据类型 | 说明 |
---|---|---|
group_id | string | 群聊 ID |
user_list | str/list[str] | 群成员 ID,支持列表添加 |
无
{
"action": "wx.add_groupmember",
"params": {
"group_id": "wxid_xxxxx",
"user_list": "wxid_xxxxx"
}
}
{
"status": "ok",
"retcode": 0,
"data": null,
"message": ""
}
from nonebot.adapters.onebot.v12 import Bot, MessageSegment
from nonebot import get_bot
async def test():
bot = get_bot()
await bot.call_api("wx.add_groupmember", group_id="wxid_xxxxx", user_list="wxid_xxxxx")
拓展
获取公众号历史消息action: wx.get_public_history
一次获取十条推送记录,可通过 offset 参数调节。
字段名 | 数据类型 | 说明 |
---|---|---|
public_id | string | 公众号 ID |
offset | int | 起始偏移,为空的话则从新到久获取十条,该值可从返回数据中取得 |
list
: 消息列表
{
"action": "wx.get_public_history",
"params": {
"public_id": "wxid_xxxxx",
"offset": 0
}
}
{
"status": "ok",
"retcode": 0,
"data": [
{
"title": "标题",
"content": "内容",
"url": "链接",
"time": 1620000000
}
],
"message": ""
}
from nonebot.adapters.onebot.v12 import Bot, MessageSegment
from nonebot import get_bot
async def test():
bot = get_bot()
history = await bot.call_api("wx.get_public_history", public_id="wxid_xxxxx", offset=0)
拓展
转发消息action: wx.send_forward_msg
只支持单条转发
字段名 | 数据类型 | 说明 |
---|---|---|
user_id | string | 用户 ID |
message_id | string | 消息 ID |
无
{
"action": "wx.send_forward_msg",
"params": {
"user_id": "wxid_xxxxx",
"message_id": "wxid_xxxxx"
}
}
{
"status": "ok",
"retcode": 0,
"data": null,
"message": ""
}
from nonebot.adapters.onebot.v12 import Bot, MessageSegment
from nonebot import get_bot
async def test():
bot = get_bot()
await bot.call_api("wx.send_forward_msg", user_id="wxid_xxxxx", message_id="wxid_xxxxx")
拓展
发送原始xml消息action: wx.send_raw_xml
字段名 | 数据类型 | 说明 |
---|---|---|
user_id | string | 用户 ID |
xml | string | xml消息 |
image_path | string | 图片路径,可选 |
无
{
"action": "wx.send_raw_xml",
"params": {
"user_id": "wxid_xxxxx",
"xml": "<xml>...</xml>",
"image_path": "C:\\Users\\xxx\\Pictures\\xxx.jpg"
}
}
{
"status": "ok",
"retcode": 0,
"data": null,
"message": ""
}
from nonebot.adapters.onebot.v12 import Bot, MessageSegment
from nonebot import get_bot
async def test():
bot = get_bot()
await bot.call_api("wx.send_raw_xml", user_id="wxid_xxxxx", xml="<xml>...</xml>")
拓展
发送名片action: wx.send_card
字段名 | 数据类型 | 说明 |
---|---|---|
user_id | string | 用户 ID |
card_id | string | 名片 ID |
nickname | string | 名片昵称 |
无
{
"action": "wx.send_card",
"params": {
"user_id": "wxid_xxxxx",
"card_id": "wxid_xxxxx",
"nickname": "昵称"
}
}
{
"status": "ok",
"retcode": 0,
"data": null,
"message": ""
}
from nonebot.adapters.onebot.v12 import Bot, MessageSegment
from nonebot import get_bot
async def test():
bot = get_bot()
await bot.call_api("wx.send_card", user_id="wxid_xxxxx", card_id="wxid_xxxxx", nickname="昵称")
拓展
清理文件缓存action: wx.clean_cache
字段名 | 数据类型 | 说明 |
---|---|---|
days | int | 清理多少天前的缓存 |
int
: 清理的文件数量
{
"action": "wx.clean_cache",
"params": {
"days": 7
}
}
{
"status": "ok",
"retcode": 0,
"data": 10,
"message": ""
}
from nonebot.adapters.onebot.v12 import Bot, MessageSegment
from nonebot import get_bot
async def test():
bot = get_bot()
await bot.call_api("wx.clean_cache", days=7)