Skip to main content

wechat_oa_sdk/
config.rs

1/// WeChat Official Account SDK configuration.
2#[derive(Debug, Clone)]
3pub struct Config {
4    /// The AppID from WeChat Official Account settings.
5    pub app_id: String,
6    /// The AppSecret from WeChat Official Account settings.
7    pub app_secret: String,
8    /// The Token used for server callback signature verification.
9    pub token: String,
10    /// The EncodingAESKey for message encryption/decryption (optional).
11    pub encoding_aes_key: Option<String>,
12}
13
14impl Config {
15    /// Create a new Config.
16    ///
17    /// - `app_id`: AppID from WeChat Official Account settings
18    /// - `app_secret`: AppSecret from WeChat Official Account settings
19    /// - `token`: Token for server callback signature verification (set in 服务器配置)
20    pub fn new(
21        app_id: impl Into<String>,
22        app_secret: impl Into<String>,
23        token: impl Into<String>,
24    ) -> Self {
25        Self {
26            app_id: app_id.into(),
27            app_secret: app_secret.into(),
28            token: token.into(),
29            encoding_aes_key: None,
30        }
31    }
32
33    pub fn with_encoding_aes_key(mut self, key: impl Into<String>) -> Self {
34        self.encoding_aes_key = Some(key.into());
35        self
36    }
37}