async_wechat/official_account/
quota.rs1use std::collections::HashMap;
2
3use crate::OfficialAccount;
4
5use super::core::BasicResponse;
6
7pub(crate) const CLEAR_QUOTA_URL: &str = "https://api.weixin.qq.com/cgi-bin/clear_quota?access_token=";
8
9#[cfg(test)]
10mod tests {
11
12 use crate::{Config, OfficialAccount};
13 use std::env;
14
15 #[tokio::test]
16 async fn get_qr_ticket() {
17 dotenv::dotenv().ok();
18
19 let appid = env::var("APPID").expect("APPID not set");
20 let app_secret = env::var("APP_SECRET").expect("APP_SECRET not set");
21 let redis_url = env::var("REDIS_URL").expect("REDIS_URL not set");
22
23 let config = Config {
24 appid: appid.clone(),
25 app_secret: app_secret.clone(),
26 token: "wechat".to_string(),
27 encoding_aes_key: None,
28 };
29 let account = OfficialAccount::new(config, redis_url);
30
31 let at = account.clear_quota().await;
32 println!("get_qr_ticket: {:#?}", at);
33 }
34}
35
36impl OfficialAccount {
37 pub async fn clear_quota(&self) -> Result<(), Box<dyn std::error::Error>> {
39 let token = self.token().await?;
40
41 let mut params = HashMap::new();
42 params.insert("appid".to_string(), self.config.appid.clone());
43
44 let url = format!("{}{}", CLEAR_QUOTA_URL, token);
45 let response = match self.client.post(url).json(¶ms).send().await {
46 Ok(r) => r,
47 Err(e) => {
48 println!("json err: {:#?}", e);
49 return Err(e.into());
50 }
51 };
52
53 if let Err(err) = response.json::<BasicResponse>().await {
54 println!("json err: {:#?}", err);
55 return Err(err.into());
56 }
57
58 Ok(())
59 }
60}