Skip to main content

wxpay_rs/
lib.rs

1//! 微信支付 API v3 Rust SDK
2//!
3//! `wxpay-rs` 是一个用于微信支付 API v3 的 Rust SDK,提供了完整的支付、退款、转账等功能。
4//!
5//! # 特性
6//!
7//! - **类型安全** - 使用 Rust 类型系统确保 API 调用的安全性
8//! - **异步支持** - 基于 Tokio 的全异步实现
9//! - **高性能** - 零成本抽象,无 GC 停顿
10//! - **完整功能** - 支持微信支付 API v3 的所有主要功能
11//!
12//! # 快速开始
13//!
14//! ```rust,no_run
15//! use wxpay_rs::{WxPayClient, WxPayConfig};
16//!
17//! #[tokio::main]
18//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
19//!     // 创建配置
20//!     let config = WxPayConfig::builder()
21//!         .app_id("wx88888888")
22//!         .merchant_id("1900000109")
23//!         .api_v3_key("abcdefghijklmnopqrstuvwxyz123456")
24//!         .private_key_from_file("path/to/private_key.pem")
25//!         .cert_serial_number("CERT123456")
26//!         .build()?;
27//!
28//!     // 创建客户端
29//!     let client = WxPayClient::new(config).await?;
30//!
31//!     // 使用 JSAPI 服务
32//!     let jsapi = client.jsapi();
33//!     let _ = jsapi;
34//!
35//!     Ok(())
36//! }
37//! ```
38//!
39//! # 模块结构
40//!
41//! - [`config`] - 配置模块
42//! - [`client`] - 客户端模块
43//! - [`auth`] - 认证模块(签名、验签)
44//! - [`crypto`] - 加解密模块
45//! - [`cert`] - 证书管理模块
46//! - [`http`] - HTTP 客户端模块
47//! - [`services`] - 业务服务模块
48//! - [`notify`] - 通知处理模块
49//! - [`utils`] - 工具模块
50//! - [`error`] - 错误类型模块
51
52// 声明模块
53pub mod auth;
54pub mod cert;
55pub mod client;
56pub mod config;
57pub mod crypto;
58pub mod error;
59pub mod http;
60pub mod notify;
61pub mod services;
62pub mod utils;
63
64// 重导出常用类型
65pub use client::{WxPayClient, WxPayClientBuilder};
66pub use config::{Environment, NotifyConfig, NotifyConfigBuilder, WxPayConfig, WxPayConfigBuilder};
67pub use error::{WxPayError, WxPayResult};
68pub use services::transport::{TransportEvent, TransportObserver};
69
70// 条件编译:文档特性
71#[cfg(feature = "docs")]
72pub mod docs;
73
74/// SDK 版本号
75pub const VERSION: &str = env!("CARGO_PKG_VERSION");
76
77/// SDK 名称
78pub const NAME: &str = env!("CARGO_PKG_NAME");
79
80/// 获取 SDK 版本信息
81pub fn version() -> &'static str {
82    VERSION
83}
84
85/// 获取 SDK 名称
86pub fn name() -> &'static str {
87    NAME
88}
89
90#[cfg(test)]
91mod tests {
92    use super::*;
93
94    #[test]
95    fn test_version() {
96        assert!(!version().is_empty());
97    }
98
99    #[test]
100    fn test_name() {
101        assert_eq!(name(), "wxpay-rs");
102    }
103}