pub struct MpClient { /* private fields */ }Expand description
小程序异步客户端
Implementations§
Source§impl MpClient
impl MpClient
Sourcepub async fn access_token(&self) -> Result<String, MpError>
pub async fn access_token(&self) -> Result<String, MpError>
获取有效 access_token(带内存缓存)
Sourcepub async fn refresh_access_token(&self) -> Result<String, MpError>
pub async fn refresh_access_token(&self) -> Result<String, MpError>
强制刷新 access_token
Sourcepub async fn get_json<T>(
&self,
path: &str,
query: &[(&str, String)],
) -> Result<T, MpError>where
T: DeserializeOwned,
pub async fn get_json<T>(
&self,
path: &str,
query: &[(&str, String)],
) -> Result<T, MpError>where
T: DeserializeOwned,
GET JSON(自动附加 access_token)
Sourcepub async fn post_json<B, T>(&self, path: &str, body: &B) -> Result<T, MpError>where
B: Serialize,
T: DeserializeOwned,
pub async fn post_json<B, T>(&self, path: &str, body: &B) -> Result<T, MpError>where
B: Serialize,
T: DeserializeOwned,
POST JSON(自动附加 access_token)
Sourcepub async fn post_query<T>(
&self,
path: &str,
query: &[(&str, String)],
) -> Result<T, MpError>where
T: DeserializeOwned,
pub async fn post_query<T>(
&self,
path: &str,
query: &[(&str, String)],
) -> Result<T, MpError>where
T: DeserializeOwned,
POST(仅查询参数、无 JSON body),用于 OCR / 图像处理的 img_url 模式
Sourcepub async fn post_query_no_token<T>(
&self,
path: &str,
query: &[(&str, String)],
) -> Result<T, MpError>where
T: DeserializeOwned,
pub async fn post_query_no_token<T>(
&self,
path: &str,
query: &[(&str, String)],
) -> Result<T, MpError>where
T: DeserializeOwned,
POST(仅查询参数、不带 access_token),如 clear_quota/v2
Sourcepub async fn post_multipart<T>(
&self,
path: &str,
query: &[(&str, String)],
fields: &[(&str, String)],
file: Option<(&str, &str, Vec<u8>)>,
) -> Result<T, MpError>where
T: DeserializeOwned,
pub async fn post_multipart<T>(
&self,
path: &str,
query: &[(&str, String)],
fields: &[(&str, String)],
file: Option<(&str, &str, Vec<u8>)>,
) -> Result<T, MpError>where
T: DeserializeOwned,
POST multipart/form-data(可选查询参数、文本字段、文件)
file:(字段名, 文件名, 字节内容),常见字段名为 img
Sourcepub async fn post_bytes<B>(
&self,
path: &str,
body: &B,
) -> Result<Vec<u8>, MpError>where
B: Serialize,
pub async fn post_bytes<B>(
&self,
path: &str,
body: &B,
) -> Result<Vec<u8>, MpError>where
B: Serialize,
POST JSON,返回原始字节(小程序码等可能返回图片)
Sourcepub async fn get_json_no_token<T>(
&self,
path_with_query: &str,
) -> Result<T, MpError>where
T: DeserializeOwned,
pub async fn get_json_no_token<T>(
&self,
path_with_query: &str,
) -> Result<T, MpError>where
T: DeserializeOwned,
不带 access_token 的 GET(如 code2session)
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for MpClient
impl !UnwindSafe for MpClient
impl Freeze for MpClient
impl Send for MpClient
impl Sync for MpClient
impl Unpin for MpClient
impl UnsafeUnpin for MpClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more