Skip to main content

Crate wechat_protocol

Crate wechat_protocol 

Source
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.

§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_11 cursor; 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§

AccountState
Accepted credentials. Serialize only into the service’s encrypted state vault.
AuthSnapshot
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.
DeviceProfile
GroupDetail
GroupMemberResult
GroupMetadataPage
GroupMutationReply
GroupRpc
LoginAttempt
LogoutReply
MessageRecall
MessageRecallReply
MetadataReply
NativeClient
Blocking client for supported WeChat server operations.
NativeOptions
SessionReadNotification
SessionReadReply

Enums§

GroupMutation
LoginStatus

Constants§

MAX_MESSAGE_BYTES

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