Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

重定向成功没有跳转页面 #30

Open
pkg2001 opened this issue Apr 10, 2024 · 0 comments
Open

重定向成功没有跳转页面 #30

pkg2001 opened this issue Apr 10, 2024 · 0 comments

Comments

@pkg2001
Copy link

pkg2001 commented Apr 10, 2024

// 1. Get Authorization Code
func GetAuthCode(w http.ResponseWriter, r *http.Request) {

params := url.Values{}
params.Add("response_type", "code")
params.Add("client_id", AppId)
params.Add("state", "test")
str := fmt.Sprintf("%s&redirect_uri=%s", params.Encode(), redirectURI)
loginURL := fmt.Sprintf("%s?%s", "https://graph.qq.com/oauth2.0/authorize", str)
http.Redirect(w, r, loginURL, http.StatusOK)
fmt.Println("Login successful")

}

// 2. Get Access Token
func GetToken(w http.ResponseWriter, r *http.Request) {
fmt.Println("Getting")
code := r.FormValue("code")
params := url.Values{}
params.Add("grant_type", "authorization_code")
params.Add("client_id", AppId)
params.Add("client_secret", AppKey)
params.Add("code", code)
str := fmt.Sprintf("%s&redirect_uri=%s", params.Encode(), redirectURI)
loginURL := fmt.Sprintf("%s?%s", "https://graph.qq.com/oauth2.0/token", str)

response, err := http.Get(loginURL)
if err != nil {
	w.Write([]byte(err.Error()))
}
defer response.Body.Close()

bs, _ := ioutil.ReadAll(response.Body)
body := string(bs)

resultMap := convertToMap(body)

info := &PrivateInfo{}
info.AccessToken = resultMap["access_token"]
info.RefreshToken = resultMap["refresh_token"]
info.ExpiresIn = resultMap["expires_in"]

GetOpenId(info, w)

}gin框架接入的时候为什么没有扫码的页面

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant