Expand description
Connect to WeChat, authenticate, synchronize and submit messages with NativeClient.
Most server operations are methods on NativeClient, rather than free
functions in this crate’s Functions list. AccountState holds accepted
credentials; it is secret, mutable state, not an API access token.
| Task | Start here |
|---|---|
| QR login | NativeClient::start_qr_login, NativeClient::poll_login, NativeClient::complete_login |
| Receive a sync page | NativeClient::sync, wire::decode_add_message |
| Send text | NativeClient::send_text, TextSendResult |
| Contacts and rooms | NativeClient::lookup_contacts, NativeClient::lookup_room |
| Attachments | media, media_send, NativeClient::send_file |
| Low-level encoding | wire, protobuf |
§Send one text message
After an approved login, call the client method with the recipient’s exact WeChat username. Persist the task ID, timestamp and intended operation in your application’s recovery record before submission. A client ID is not a server guarantee against duplicate sends.
use wechat_protocol::{wire, AccountState, NativeClient, TextSendResult};
fn send_once(
client: &NativeClient,
state: &mut AccountState,
recipient: &str,
text: &str,
task_id: &str,
created_at: u32,
) -> anyhow::Result<TextSendResult> {
let client_id = wire::client_message_id(task_id.as_bytes());
anyhow::ensure!(client_id != 0, "Choose another task ID");
client.send_text(state, recipient, text, created_at, client_id)
}The source package includes runnable qr_login, send_text and sync_once
examples. They keep credentials in memory and perform no profile writes.
§Application responsibilities
The crate implements supported wire operations, transport authentication and response decoding. The embedding application owns credential storage, send intents, uncertainty handling, sync recovery and official-profile writeback. An accepted receipt establishes server acceptance, not recipient playback or completed local history. An error after submission must not cause a blind resend.
This library does not launch or load the official client. Peer responses pass pinned MMTLS signature and record authentication before business decode. Network methods block; async applications must use a blocking worker.
Re-exports§
pub use crate::wire::AddMessage;pub use crate::wire::AvatarBytes;pub use crate::wire::ContactLookup;pub use crate::wire::ContactRecord;pub use crate::wire::Heartbeat;pub use crate::wire::InitContactPage;pub use crate::wire::RoomMember;pub use crate::wire::RoomRoster;pub use crate::wire::SyncBatch;pub use crate::wire::SyncCommand;pub use crate::wire::TextSendResult;pub use crate::wire::VoiceChunk;
Modules§
- business
- Business encryption is separate from authenticated MMTLS records.
- contact_
sync - Linux 4.1.13.26 contact stream (CGI8674). This stream has its own
rs_config/sync_11cursor; the message SyncKey is only request context. - crypto
- file_
upload - File-upload message reservation. This authenticated request can affect the account’s message state; callers must persist its receipt and never retry an uncertain response automatically.
- media
- Bounded native CDN transport. This uses the observed HTTP carrier on port 443, not HTTPS. Media encryption and advertised size/digests are checked separately.
- media_
send - Final media-message metadata. CDN upload and message submission are separate steps; persist source bytes, generated keys and intent before either step.
- mmtls
- Fresh pinned MMTLS handshake and authenticated shortlink exchange.
- protobuf
- Bounded numbered protobuf primitives. Unknown fields and full u64 values survive.
- push
- Persistent authenticated incoming notifications. The outer longlink command is distinct from the encrypted business CGI: heartbeat 238/518, sync 121/138.
- quote_
send - Quoted app-message metadata. Callers resolve the selected message and persist this reference and the final XML before submitting a send attempt.
- silk
- Bounded independent SILK SDK wrapper. Public source/license pins are under vendor/silk; no WeChat codec library is linked or loaded.
- wire
- Typed numbered business messages for the supported native profile.
Structs§
- Account
State - Accepted credentials. Serialize only into the service’s encrypted state vault.
- Auth
Snapshot - Raw accepted auth sections, retained only inside the encrypted account state. The update mask describes native application gates; presence alone does not mean an optional section changed active account credentials.
- Device
Profile - Group
Detail - Group
Member Result - Group
Metadata Page - Group
Mutation Reply - Group
Rpc - Login
Attempt - Logout
Reply - Message
Recall - Message
Recall Reply - Metadata
Reply - Native
Client - Blocking client for supported WeChat server operations.
- Native
Options - Session
Read Notification - Session
Read Reply
Enums§
Constants§
Functions§
- contact_
notification_ request - Direct contact writes use the official full-contact oplog shape. Fetch a current record first; change only the mute bit and preserve all other bytes.
- contact_
pinning_ requests - Ordinary Linux pin/unpin copies the complete contact, changes primary bit 0x800, and sends ModContact through oplog2. The secondary mask is a uint64. A folded group is removed from its message box in a preceding oplog74 step.
- controlled_
contact_ fields - Extract only the proved field-control IDs. Version ordering is deliberately not guessed: callers preserve these fields and retain the unresolved update.
- decode_
group_ detail - decode_
group_ inventory - decode_
group_ mutation - group_
detail_ request - group_
inventory_ request - group_
mutation_ requests - Steps are separate requests. An uncertain step must stop the entire flow. A known cleanup rejection can be retained while a later quit is attempted.
- is_
retryable_ login_ poll_ error - Polling an issued login challenge is repeatable. This does not authorize retrying QR creation, credential exchange, sends or rejected authentication.
- login_
lan_ error_ reason - observed_
created_ group - Recover a valid create identity even when another success field is malformed. This is evidence for review, never permission to repeat the creation.
- ordinary_
identity