Skip to content

Commit

Permalink
fix: 修复QQ登录的BUG (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lansongxx authored Apr 4, 2024
1 parent 7dd31f3 commit 545c7dc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@

## 2024-04-04

### 🐛 Bug Fixes | Bug 修复

* 修复QQ登录的BUG

## 2024-04-01

### ✨ Features | 新功能
Expand Down
14 changes: 8 additions & 6 deletions biz/infrastructure/utils/oauth/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
)

type Token struct {
AccessToken string `json:"access_token"`
TokenType string `json:"token_type"` // 这个字段没用到
Scope string `json:"scope"` // 这个字段也没用到
AccessToken string `json:"Access_Token"`
//TokenType string `json:"token_type"` // 这个字段没用到
//Scope string `json:"scope"` // 这个字段也没用到
}

type GiteeInfo struct {
Expand Down Expand Up @@ -53,11 +53,13 @@ func QQLogin(conf config.OauthConf, code string) (*QQInfo, error) {
if res, err = httpClient.Do(req); err != nil {
return nil, err
}

fmt.Println(res.Body)
if err = json.NewDecoder(res.Body).Decode(&token); err != nil {
return nil, err
}

url = fmt.Sprintf("https://graph.qq.com/oauth2.0/me?access_token=%s", token.AccessToken)
url = fmt.Sprintf("https://graph.qq.com/oauth2.0/me?access_token=%s&fmt=json", token.AccessToken)
if req, err = http.NewRequest(http.MethodGet, url, nil); err != nil {
return nil, err
}
Expand All @@ -73,7 +75,7 @@ func QQLogin(conf config.OauthConf, code string) (*QQInfo, error) {
return nil, err
}

url = fmt.Sprintf("https://graph.qq.com/user/get_user_info?access_token=%s&oauth_consumer_key=%s&openid=%s", token.AccessToken, conf.ClientId, userInfo.OpenId)
url = fmt.Sprintf("https://graph.qq.com/user/get_user_info?access_token=%s&oauth_consumer_key=%s&openid=%s&fmt=json", token.AccessToken, conf.ClientId, userInfo.OpenId)
if req, err = http.NewRequest(http.MethodGet, url, nil); err != nil {
return nil, err
}
Expand Down Expand Up @@ -137,7 +139,7 @@ func getTokenUrl(conf config.OauthConf, authType sts.AuthType, code string) stri
case sts.AuthType_gitee:
return fmt.Sprintf("https://gitee.com/oauth/token?grant_type=authorization_code&code=%s&client_id=%s&redirect_uri=%s&client_secret=%s", code, conf.ClientId, conf.Redirect, conf.Secret)
case sts.AuthType_qq:
return fmt.Sprintf("https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&client_id=%s&client_secret=%s&code=%s&redirect_uri=%s", conf.ClientId, conf.Secret, code, conf.Redirect)
return fmt.Sprintf("https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&client_id=%s&client_secret=%s&code=%s&redirect_uri=%s&fmt=json", conf.ClientId, conf.Secret, code, conf.Redirect)
default:
return ""
}
Expand Down

0 comments on commit 545c7dc

Please sign in to comment.