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 open_wechat::client::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 open_wechat::{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(())
}
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