pub struct Client { /* private fields */ }Expand description
存储微信小程序的 appid 和 secret
Implementations§
Source§impl Client
impl Client
Sourcepub fn new(app_id: &str, secret: &str) -> Self
pub fn new(app_id: &str, secret: &str) -> Self
ⓘ
use wechat_minapp::Client;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let app_id = "your app id";
let secret = "your app secret";
let client = Client::new(app_id, secret);
Ok(())
}Sourcepub async fn login(&self, code: &str) -> Result<Credential>
pub async fn login(&self, code: &str) -> Result<Credential>
登录凭证校验 https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/user-login/code2Session.html
use axum::{extract::State, response::IntoResponse, Json};
use wechat_minapp::{client::Client, Result};
use serde::Deserialize;
#[derive(Deserialize, Default)]
#[serde(default)]
pub(crate) struct Logger {
code: String,
}
pub(crate) async fn login(
State(client): State<Client>,
Json(logger): Json<Logger>,
) -> Result<impl IntoResponse> {
let credential = client.login(&logger.code).await?;
Ok(())
}Sourcepub async fn access_token(&self) -> Result<String>
pub async fn access_token(&self) -> Result<String>
ⓘ
use wechat_minapp::Client;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let app_id = "your app id";
let secret = "your app secret";
let client = Client::new(app_id, secret);
let access_token = client.access_token().await?;
Ok(())
}Sourcepub async fn stable_access_token(
&self,
force_refresh: impl Into<Option<bool>> + Clone + Send,
) -> Result<String>
pub async fn stable_access_token( &self, force_refresh: impl Into<Option<bool>> + Clone + Send, ) -> Result<String>
ⓘ
use wechat_minapp::Client;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let app_id = "your app id";
let secret = "your app secret";
let client = Client::new(app_id, secret);
let stable_access_token = client.stable_access_token(Some(true)).await?;
Ok(())
}Source§impl Client
impl Client
Sourcepub async fn check_session_key(
&self,
session_key: &str,
open_id: &str,
) -> Result<()>
pub async fn check_session_key( &self, session_key: &str, open_id: &str, ) -> Result<()>
检查登录态是否过期 https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/user-login/checkSessionKey.html
Sourcepub async fn reset_session_key(
&self,
session_key: &str,
open_id: &str,
) -> Result<Credential>
pub async fn reset_session_key( &self, session_key: &str, open_id: &str, ) -> Result<Credential>
重置用户的 session_key https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/user-login/ResetUserSessionKey.html
Source§impl Client
impl Client
Sourcepub async fn qr_code(&self, args: QrCodeArgs) -> Result<QrCode>
pub async fn qr_code(&self, args: QrCodeArgs) -> Result<QrCode>
ⓘ
use wechat_minapp::{Client,QrCodeArgs};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let app_id = "your app id";
let secret = "your app secret";
let client = Client::new(app_id, secret);
let qr_args = QrCodeArgs::builder().path(&page).build()?;
let buffer = minapp.qr_code(qr_args).await?;
Ok(())
}Source§impl Client
impl Client
Sourcepub async fn get_contact(
&self,
code: &str,
open_id: Option<&str>,
) -> Result<Contact>
pub async fn get_contact( &self, code: &str, open_id: Option<&str>, ) -> Result<Contact>
ⓘ
use wechat_minapp::Client;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let app_id = "your app id";
let secret = "your app secret";
let client = Client::new(app_id, secret);
let access_token = client.get_contace("code","openid").await?;
Ok(())
}Trait Implementations§
Auto Trait Implementations§
impl Freeze for Client
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
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