Skip to main content

wechat_mp_sdk/
lib.rs

1//! WeChat Mini Program SDK for Rust
2//!
3//! A complete Rust SDK for the WeChat Mini Program server-side APIs,
4//! covering **128 endpoints** across 24 categories.
5//!
6//! ## API Coverage
7//!
8//! | Category | Endpoints |
9//! |----------|-----------|
10//! | Login / Session | 3 |
11//! | Access Token | 2 |
12//! | OpenAPI Management | 8 |
13//! | Security | 3 |
14//! | User Info | 5 |
15//! | QR Code / Links | 9 |
16//! | Customer Service | 4 |
17//! | Subscribe Messages | 10 |
18//! | Analytics | 11 |
19//! | Operations | 10 |
20//! | Image / OCR | 8 |
21//! | Plugin | 2 |
22//! | Nearby Mini Programs | 4 |
23//! | Cloud Development | 10 |
24//! | Live Streaming | 9 |
25//! | Hardware / IoT | 6 |
26//! | Instant Delivery | 5 |
27//! | Logistics | 6 |
28//! | Service Market | 1 |
29//! | Biometric Auth | 1 |
30//! | Face Verification | 2 |
31//! | WeChat Search | 1 |
32//! | Advertising | 4 |
33//! | WeChat KF | 3 |
34//!
35//! ## Quick Start
36//!
37//! ```rust,ignore
38//! use wechat_mp_sdk::{WechatMp, types::{AppId, AppSecret}};
39//!
40//! #[tokio::main]
41//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
42//!     let wechat = WechatMp::builder()
43//!         .appid(AppId::new("wx1234567890abcdef")?)
44//!         .secret(AppSecret::new("your_secret")?)
45//!         .build()?;
46//!
47//!     // Login with code from wx.login()
48//!     let session = wechat.auth_login("code_from_miniprogram").await?;
49//!     println!("OpenID: {}", session.openid);
50//!
51//!     // Get phone number
52//!     let phone = wechat.get_phone_number("code_from_getPhoneNumber").await?;
53//!     println!("Phone: {}", phone.phone_info.phone_number);
54//!
55//!     Ok(())
56//! }
57//! ```
58//!
59//! ## Modules
60//!
61//! - [`api`] - WeChat API modules (auth, user, message, qrcode, analytics, etc.)
62//! - [`client`] - HTTP client for API calls
63//! - [`crypto`] - Data decryption utilities
64//! - [`error`] - Error types
65//! - [`token`] - Access token management (internal, for advanced users)
66//! - [`types`] - Type definitions for WeChat API entities
67//!
68//! ## Error Handling
69//!
70//! The SDK uses the [`WechatError`] enum for error handling:
71//!
72//! ```rust,ignore
73//! use wechat_mp_sdk::WechatError;
74//!
75//! match result {
76//!     Ok(response) => { /* handle success */ }
77//!     Err(WechatError::Api { code, message }) => {
78//!         eprintln!("API error: {} - {}", code, message);
79//!     }
80//!     Err(WechatError::Http(e)) => {
81//!         eprintln!("HTTP error: {}", e);
82//!     }
83//!     Err(e) => {
84//!         eprintln!("Other error: {}", e);
85//!     }
86//! }
87//! ```
88
89pub mod api;
90pub mod client;
91pub mod crypto;
92pub mod error;
93pub mod middleware;
94pub mod token;
95pub mod types;
96mod utils;
97
98pub use client::{WechatClient, WechatClientBuilder, WechatMp, WechatMpBuilder};
99pub use error::WechatError;