wechat_backend_auth/
config.rs

1use crate::types::{AppId, AppSecret};
2use std::time::Duration;
3use typed_builder::TypedBuilder;
4
5/// HTTP传输层配置
6#[derive(Debug, Clone, TypedBuilder)]
7pub struct HttpConfig {
8    /// 请求超时时间(默认30秒)
9    #[builder(default = Duration::from_secs(30))]
10    pub timeout: Duration,
11
12    /// 连接超时时间(默认10秒)
13    #[builder(default = Duration::from_secs(10))]
14    pub connect_timeout: Duration,
15
16    /// 最大重试次数(默认3次)
17    #[builder(default = 3)]
18    pub max_retries: u32,
19
20    /// 重试延迟(默认1秒)
21    #[builder(default = Duration::from_secs(1))]
22    pub retry_delay: Duration,
23}
24
25impl Default for HttpConfig {
26    fn default() -> Self {
27        Self::builder().build()
28    }
29}
30
31/// 后端授权配置
32#[derive(Debug, Clone, TypedBuilder)]
33pub struct BackendConfig {
34    /// 微信应用ID(公众号、开放平台、移动应用通用)
35    pub app_id: AppId,
36
37    /// 应用密钥
38    pub app_secret: AppSecret,
39
40    /// HTTP传输层配置
41    #[builder(default)]
42    pub http: HttpConfig,
43}
44
45impl BackendConfig {
46    /// 获取应用ID
47    pub fn app_id(&self) -> &AppId {
48        &self.app_id
49    }
50
51    /// 获取应用密钥
52    pub fn app_secret(&self) -> &AppSecret {
53        &self.app_secret
54    }
55
56    /// 获取HTTP配置
57    pub fn http_config(&self) -> &HttpConfig {
58        &self.http
59    }
60}