添加操作类型及部分修改

This commit is contained in:
junleea 2025-04-26 11:24:46 +08:00
parent 315ca73851
commit fc30a92ca4
1 changed files with 8 additions and 6 deletions

View File

@ -115,17 +115,18 @@ type QQCallbackReq struct {
func GetQQAuthUrl(c *gin.Context) { func GetQQAuthUrl(c *gin.Context) {
//query //query
uuid := c.Query("uuid") uuid := c.Query("uuid")
hType := c.Query("type")
var resp proto.GenerateResp var resp proto.GenerateResp
if uuid == "" { if uuid == "" || hType == "" {
resp.Code = proto.ParameterError resp.Code = proto.ParameterError
resp.Message = "uuid is empty" resp.Message = "uuid or hType is empty"
c.JSON(http.StatusOK, resp) c.JSON(http.StatusOK, resp)
return return
} }
params := url.Values{} params := url.Values{}
params.Add("response_type", "code") params.Add("response_type", "code")
params.Add("client_id", worker.AppId) params.Add("client_id", worker.AppId)
params.Add("state", "saw_"+uuid) params.Add("state", "saw_"+hType+"_"+uuid)
str := fmt.Sprintf("%s&redirect_uri=%s", params.Encode(), worker.RedirectURI) str := fmt.Sprintf("%s&redirect_uri=%s", params.Encode(), worker.RedirectURI)
loginURL := fmt.Sprintf("%s?%s", "https://graph.qq.com/oauth2.0/authorize", str) loginURL := fmt.Sprintf("%s?%s", "https://graph.qq.com/oauth2.0/authorize", str)
//c.Redirect(http.StatusFound, loginURL) //重定向到QQ登录页面 //c.Redirect(http.StatusFound, loginURL) //重定向到QQ登录页面
@ -644,17 +645,18 @@ func handleGithubCallback(c *gin.Context) {
func ToGithubAuthPage(c *gin.Context) { func ToGithubAuthPage(c *gin.Context) {
uuid := c.Query("uuid") uuid := c.Query("uuid")
hType := c.Query("type") //操作类型add,login
var resp proto.GenerateResp var resp proto.GenerateResp
if uuid == "" { if uuid == "" || hType == "" {
resp.Code = proto.ParameterError resp.Code = proto.ParameterError
resp.Message = "uuid is empty" resp.Message = "uuid or type is empty"
c.JSON(http.StatusOK, resp) c.JSON(http.StatusOK, resp)
return return
} }
params := url.Values{} params := url.Values{}
params.Add("client_id", proto.Config.GITHUB_CLIENT_ID) params.Add("client_id", proto.Config.GITHUB_CLIENT_ID)
params.Add("login", uuid) params.Add("login", uuid)
params.Add("state", "saw_"+uuid) params.Add("state", "saw_"+hType+"_"+uuid)
baseUri := "https://github.com/login/oauth/authorize" baseUri := "https://github.com/login/oauth/authorize"
redirectUrl := fmt.Sprintf("%s?%s", baseUri, params.Encode()) redirectUrl := fmt.Sprintf("%s?%s", baseUri, params.Encode())
redirectUrl = fmt.Sprintf("%s&redirect_uri=%s", redirectUrl, "https://sv.ljsea.top") redirectUrl = fmt.Sprintf("%s&redirect_uri=%s", redirectUrl, "https://sv.ljsea.top")