Skip to main content

WxOpenOAuth2ServiceImpl

Struct WxOpenOAuth2ServiceImpl 

Source
pub struct WxOpenOAuth2ServiceImpl { /* private fields */ }
Expand description

oauth2 网页授权服务实现(对应 Java WxOpenOAuth2ServiceImpl)。

Implementations§

Source§

impl WxOpenOAuth2ServiceImpl

Source

pub fn new( app_id: String, app_secret: String, wx_open_service: Arc<dyn WxOpenService>, ) -> Self

构建服务(对应 Java new WxOpenOAuth2ServiceImpl(String appId, String appSecret, WxOpenConfigStorage openConfigStorage))。

§参数
  • app_id:授权方 appid
  • app_secret:授权方 appsecret
  • wx_open_service:门面服务强引用(内部降级为弱引用)
Source

pub async fn validate_access_token( &self, token: &WxOAuth2AccessToken, ) -> Result<bool, WxErrorException>

验证 access token 是否有效(对应 Java validateAccessToken(WxOAuth2AccessToken token))。

Java:GET /sns/authWxErrorException 捕获返回 false, IOExceptionWxRuntimeException;Rust 以 HTTP/解析错误抛 -99、业务错误返回 false 表达(ADAPTED:Rust 无 WxRuntimeException,统一以 Err 表达 IO 异常)。

Trait Implementations§

Source§

impl WxOAuth2Service for WxOpenOAuth2ServiceImpl

Source§

fn build_authorization_url( &self, redirect_uri: &str, scope: &str, state: &str, ) -> String

构建网页授权 URL(对应 Java buildAuthorizationUrl(...)QRCONNECT_URL 格式化——redirect_uri 经 JS encodeURIComponent 语义编码、state 经 trim)。

注意:Java 使用 WxMpApiUrl.Other.QRCONNECT_URL(网站应用授权 登录链接 /connect/qrconnect),Rust 严格镜像。

Source§

fn get_access_token<'life0, 'life1, 'async_trait>( &'life0 self, code: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<WxOAuth2AccessToken, WxErrorException>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

用 code 获取 access token(对应 Java getAccessToken(String code) → 委托 getAccessToken(appId, appSecret, code))。

Source§

fn get_access_token_with<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, app_id: &'life1 str, app_secret: &'life2 str, code: &'life3 str, ) -> Pin<Box<dyn Future<Output = Result<WxOAuth2AccessToken, WxErrorException>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

用 code 获取 access token(对应 Java getAccessToken(String appId, String appSecret, String code): GET /sns/oauth2/access_token?appid=&secret=&code=)。

Source§

fn refresh_access_token<'life0, 'life1, 'async_trait>( &'life0 self, refresh_token: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<WxOAuth2AccessToken, WxErrorException>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

刷新 access token(对应 Java refreshAccessToken(String refreshToken):GET /sns/oauth2/refresh_token?appid=&grant_type=refresh_token&refresh_token=)。

Source§

fn get_user_info<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, token: &'life1 WxOAuth2AccessToken, lang: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<WxOAuth2UserInfo, WxErrorException>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

获取用户信息(对应 Java getUserInfo(WxOAuth2AccessToken token, String lang):lang 为 null 时默认 zh_CN,GET /sns/userinfo?access_token=&openid=&lang=)。

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more