feat: update

This commit is contained in:
Rogee
2025-04-30 18:50:11 +08:00
parent 42c1c17c0a
commit 11288471d4
8 changed files with 204 additions and 91 deletions

View File

@@ -11,6 +11,7 @@ func (r *ErrorResponse) Error() error {
type AccessTokenResponse struct {
ErrorResponse
AccessToken string `json:"access_token,omitempty"`
ExpiresIn int `json:"expires_in,omitempty"` // seconds
AccessToken string `json:"access_token,omitempty"`
RefreshToken string `json:"refresh_token,omitempty"`
ExpiresIn int `json:"expires_in,omitempty"` // seconds
}

View File

@@ -89,6 +89,26 @@ func (we *Client) wrapParams(params map[string]string) map[string]string {
return params
}
// RefreshAccessToken
func (we *Client) RefreshAccessToken(refreshToken string) (*AccessTokenResponse, error) {
params := we.wrapParams(map[string]string{
"grant_type": "refresh_token",
"refresh_token": refreshToken,
})
var data AccessTokenResponse
_, err := we.client.R().SetSuccessResult(&data).SetQueryParams(params).Get("/sns/oauth2/refresh_token")
if err != nil {
return nil, errors.Wrap(err, "call /sns/oauth2/refresh_token failed")
}
if data.ErrCode != 0 {
return nil, data.Error()
}
return &data, nil
}
func (we *Client) GetAccessToken() (*AccessTokenResponse, error) {
params := map[string]string{
"grant_type": "client_credential",