pub struct WxOpenOAuth2ServiceImpl { /* private fields */ }Expand description
oauth2 网页授权服务实现(对应 Java WxOpenOAuth2ServiceImpl)。
Implementations§
Source§impl WxOpenOAuth2ServiceImpl
impl WxOpenOAuth2ServiceImpl
Sourcepub fn new(
app_id: String,
app_secret: String,
wx_open_service: Arc<dyn WxOpenService>,
) -> Self
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:授权方 appidapp_secret:授权方 appsecretwx_open_service:门面服务强引用(内部降级为弱引用)
Sourcepub async fn validate_access_token(
&self,
token: &WxOAuth2AccessToken,
) -> Result<bool, WxErrorException>
pub async fn validate_access_token( &self, token: &WxOAuth2AccessToken, ) -> Result<bool, WxErrorException>
验证 access token 是否有效(对应 Java
validateAccessToken(WxOAuth2AccessToken token))。
Java:GET /sns/auth,WxErrorException 捕获返回 false,
IOException 抛 WxRuntimeException;Rust 以 HTTP/解析错误抛
-99、业务错误返回 false 表达(ADAPTED:Rust 无
WxRuntimeException,统一以 Err 表达 IO 异常)。
Trait Implementations§
Source§impl WxOAuth2Service for WxOpenOAuth2ServiceImpl
impl WxOAuth2Service for WxOpenOAuth2ServiceImpl
构建网页授权 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,
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,
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,
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,
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=)。