pub struct OfficialAccount { /* private fields */ }
Implementations§
Source§impl OfficialAccount
impl OfficialAccount
Sourcepub fn get_redirect_url(
&self,
redirect_uri: String,
scope: String,
state: Option<String>,
) -> String
pub fn get_redirect_url( &self, redirect_uri: String, scope: String, state: Option<String>, ) -> String
Sourcepub async fn get_oauth2_token(
&self,
code: String,
) -> Result<AccessTokenResponse, Box<dyn Error>>
pub async fn get_oauth2_token( &self, code: String, ) -> Result<AccessTokenResponse, Box<dyn Error>>
Exchanges the given authorization code for an access token using the WeChat API
This function constructs a request to the WeChat OAuth2 API endpoint with the provided authorization code, app ID, and app secret, and processes the response to retrieve an access token.
§Arguments
code
- AString
containing the authorization code received from the WeChat authorization server.
§Returns
- A
Result
containing anAccessTokenResponse
on success, or a boxed error on failure.
§Errors
- Returns an error if the HTTP request fails or returns a non-success status, or if
the response cannot be deserialized into an
AccessTokenResponse
.
Sourcepub async fn get_userinfo(
&self,
openid: String,
) -> Result<UserInfoResponse, Box<dyn Error>>
pub async fn get_userinfo( &self, openid: String, ) -> Result<UserInfoResponse, Box<dyn Error>>
Retrieves user information from WeChat API using the provided openid
.
This function fetches the access token from the Redis database associated
with the given openid
, constructs a request to the WeChat API to get
user information, and processes the response.
§Arguments
openid
- AString
representing the user’s unique identifier in WeChat.
§Returns
- A
Result
containing aUserInfoResponse
on success, or a boxed error on failure.
§Errors
- Returns an error if the access token is not found in Redis, if the HTTP
request fails or returns a non-success status, or if the response cannot be
deserialized into a
UserInfoResponse
.
Source§impl OfficialAccount
impl OfficialAccount
Deletes all custom menus for the official account
§Returns
- A
Result
containing aString
with the value"ok"
on success, or a boxed error on failure.
§Errors
- Returns an error if the HTTP request fails or returns a non-success status,
or if the response cannot be deserialized into a
BasicResponse
.
Source§impl OfficialAccount
impl OfficialAccount
Sourcepub async fn get_qr_ticket(
&self,
req: TicketRequest,
) -> Result<TicketResponse, Box<dyn Error>>
pub async fn get_qr_ticket( &self, req: TicketRequest, ) -> Result<TicketResponse, Box<dyn Error>>
Create a QR code ticket for the official account
This function creates a QR code ticket for the official account and returns a string representing the ticket.
§Errors
- Returns an error if the HTTP request fails or returns a non-success status,
or if the response cannot be deserialized into a
String
.
Source§impl OfficialAccount
impl OfficialAccount
Source§impl OfficialAccount
impl OfficialAccount
Sourcepub async fn request_validate(&self, query: WechatQuery) -> bool
pub async fn request_validate(&self, query: WechatQuery) -> bool
Source§impl OfficialAccount
impl OfficialAccount
Sourcepub async fn token(&self) -> Result<String, Box<dyn Error>>
pub async fn token(&self) -> Result<String, Box<dyn Error>>
Retrieves the access token for the official account
This function attempts to fetch the access token from the Redis database. If not found, it requests a new token from the WeChat API using the application ID and secret, then stores the token in Redis for future use.
§Returns
- A
Result
containing the access token as aString
on success, or a boxed error on failure.
§Errors
- Returns an error if the Redis operation fails, if the HTTP request fails,
or if the response cannot be deserialized into a
TokenResponse
.