wechat-api-rs 0.1.0

A Rust SDK for WeChat Official Account and Mini Program APIs
Documentation
# WeChat SDK 使用指南

## 打包发布指南

### 方案一:发布到 crates.io

#### 1. 准备发布

```bash
# 确保项目构建通过
cargo build --release

# 运行测试
cargo test

# 检查包的内容
cargo package --dry-run
```

#### 2. 发布到 crates.io

```bash
# 登录 crates.io(需要先注册账号)
cargo login

# 发布包
cargo publish
```

#### 3. 其他项目中使用

在其他项目的 `Cargo.toml` 中添加:

```toml
[dependencies]
wechat-api-rs = "0.1.0"
```

### 方案二:作为 Git 依赖

如果不想发布到 crates.io,可以直接使用 Git 仓库:

```toml
[dependencies]
wechat-api-rs = { git = "https://github.com/wufei/wechat-sdk.git" }

# 或指定分支/标签
wechat-api-rs = { git = "https://github.com/wufei/wechat-sdk.git", branch = "main" }
wechat-api-rs = { git = "https://github.com/wufei/wechat-sdk.git", tag = "v0.1.0" }
```

### 方案三:本地路径依赖(开发时)

```toml
[dependencies]
wechat-api-rs = { path = "../wechat-sdk" }
```

## SDK 使用示例

### 基础使用

```rust
use wechat_api_rs::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()?;

    // 发送文本消息(公众号)
    #[cfg(feature = "official")]
    {
        client.official()
            .message()
            .to("user_openid")
            .text("Hello World")
            .send().await?;
    }

    // 验证登录码(小程序)
    #[cfg(feature = "miniapp")]
    {
        let session = client.miniapp()
            .auth()
            .code_to_session("js_code")
            .call().await?;
        println!("Session: {:?}", session);
    }

    Ok(())
}
```

### 功能特性配置

默认启用所有功能:

```toml
[dependencies]
wechat-api-rs = "0.1.0"
```

只使用公众号功能:

```toml
[dependencies]
wechat-sdk = { version = "0.1.0", default-features = false, features = ["official"] }
```

只使用小程序功能:

```toml
[dependencies]
wechat-sdk = { version = "0.1.0", default-features = false, features = ["miniapp"] }
```

启用缓存支持:

```toml
[dependencies]
wechat-sdk = { version = "0.1.0", features = ["cache"] }
```

### 高级配置

```rust
use wechat_api_rs::WeChat;
use std::time::Duration;

#[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")
        .timeout(Duration::from_secs(30))  // 设置超时时间
        .build()?;

    // 获取核心客户端
    let core_client = client.core();

    // 使用核心客户端进行自定义请求
    // let response = core_client.get("https://api.weixin.qq.com/custom/endpoint").await?;

    Ok(())
}
```

## 项目结构

这是一个 Workspace 项目,包含以下子包:

- `wechat-core`: 核心功能(HTTP 客户端、认证、错误处理)
- `wechat-types`: 类型定义
- `wechat-crypto`: 加密相关工具
- `wechat-official`: 公众号 API
- `wechat-miniapp`: 小程序 API
- `examples`: 使用示例

## 版本管理

### 发布新版本

1. 更新版本号(在 workspace 的 `Cargo.toml` 中):
```toml
[workspace.package]
version = "0.2.0"  # 新版本号
```

2. 更新 CHANGELOG.md

3. 创建 Git 标签:
```bash
git tag v0.2.0
git push origin v0.2.0
```

4. 发布到 crates.io:
```bash
cargo publish
```

### 语义化版本

- `0.x.y`: 主要功能开发阶段
- `1.0.0`: 第一个稳定版本
- `1.x.0`: 新功能添加(向后兼容)
- `1.0.x`: Bug 修复

## 文档生成

```bash
# 生成文档
cargo doc --open

# 生成所有功能的文档
cargo doc --all-features --open
```

## 许可证

本项目使用 MIT 或 Apache 2.0 双许可证。

## 贡献指南

1. Fork 项目
2. 创建功能分支 (`git checkout -b feature/amazing-feature`)
3. 提交改动 (`git commit -m 'Add some amazing feature'`)
4. 推送到分支 (`git push origin feature/amazing-feature`)
5. 开启 Pull Request

## 支持

如有问题,请在 GitHub 上创建 Issue。