← 返回文档中心

VXHook 开发文档

基础main.py软件UI界面与功能调用
基础get_user_info.py获取当前登录用户信息
消息send_message.py发送普通文本消息
消息send_at_message.py发送群聊 @ 消息
消息send_gif.py发送 GIF 表情文件
消息send_image.py发送图片或普通文件
消息send_video.py发送本地视频文件
消息send_voice.py发送 SILK 语音文件
消息send_pat.py发送拍一拍
消息send_miniprogram.py发送微信小程序卡片
消息send_xml.py发送 XML 链接卡片
群聊get_groups.py扫描微信群列表并读取群昵称、备注、room_wxid 和人数
群聊get_room_members.py获取指定群聊成员列表
群聊create_group.py创建群聊
群聊add_room_member_friend.py添加群成员好友(可自定义添加来源)
群聊kick_room_member.py移除群聊指定wxid成员
群聊invite_room_member.py群聊 40 人内:直接拉成员加入群聊
群聊invite_room_member40.py群聊 40 人上:发送链接邀请成员加入群聊
群聊leave_room.py退出指定微信群聊
群聊send_room_announcement.py向指定群聊发送群公告
群聊set_room_nickname.py修改群聊群昵称(需要群主/管理员权限)
群聊set_room_member_nickname.py修改群聊内本人昵称
朋友圈moments_refresh.py刷新并读取最新朋友圈数据
朋友圈moments_user_refresh.py刷新并读取指定好友的朋友圈数据
朋友圈send_moments.py发送文本或图片朋友圈
朋友圈moments_like.py按 feed_id 点赞或取消点赞
朋友圈moments_comment.py按 feed_id 评论朋友圈
好友get_contacts.py查询通讯录(all=全部   wxid=指定联系人)
好友send_card.py发送好友名片
好友set_remark.py修改联系人备注昵称
好友add_contacts.py搜索联系人并发送好友验证
好友delete_friend.py按 wxid 删除指定好友
好友get_search_contact.py搜索联系人并返回加密账号与验证凭证(加好友前置步骤)
工具cdn_download.py下载微信 CDN 原始文件
HOOKhook_text.py实时监听收到的信息
HOOKrecall_text.py实时记录撤回消息msgid
HOOKhook_autoaccept.py监听并自动同意好友申请
HOOKaccept_transfer.py自动接收转账
SQLiteSQLite/SQLite.py初始化SQL数据库
SQLiteSQLite/SQLitePersonalInfo.py读取 SQLite 中的个人信息
SQLiteSQLite/SQLiteContacts.py读取 SQLite 通讯录
SQLiteSQLite/SQLiteGroups.py读取 SQLite 群聊列表
SQLiteSQLite/SQLiteGroupMembers.py读取指定群聊成员
SQLiteSQLite/SQLiteMessageById.py按 msgId 查询消息内容
SQLiteSQLite/SQLiteChatExport.py导出指定会话聊天记录
SQLiteSQLite/SQLiteMessageMonitoring.py实时监控 SQLite 消息表
SQLiteSQLite/SQLitePaymentMonitoring.py实时监控微信收款助手消息
协议text_msg.py协议发送文本消息
协议image_msg.py协议上传并发送图片
协议quote_msg.py协议发送引用回复消息
协议revoke_msg.py协议撤回已发送的消息
协议search_contact.py协议搜索联系人资料
协议verify_user.py协议添加好友
协议fav_msg.py协议收藏文本消息
协议mini_code.py协议获取小程序 code
协议chatroom_member.py协议获取群成员详情
协议hongbao.py协议接收并领取红包
协议geta8key.py协议获取群邀请卡片 A8Key 导航链接
协议join_chatroom.py协议通过邀请链接查询/加入群聊

1. 初始化微信内存空间

Python
from main import init_weixin_space

pm, dll_base, message = init_weixin_space()
if pm is None:
    raise RuntimeError(message)

2. 获取当前登录微信信息

Python
import get_user_info

info = get_user_info.get_user_info(pm, dll_base)
print(info)

1. 发送文本消息

Python
import send_message

send_message.send_message(pm, dll_base, "filehelper", "测试文本信息")

2. 群聊 @ 成员

Python
import send_at_message

send_at_message.send_at_message(
    pm,
    dll_base,
    "73948261508@chatroom",
    "@所有人  艾特全体成员信息",
    "notify@all"
)

3. 发送 GIF 表情

Python
import send_gif

send_gif.send_gif(pm, dll_base, "filehelper", r"C:\1.GIF")

4. 发送图片或文件

Python
import send_image

send_image.send_image(pm, dll_base, "filehelper", r"C:\2.png")
send_image.send_image(pm, dll_base, "filehelper", r"C:\测试.zip")

5. 发送视频

Python
import send_video

send_video.send_video(pm, dll_base, "filehelper", r"C:\3.mp4")

6. 发送语音

Python
import send_voice

send_voice.send_voice(pm, dll_base, "filehelper", r"C:\4.silk")

7. 发送拍一拍

Python
import send_pat

send_pat.send_pat(
    pm,
    dll_base,
    "73948261508@chatroom",
    "wxid_4n8c2v7b5m9k31",
    from_wxid="wxid_sender"
)

8. 发送小程序

Python
import send_miniprogram

send_miniprogram.send_app(
    pm,
    dll_base,
    "filehelper",
    "小程序标题",
    "小程序内容",
    "gh_6cca656d4558@app",
    r"C:\2.png"
)

9. 发送 XML 卡片

Python
import send_xml

send_xml.send_xml(
    pm,
    dll_base,
    "filehelper",
    "https://mp.weixin.qq.com/s/EXAMPLE",
    "XML 卡片标题",
    "gh_example",
    "https://mmbiz.qpic.cn/example/0?wx_fmt=jpeg",
    "卡片昵称"
)

1. 获取群列表

Python
import get_groups

groups = get_groups.get_group_list(
    pm,
    dll_base,
    include_member_count=True,
    member_timeout=3.0,
    member_batch_size=100,
    member_cache_ttl=60.0
)

for group in groups:
    print(
        group["nickname"],
        group["remark"],
        group["wxid"],
        group.get("member_count")
    )

2. 获取群成员

Python
import get_room_members

members = get_room_members.get_room_members(
    pm,
    dll_base,
    "73948261508@chatroom",
    timeout=10.0,
    poll_interval=0.1
)
print(members)

3. 群成员加好友

Python
import add_room_member_friend

status = add_room_member_friend.add_room_member_friend(
    pm,
    dll_base,
    "73948261508@chatroom",
    "wxid_4n8c2v7b5m9k31",
    verify_text="你好",
    # 来源:3=搜索账号(默认),13=手机通讯录,14=群聊,15=搜索手机号
    scene=3,
    timeout=10.0
)
print(status.ok, status.stage, status.message)

4. 踢出群成员

Python
import kick_room_member

kick_room_member.kick_room_member(
    pm, dll_base, "73948261508@chatroom", "wxid_6p2r9x4d8f3j17"
)

5. 拉成员加入群聊

Python
import invite_room_member

invite_room_member.invite_room_member(
    pm,
    dll_base,
    "73948261508@chatroom",
    ["wxid_3m7q5k9v2c8n46", "wxid_8d4f6h2j9p5r73"]
)
Python · 40 人上链接邀请
import invite_room_member40

invite_room_member40.invite_room_member(
    pm,
    dll_base,
    "73948261508@chatroom",
    ["wxid_3m7q5k9v2c8n46", "wxid_8d4f6h2j9p5r73"]
)

6. 退出群聊

Python
import leave_room

leave_room.leave_room(
    pm, dll_base, "73948261508@chatroom", timeout=10.0
)

7. 发送群公告

Python
import send_room_announcement

send_room_announcement.send_room_announcement(
    pm,
    dll_base,
    "73948261508@chatroom",
    "这里填写群公告内容",
    timeout=10.0
)

8. 修改群聊昵称

Python
import set_room_nickname

set_room_nickname.set_room_nickname(
    pm, dll_base, "73948261508@chatroom", "新的群聊昵称"
)

9. 修改群成员昵称

Python
import set_room_member_nickname

set_room_member_nickname.set_room_member_nickname(
    pm, dll_base, "73948261508@chatroom", "新的群成员昵称"
)

10. 创建群聊

Python
import create_group

result = create_group.create_group(
    pm,
    dll_base,
    ["wxid_5t9y3u7i2o6p84", "wxid_2a8s4d7f9g5h61"],
    room_name="项目讨论组"
)
if not result.ok:
    raise RuntimeError(f"{result.stage}: {result.message}")
print(result.room_id)

1. 刷新并读取朋友圈

Python
import moments_refresh

moments_refresh.moments_refresh(pm, dll_base)
moments = moments_refresh.read_latest_moments(pm, dll_base, 20)
print(moments)

2. 发送文本或图片朋友圈

Python
import send_moments

send_moments.send_moments(
    pm, dll_base, "图文朋友圈", [r"C:\2.png"]
)
send_moments.send_moments(pm, dll_base, "纯文本朋友圈", "")

3. 点赞或取消点赞

Python
import moments_like

moments_like.moments_like(pm, dll_base, "14966840275663393331", True)
moments_like.moments_like(pm, dll_base, "14966840275663393331", False)

4. 评论朋友圈

Python
import moments_comment

moments_comment.moments_comment(
    pm, dll_base, "14966840275663393331", "这里填写评论内容"
)

5. 获取指定好友朋友圈

Python
import moments_user_refresh

user_name = "wxid_7h3k9m2p4q6r22"
moments_user_refresh.refresh_user_moments(pm, dll_base, user_name)
items = moments_user_refresh.read_user_moments(
    pm, dll_base, user_name, limit=20
)
print(items)

1. 查询通讯录

Python
import get_contacts

all_contacts = get_contacts.get_contacts(pm, dll_base, "all")
one_contact = get_contacts.get_contacts(pm, dll_base, "wxid_9k3m7n2b6v8c45")

2. 发送好友名片

Python
import send_card

ok = send_card.send_card(
    pm,
    dll_base,
    "filehelper",
    "wxid_9k3m7n2b6v8c45"
)
print(ok)

3. 修改联系人备注

Python
import set_remark

set_remark.set_remark(pm, dll_base, "wxid_4q8w2e6r9t3y57", "新的备注昵称")

4. 搜索加好友

Python
import add_contacts

status = add_contacts.add_contacts(
    pm,
    dll_base,
    "wxid_7u3i9o5p2a8s64",
    "你好",
    scene=3,
    timeout=10.0
)
print(status.ok, status.stage, status.message)

5. 删除好友

Python
import delete_friend

ok = delete_friend.delete_friend(pm, dll_base, "wxid_6d2f8g4h9j3k75")
print(ok)

6. 搜索联系人获取凭证

Python
import get_search_contact

result = get_search_contact.search_contact(
    pm, dll_base, "wxid_7u3i9o5p2a8s64", timeout=10.0
)
print(result.encrypt_username, result.antispam_ticket)

1. CDN 文件下载

Python
import time
import cdn_download

cdn_download.cdn_download(
    pm,
    dll_base,
    str(int(time.time())),
    "305f02010004...",
    "1a4e4595fae41918251bc356a388fef5",
    r"C:\cdn.jpg"
)

2. 微信自动更新控制

Python
app.btn_disable_weixin_update()  # 禁止微信自动更新
app.btn_enable_weixin_update()   # 恢复微信自动更新

1. 消息监听 Hook

Python
import hook_text

def on_message(text):
    print(text)

hook_text.install_msg_hook(pm, dll_base, on_message)
hook_text.uninstall_msg_hook(pm, dll_base, on_message)

2. 撤回消息记录 Hook

Python
import recall_text

def on_recall(text):
    print(text)

recall_text.install_recall_hook(pm, dll_base, on_recall)
recall_text.uninstall_recall_hook(pm, dll_base, on_recall)

3. 自动同意好友申请 Hook

Python
import hook_autoaccept

def on_friend_request(event):
    print(event)

hook_autoaccept.install_tmp_hook(pm, dll_base, on_friend_request)
hook_autoaccept.uninstall_tmp_hook(pm, dll_base)

4. 自动接收转账 Hook

Python
import hook_text

hook_text.install_msg_hook(pm, dll_base, print)
hook_text.set_auto_accept_transfer(True)

1. 初始化 SQLite 数据库

Python
from SQLite import SQLite as sqlite

db = sqlite.initialize_database()
for database_file, key in sqlite.list_database_keys(db):
    print(database_file, key)

2. 读取个人信息

Python
from SQLite import SQLitePersonalInfo as sqlite_personal_info

info = sqlite_personal_info.read_personal_info(db)
print(info)

3. 获取通讯录

Python
from SQLite import SQLiteContacts as sqlite_contacts

contacts = sqlite_contacts.get_contacts(db)
for contact in contacts:
    print(contact)

4. 获取群列表与群成员

Python
from SQLite import SQLiteGroups as sqlite_groups
from SQLite import SQLiteGroupMembers as sqlite_group_members

groups = sqlite_groups.get_groups(db)
print(groups)

members = sqlite_group_members.get_group_members(
    db, "73948261508@chatroom"
)
print(members)

5. 按 msgId 查询消息

Python
from SQLite import SQLiteMessageById as sqlite_message_by_id

messages = sqlite_message_by_id.get_message_by_id(db, 123456789)
for message in messages:
    print(message)

6. 导出聊天记录

Python
from SQLite import SQLiteChatExport as sqlite_chat_export

count = sqlite_chat_export.export_chat_history(
    db,
    "73948261508@chatroom",
    r"C:\chat_history.txt"
)
print(f"导出消息数: {count}")

7. 实时监控消息

Python
from SQLite import SQLiteMessageMonitoring as sqlite_message_monitoring

monitor = sqlite_message_monitoring.MessageMonitor(
    db, lambda text: print(text, end="")
)
started, detail = monitor.start()
if not started:
    raise RuntimeError(detail)

# 程序退出或不再需要时停止后台监控
monitor.stop()

8. 实时监控收款

Python
from SQLite import SQLitePaymentMonitoring as sqlite_payment_monitoring

monitor = sqlite_payment_monitoring.PaymentMonitor(
    db, lambda text: print(text, end="")
)
started, detail = monitor.start()
if not started:
    raise RuntimeError(detail)

monitor.stop()

1. 发送文本消息

Python
import secrets
import time

from protocol.cgi_bin import NativeCgiTransport
from protocol.text_msg import TEXT_SPEC, TextMessage, send_text

transport = NativeCgiTransport(pm.process_id, TEXT_SPEC)
message = TextMessage(
    "filehelper",
    "协议层测试文本",
    int(time.time()),
    secrets.randbelow(0xFFFFFFFF) + 1
)
raw = send_text(message, transport=transport)
print(f"发送成功,响应 {len(raw)} 字节")

2. 上传并发送图片

Python
import get_user_info
from protocol.cgi_bin import NativeCgiTransport
from protocol.image_msg import IMAGE_SPEC, inspect_image, send_image

transport = NativeCgiTransport(pm.process_id, IMAGE_SPEC)
sender = get_user_info.get_user_info(pm, dll_base)["wxid"]
raw = send_image(
    "filehelper",
    inspect_image(r"C:\2.png"),
    transport=transport,
    from_wxid=sender,
    progress=lambda sent, total: print(f"上传 {sent}/{total} 字节")
)
print(f"图片发送成功,响应 {len(raw)} 字节")

3. 发送引用回复消息

Python
import get_user_info
import time

from protocol.cgi_bin import NativeCgiTransport
from protocol.quote_msg import SENDAPPMSG_SPEC, QuotedMessage, send_quote_appmsg

transport = NativeCgiTransport(pm.process_id, SENDAPPMSG_SPEC)
sender = get_user_info.get_user_info(pm, dll_base)["wxid"]
quoted = QuotedMessage(
    svrid=72623859790382856,
    content="被引用的原文内容",
    fromusr="filehelper",
    chatusr="filehelper",
    createtime=int(time.time()),
    displayname="",
    msgsource=""
)
raw = send_quote_appmsg(
    to_user_name="filehelper",
    from_user_name=sender,
    reply_text="引用回复内容",
    quoted=quoted,
    create_time=int(time.time()),
    transport=transport
)
print(f"引用消息发送成功,响应 {len(raw)} 字节")

4. 撤回已发送消息

Python
import get_user_info
import time

from protocol.cgi_bin import NativeCgiTransport
from protocol.revoke_msg import REVOKE_SPEC, revoke_msg

transport = NativeCgiTransport(pm.process_id, REVOKE_SPEC)
sender = get_user_info.get_user_info(pm, dll_base)["wxid"]
raw = revoke_msg(
    client_msg_id=246813579,
    new_msg_id=72623859790382856,
    to_user_name="filehelper",
    from_user=sender,
    create_time=int(time.time()),
    transport=transport
)
print(f"撤回成功,响应 {len(raw)} 字节")

5. 搜索联系人资料

Python
from protocol.cgi_bin import NativeCgiTransport
from protocol.search_contact import (
    SEARCH_SPEC,
    SearchContactResponsePb,
    send_search_contact,
)

transport = NativeCgiTransport(pm.process_id, SEARCH_SPEC)
raw = send_search_contact("wxid_xxx", transport=transport)
response = SearchContactResponsePb.FromString(raw)
print(f"ret={response.base.ret} 昵称={response.nickname.value}")

6. 收藏文本消息

Python
import get_user_info
import time

from protocol.cgi_bin import NativeCgiTransport
from protocol.fav_msg import FAV_SPEC, send_addfav_text

transport = NativeCgiTransport(pm.process_id, FAV_SPEC)
sender = get_user_info.get_user_info(pm, dll_base)["wxid"]
raw = send_addfav_text(
    content="需要收藏的文本内容",
    svrid="72623859790382856",
    fromusr="filehelper",
    tousr="filehelper",
    realchatname=sender,
    createtime=int(time.time()),
    transport=transport
)
print(f"收藏成功,响应 {len(raw)} 字节")

7. 获取小程序 code

Python
from protocol.cgi_bin import NativeCgiTransport
from protocol.mini_code import MINI_SPEC, JsLoginResponsePb, send_minicode

transport = NativeCgiTransport(pm.process_id, MINI_SPEC)
raw = send_minicode("wx9b55f3f034302737", transport=transport)
response = JsLoginResponsePb.FromString(raw)
print(f"ret={response.base.ret} code={response.code}")

8. 获取群成员详情

Python
from protocol.cgi_bin import NativeCgiTransport
from protocol.chatroom_member import (
    CHATROOM_MEMBER_SPEC,
    GetChatroomMemberDetailResponsePb,
    send_chatroom_member_detail,
)

transport = NativeCgiTransport(pm.process_id, CHATROOM_MEMBER_SPEC)
raw = send_chatroom_member_detail("73948261508@chatroom", transport=transport)
response = GetChatroomMemberDetailResponsePb.FromString(raw)
for member in response.member_data.members:
    print(member.user_name.decode("utf-8"), member.nick_name.decode("utf-8"))

9. 接收并领取红包

Python
import get_user_info
from protocol.cgi_bin import NativeCgiTransport
from protocol.hongbao import (
    HB_SPEC,
    OPEN_SPEC,
    parse_response,
    parse_wcpayinfo,
    send_claim_hongbao,
    send_hongbao,
)

pay = parse_wcpayinfo(content)   # content 为红包消息中的 wcpayinfo 内容
session = chat_id                # 红包所在会话的 wxid / room_wxid
send_id = pay["sendid"]
native_url = pay["nativeurl"]
channel_id = pay["channelid"]
nickname = get_user_info.get_user_info(pm, dll_base)["nickname"]

transport = NativeCgiTransport(pm.process_id, HB_SPEC)
raw = send_hongbao(session, send_id, native_url, channel_id, transport=transport)
timing = parse_response(raw)["timing_identifier"]

transport = NativeCgiTransport(pm.process_id, OPEN_SPEC)
raw = send_claim_hongbao(
    session, send_id, native_url, channel_id, timing, nickname, transport=transport
)
print(f"领取成功,响应 {len(raw)} 字节")

10. 协议验证并添加好友

Python
from protocol.cgi_bin import NativeCgiTransport
from protocol.verify_user import VERIFY_SPEC, VerifyUserResponsePb, send_verify_user

transport = NativeCgiTransport(pm.process_id, VERIFY_SPEC)
raw = send_verify_user(
    ticket_v3="v3_xxxx==@stranger",
    ticket_v4="v4_xxxx==@stranger",
    content="你好,我是xxx",
    transport=transport,
    scene=15
)
response = VerifyUserResponsePb.FromString(raw)
print(f"ret={response.base.ret}")

11. 获取 A8Key 导航链接

Python
from protocol.cgi_bin import NativeCgiTransport
from protocol.geta8key import A8KEY_SPEC, GetA8KeyResponsePb, send_a8key

card_url = "https://support.weixin.qq.com/cgi-bin/mmsupport-bin/addchatroombyinvite?ticket=...&exportkey=..."
transport = NativeCgiTransport(pm.process_id, A8KEY_SPEC)
raw = send_a8key(card_url, transport=transport)
response = GetA8KeyResponsePb.FromString(raw)
print(f"ret={response.base.ret} a8key={response.a8key}")

12. 一键进群

Python
from protocol.cgi_bin import NativeCgiTransport
from protocol.geta8key import A8KEY_SPEC, auto_join, get_a8key_navigation, send_a8key

card_url = "https://support.weixin.qq.com/cgi-bin/mmsupport-bin/addchatroombyinvite?ticket=...&exportkey=..."
transport = NativeCgiTransport(pm.process_id, A8KEY_SPEC)
raw = send_a8key(card_url, transport=transport)
nav_url = get_a8key_navigation(raw, card_url)
result = auto_join(nav_url)
print(result["state"], result["room"], result["members"], result["members_after"])

13. 邀请链接查询/入群

Python
from protocol.join_chatroom import InviteClient

client = InviteClient(
    "https://support.weixin.qq.com/cgi-bin/mmsupport-bin/addchatroombyinvite?ticket=...&exportkey=...",
    timeout=20
)
try:
    result = client.run(join=True)
    print(result["state"], result.get("room"), result.get("member_count"))
finally:
    client.session.close()