From 5cc9135d0e777c2ebfa2c8f0776b8332b0ed3ac2 Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Sat, 26 Apr 2025 11:03:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=8E=B7=E5=8F=96=E7=99=BB?= =?UTF-8?q?=E5=BD=95url=EF=BC=8C=E4=BF=AE=E6=94=B9=E6=8B=A6=E6=88=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- handler/tool.go | 24 ++++++++++++++++++------ proto/conf.go | 2 +- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/handler/tool.go b/handler/tool.go index 57ea660..515a06e 100644 --- a/handler/tool.go +++ b/handler/tool.go @@ -56,7 +56,7 @@ func SetUpToolGroup(router *gin.Engine) { //服务器、设备状态接口 toolGroup.POST("/monitor", SetDeviceStatusV2) toolGroup.POST("/qq_callback", handleQQCallback) - toolGroup.POST("/qq_auth", GetAuthCode) + toolGroup.POST("/qq_auth", GetQQAuthUrl) toolGroup.POST("/github_auth", ToGithubAuthPage) toolGroup.POST("/github_callback", handleGithubCallback) //发送邮件 @@ -112,11 +112,11 @@ type QQCallbackReq struct { State string `json:"state" form:"state"` } -func GetAuthCode(c *gin.Context) { +func GetQQAuthUrl(c *gin.Context) { //query uuid := c.Query("uuid") + var resp proto.GenerateResp if uuid == "" { - var resp proto.GenerateResp resp.Code = proto.ParameterError resp.Message = "uuid is empty" c.JSON(http.StatusOK, resp) @@ -128,7 +128,11 @@ func GetAuthCode(c *gin.Context) { params.Add("state", "saw_"+uuid) str := fmt.Sprintf("%s&redirect_uri=%s", params.Encode(), worker.RedirectURI) 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登录页面 + resp.Message = "success" + resp.Code = proto.SuccessCode + resp.Data = loginURL + c.JSON(http.StatusOK, resp) } func handleQQCallback(c *gin.Context) { @@ -640,8 +644,11 @@ func handleGithubCallback(c *gin.Context) { func ToGithubAuthPage(c *gin.Context) { uuid := c.Query("uuid") + var resp proto.GenerateResp if uuid == "" { - c.JSON(http.StatusOK, gin.H{"code": proto.ParameterError, "message": "uuid is empty"}) + resp.Code = proto.ParameterError + resp.Message = "uuid is empty" + c.JSON(http.StatusOK, resp) return } params := url.Values{} @@ -651,5 +658,10 @@ func ToGithubAuthPage(c *gin.Context) { baseUri := "https://github.com/login/oauth/authorize" redirectUrl := fmt.Sprintf("%s?%s", baseUri, params.Encode()) redirectUrl = fmt.Sprintf("%s&redirect_uri=%s", redirectUrl, "https://sv.ljsea.top") - c.Redirect(http.StatusFound, redirectUrl) + //c.Redirect(http.StatusFound, redirectUrl) + resp.Message = "success" + resp.Code = proto.SuccessCode + resp.Data = redirectUrl + c.JSON(http.StatusOK, resp) + } diff --git a/proto/conf.go b/proto/conf.go index 2688bc7..6bb07a8 100644 --- a/proto/conf.go +++ b/proto/conf.go @@ -9,7 +9,7 @@ import ( var Config ConfigStruct var SigningKey = []byte{} -var Url_map = map[string]bool{"/login": true, "/register": true, "/uuid": true, "/gqr": true, "/cid/callback": true, "/tool/monitor": true, "/user/sync": true, "/tool/file/": true, "/user/reset": true, "/tool/qq_auth": true, "/tool/qq_callback": true} // 不需要token验证的url +var Url_map = map[string]bool{"/login": true, "/register": true, "/uuid": true, "/gqr": true, "/cid/callback": true, "/tool/monitor": true, "/user/sync": true, "/tool/file/": true, "/user/reset": true, "/tool/qq_auth": true, "/tool/qq_callback": true, "/tool/github_auth": true, "/tool/github_callback": true, "/user/oAuth": true, "/user/oAuth_uuid": true} // 不需要token验证的url var Per_menu_map = map[string]int{"/video/": 1, "/device/": 2, "/cid/": 3} var File_Type = map[string]int{"im": 1, "avatar": 2, "file": 3, "config": 4} // 文件类型 const (