修改stackoverflow数据获取

This commit is contained in:
junleea 2025-05-06 12:53:34 +08:00
parent af6c4822e5
commit d1ab6e8c17
3 changed files with 23 additions and 21 deletions

View File

@ -4,6 +4,7 @@
<inspection_tool class="GoDfaErrorMayBeNotNil" enabled="true" level="WARNING" enabled_by_default="true"> <inspection_tool class="GoDfaErrorMayBeNotNil" enabled="true" level="WARNING" enabled_by_default="true">
<functions> <functions>
<function importPath="net/http" name="NewRequest" /> <function importPath="net/http" name="NewRequest" />
<function importPath="StuAcaWorksAI/worker" name="GetStackoverflowAccessTokenByCode" />
</functions> </functions>
</inspection_tool> </inspection_tool>
</profile> </profile>

View File

@ -548,32 +548,33 @@ func DoFaceBookCallBack(state *proto.ThirdPartyLoginState, code string) {
} }
func DoStackoverflowCallBack(state *proto.ThirdPartyLoginState, code string) { func DoStackoverflowCallBack(state *proto.ThirdPartyLoginState, code string) {
var thirdPartyLoginStatus proto.ThirdPartyLoginStatus
var userInfo proto.StackoverflowUserInfo
thirdPartyLoginStatus.Type = state.Platform
//根据code获取Access Token //根据code获取Access Token
tokenResp, err := worker.GetStackoverflowAccessTokenByCode(code, "https://pm.ljsea.top/tool/third_party_callback", worker.StackOverflowClientID, worker.StackOverflowClientSecret) tokenResp, err := worker.GetStackoverflowAccessTokenByCode(code, "https://pm.ljsea.top/tool/third_party_callback", worker.StackOverflowClientID, worker.StackOverflowClientSecret)
if tokenResp.AccessToken == "" { if tokenResp.AccessToken == "" {
log.Println("get Stackoverflow access token is empty") log.Println("get Stackoverflow access token is empty")
return thirdPartyLoginStatus.Status = proto.ParameterError
} } else {
log.Println("get Stackoverflow access token:", tokenResp) log.Println("get Stackoverflow access token:", tokenResp)
//获取用户信息 //获取用户信息
userInfoResp, err := worker.GetStackoverflowUserInfo(tokenResp.AccessToken) userInfoResp, err2 := worker.GetStackoverflowUserInfo(tokenResp.AccessToken)
if err != nil { if err2 != nil {
log.Println("get Stackoverflow user info error:", err) log.Println("get Stackoverflow user info error:", err)
return thirdPartyLoginStatus.Status = proto.ParameterError
} } else {
log.Println("get Stackoverflow user info:", userInfoResp) log.Println("get Stackoverflow user info:", userInfoResp)
var userInfo proto.StackoverflowUserInfo
if userInfoResp.Items != nil && len(userInfoResp.Items) > 0 { if userInfoResp.Items != nil && len(userInfoResp.Items) > 0 {
userInfo = userInfoResp.Items[0] userInfo = userInfoResp.Items[0]
} else {
log.Println("get Stackoverflow user info is empty")
return
}
var thirdPartyLoginStatus proto.ThirdPartyLoginStatus
thirdPartyLoginStatus.Type = state.Platform
thirdPartyUserInfo := proto.ThirdPartyUserInfo{UserID: strconv.Itoa(userInfo.UserID), Name: userInfo.DisplayName, Avatar: userInfo.ProfileImage, Email: ""} thirdPartyUserInfo := proto.ThirdPartyUserInfo{UserID: strconv.Itoa(userInfo.UserID), Name: userInfo.DisplayName, Avatar: userInfo.ProfileImage, Email: ""}
HandleThirdPartyLoginStatusV2(state, &thirdPartyLoginStatus, &thirdPartyUserInfo) HandleThirdPartyLoginStatusV2(state, &thirdPartyLoginStatus, &thirdPartyUserInfo)
} else {
log.Println("get Stackoverflow user info is empty")
thirdPartyLoginStatus.Status = proto.ParameterError
}
}
}
//更新redis中的第三方登录状态 //更新redis中的第三方登录状态
thirdPartyLoginStatusStr, _ := json.Marshal(thirdPartyLoginStatus) thirdPartyLoginStatusStr, _ := json.Marshal(thirdPartyLoginStatus)
log.Println("do handle Stackoverflow callback success, third party login status:", string(thirdPartyLoginStatusStr)) log.Println("do handle Stackoverflow callback success, third party login status:", string(thirdPartyLoginStatusStr))

View File

@ -377,7 +377,7 @@ func GetFaceBookUserInfo(accessToken string) (proto.FaceBookUserInfoResp, error)
const ( const (
StackOverflowClientID = "32093" StackOverflowClientID = "32093"
StackOverflowClientSecret = "cgHOI0emSLU7VB7jpAY9NQ((" StackOverflowClientSecret = "SOvAmbfCBeei1ikqH4IwNA(("
StackOverflowKey = "rl_s6vbPNPhbFbMcyWp7YbaTeg18" StackOverflowKey = "rl_s6vbPNPhbFbMcyWp7YbaTeg18"
) )