| Crates.io | wechat-api-rs |
| lib.rs | wechat-api-rs |
| version | 0.1.0 |
| created_at | 2025-09-13 03:26:09.00824+00 |
| updated_at | 2025-09-13 03:26:09.00824+00 |
| description | A Rust SDK for WeChat Official Account and Mini Program APIs |
| homepage | https://github.com/wufei/wechat-api-rs |
| repository | https://github.com/wufei/wechat-api-rs |
| max_upload_size | |
| id | 1837190 |
| size | 164,763 |
一个功能完整、类型安全、易于使用的Rust微信开发SDK,支持微信公众号和小程序APIs。
[dependencies]
wechat-sdk = "0.1.0"
tokio = { version = "1.0", features = ["full"] }
use wechat_sdk::WeChat;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// 创建微信客户端
let client = WeChat::builder()
.app_id("your_app_id")
.app_secret("your_app_secret")
.build()?;
// 发送公众号消息
client.official()
.message()
.to("user_openid")
.text("Hello World!")
.send().await?;
// 小程序登录验证
let session = client.miniapp()
.auth()
.code_to_session("js_code")
.call().await?;
println!("用户OpenID: {}", session.openid);
Ok(())
}
| 模块 | 功能 | 特性标志 |
|---|---|---|
| wechat-core | 核心功能 | - |
| wechat-official | 公众号API | official |
| wechat-miniapp | 小程序API | miniapp |
| wechat-crypto | 加密解密 | - |
| wechat-types | 类型定义 | - |
# 只使用公众号功能
wechat-sdk = { version = "0.1.0", default-features = false, features = ["official"] }
# 只使用小程序功能
wechat-sdk = { version = "0.1.0", default-features = false, features = ["miniapp"] }
# 添加缓存支持
wechat-sdk = { version = "0.1.0", features = ["cache"] }
┌─────────────────────────────────────────┐
│ 用户API层 (Public API) │
├─────────────────────────────────────────┤
│ 业务逻辑层 (Business Logic) │
├─────────────────────────────────────────┤
│ 协议层 (Protocol Layer) │
├─────────────────────────────────────────┤
│ 传输层 (Transport Layer) │
└─────────────────────────────────────────┘
查看 examples 目录获取更多示例:
# 设置环境变量
export WECHAT_APP_ID="your_app_id"
export WECHAT_APP_SECRET="your_app_secret"
# 运行基础示例
cargo run --example basic_usage
# 运行Web服务器示例
cargo run --example axum_integration --features web-axum
git clone https://github.com/your-username/wechat-sdk-rust.git
cd wechat-sdk-rust
cargo build
# 运行所有测试
cargo test
# 运行特定模块测试
cargo test --package wechat-core
cargo test --package wechat-official
cargo test --package wechat-miniapp
欢迎贡献代码!请阅读 CONTRIBUTING.md 了解贡献指南。
git checkout -b feature/amazing-feature)git commit -m 'Add amazing feature')git push origin feature/amazing-feature)本项目采用 MIT 或 Apache-2.0 双许可证。详见:
感谢所有贡献者和以下项目的灵感:
如果你在使用过程中遇到问题: