Skip to main content

wechat_mp_ops/
lib.rs

1//! 微信小程序 openApi 管理(运维)
2//!
3//! 文档:[openApi 管理](https://developers.weixin.qq.com/miniprogram/dev/server/API/openApi-mgnt/)
4
5mod network;
6mod quota;
7mod rid;
8
9pub use network::*;
10pub use quota::*;
11pub use rid::*;
12
13use wechat_mp_core::MpClient;
14
15/// openApi 管理 / 运维 API 门面
16#[derive(Clone)]
17pub struct OpsApi {
18    client: MpClient,
19}
20
21impl OpsApi {
22    pub fn new(client: MpClient) -> Self {
23        Self { client }
24    }
25
26    pub fn client(&self) -> &MpClient {
27        &self.client
28    }
29
30    /// 微信 API 服务器 IP
31    pub async fn get_api_domain_ip(&self) -> wechat_mp_core::Result<IpListResponse> {
32        get_api_domain_ip(&self.client).await
33    }
34
35    /// 微信推送服务器 IP
36    pub async fn get_callback_ip(&self) -> wechat_mp_core::Result<IpListResponse> {
37        get_callback_ip(&self.client).await
38    }
39
40    /// 网络通信检测
41    pub async fn callback_check(
42        &self,
43        req: &CallbackCheckRequest,
44    ) -> wechat_mp_core::Result<CallbackCheckResponse> {
45        callback_check(&self.client, req).await
46    }
47
48    /// 查询 API 调用额度
49    pub async fn get_api_quota(
50        &self,
51        cgi_path: impl Into<String>,
52    ) -> wechat_mp_core::Result<GetQuotaResponse> {
53        get_api_quota(&self.client, &GetQuotaRequest::new(cgi_path)).await
54    }
55
56    /// 清空账号全部接口日额度
57    pub async fn clear_quota(&self, appid: impl Into<String>) -> wechat_mp_core::Result<()> {
58        clear_quota(&self.client, appid).await
59    }
60
61    /// 清空当前配置 AppID 的全部日额度
62    pub async fn clear_quota_self(&self) -> wechat_mp_core::Result<()> {
63        clear_quota_self(&self.client).await
64    }
65
66    /// 重置指定接口日额度
67    pub async fn clear_api_quota(
68        &self,
69        cgi_path: impl Into<String>,
70    ) -> wechat_mp_core::Result<()> {
71        clear_api_quota(&self.client, cgi_path).await
72    }
73
74    /// 使用 AppSecret 清空额度
75    pub async fn clear_quota_by_secret(
76        &self,
77        appid: impl Into<String>,
78        appsecret: impl Into<String>,
79    ) -> wechat_mp_core::Result<()> {
80        clear_quota_by_secret(&self.client, appid, appsecret).await
81    }
82
83    /// 使用当前配置凭据清空额度
84    pub async fn clear_quota_by_secret_self(&self) -> wechat_mp_core::Result<()> {
85        clear_quota_by_secret_self(&self.client).await
86    }
87
88    /// 查询 rid 详情
89    pub async fn get_rid_info(
90        &self,
91        rid: impl Into<String>,
92    ) -> wechat_mp_core::Result<GetRidResponse> {
93        get_rid_info(&self.client, rid).await
94    }
95}