fix: issues
This commit is contained in:
@@ -80,13 +80,22 @@ func (we *Client) GetAccessToken() (*AccessTokenResponse, error) {
|
||||
"grant_type": "client_credential",
|
||||
}
|
||||
|
||||
var data AccessTokenResponse
|
||||
_, err := we.client.R().SetSuccessResult(&data).SetQueryParams(params).Get("/cgi-bin/token")
|
||||
var data ErrorResponse
|
||||
resp, err := we.client.R().SetSuccessResult(&data).SetQueryParams(params).Get("/cgi-bin/token")
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "call /cgi-bin/token failed")
|
||||
}
|
||||
|
||||
return &data, nil
|
||||
if data.ErrCode != 0 {
|
||||
return nil, data.Error()
|
||||
}
|
||||
|
||||
var token AccessTokenResponse
|
||||
if err := resp.Unmarshal(&token); err != nil {
|
||||
return nil, errors.Wrap(err, "parse response failed")
|
||||
}
|
||||
|
||||
return &token, nil
|
||||
}
|
||||
|
||||
// ScopeAuthorizeURL
|
||||
@@ -115,13 +124,14 @@ func (we *Client) ScopeAuthorizeURL(opts ...ScopeAuthorizeURLOptions) (*url.URL,
|
||||
}
|
||||
|
||||
type AuthorizeAccessToken struct {
|
||||
AccessToken string `json:"access_token"`
|
||||
ExpiresIn int64 `json:"expires_in"`
|
||||
IsSnapshotuser int64 `json:"is_snapshotuser"`
|
||||
Openid string `json:"openid"`
|
||||
RefreshToken string `json:"refresh_token"`
|
||||
Scope string `json:"scope"`
|
||||
Unionid string `json:"unionid"`
|
||||
ErrorResponse
|
||||
AccessToken string `json:"access_token,omitempty"`
|
||||
ExpiresIn int64 `json:"expires_in,omitempty"`
|
||||
IsSnapshotuser int64 `json:"is_snapshotuser,omitempty"`
|
||||
Openid string `json:"openid,omitempty"`
|
||||
RefreshToken string `json:"refresh_token,omitempty"`
|
||||
Scope string `json:"scope,omitempty"`
|
||||
Unionid string `json:"unionid,omitempty"`
|
||||
}
|
||||
|
||||
func (we *Client) AuthorizeCode2Token(code string) (*AuthorizeAccessToken, error) {
|
||||
@@ -136,6 +146,10 @@ func (we *Client) AuthorizeCode2Token(code string) (*AuthorizeAccessToken, error
|
||||
return nil, errors.Wrap(err, "call /sns/oauth2/access_token failed")
|
||||
}
|
||||
|
||||
if err := data.Error(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &data, nil
|
||||
}
|
||||
|
||||
@@ -151,19 +165,24 @@ func (we *Client) AuthorizeRefreshAccessToken(accessToken string) (*AuthorizeAcc
|
||||
return nil, errors.Wrap(err, "call /sns/oauth2/refresh_token failed")
|
||||
}
|
||||
|
||||
if err := data.Error(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &data, nil
|
||||
}
|
||||
|
||||
type AuthorizeUserInfo struct {
|
||||
City string `json:"city"`
|
||||
Country string `json:"country"`
|
||||
Headimgurl string `json:"headimgurl"`
|
||||
Nickname string `json:"nickname"`
|
||||
Openid string `json:"openid"`
|
||||
Privilege []string `json:"privilege"`
|
||||
Province string `json:"province"`
|
||||
Sex int64 `json:"sex"`
|
||||
Unionid string `json:"unionid"`
|
||||
ErrorResponse
|
||||
City string `json:"city,omitempty"`
|
||||
Country string `json:"country,omitempty"`
|
||||
Headimgurl string `json:"headimgurl,omitempty"`
|
||||
Nickname string `json:"nickname,omitempty"`
|
||||
Openid string `json:"openid,omitempty"`
|
||||
Privilege []string `json:"privilege,omitempty"`
|
||||
Province string `json:"province,omitempty"`
|
||||
Sex int64 `json:"sex,omitempty"`
|
||||
Unionid string `json:"unionid,omitempty"`
|
||||
}
|
||||
|
||||
func (we *Client) AuthorizeUserInfo(accessToken, openID string) (*AuthorizeUserInfo, error) {
|
||||
@@ -178,5 +197,9 @@ func (we *Client) AuthorizeUserInfo(accessToken, openID string) (*AuthorizeUserI
|
||||
return nil, errors.Wrap(err, "call /sns/userinfo failed")
|
||||
}
|
||||
|
||||
if err := data.Error(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &data, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user