From 814e9572a879ea6aa07ce332a9a98a4d1df46737 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E4=BF=8A=E5=AE=8F?= <389838709@qq.com> Date: Tue, 3 Dec 2024 15:48:23 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E7=BB=9F=E4=B8=80=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E8=8F=9C=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/backend/menu_controller.go | 51 +++++++++++++++++++ app/http/routes/admin.go | 3 ++ 2 files changed, 54 insertions(+) create mode 100644 app/http/controllers/backend/menu_controller.go diff --git a/app/http/controllers/backend/menu_controller.go b/app/http/controllers/backend/menu_controller.go new file mode 100644 index 0000000..ce08af2 --- /dev/null +++ b/app/http/controllers/backend/menu_controller.go @@ -0,0 +1,51 @@ +package backend + +import ( + "bytes" + "github.com/gin-gonic/gin" + "io" + "net/http" +) + +const UnifiedLandingPlatform = "https://api.user.1688sup.com" + +func MenusList(c *gin.Context) { + // Target URL + baseURL := UnifiedLandingPlatform + "/v1/menu/myCodes?systemId=" + // Construct the complete target URL, including the path and query parameters + request := c.Query("systemId") + if request == "" { + c.JSON(http.StatusBadRequest, gin.H{"error": "参数解析失败"}) + return + } + baseURL += request + // Rebuild the request + req, err := http.NewRequest(c.Request.Method, baseURL, bytes.NewBufferString(request)) + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{"error": "构建请求失败"}) + return + } + req.Header.Set("Content-Type", "application/json") + req.Header = c.Request.Header + // Initiate the request + client := &http.Client{} + resp, err := client.Do(req) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"error": "请求失败"}) + return + } + defer resp.Body.Close() + // Copy the response content to the original request's response + for k, v := range resp.Header { + for _, value := range v { + c.Header(k, value) + } + } + data, _ := io.ReadAll(resp.Body) + _, err = c.Writer.Write(data) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"error": "写入数据失败"}) + return + } + return +} diff --git a/app/http/routes/admin.go b/app/http/routes/admin.go index 34d1a38..1dafafe 100644 --- a/app/http/routes/admin.go +++ b/app/http/routes/admin.go @@ -23,6 +23,9 @@ func RegisterAdminRoute(router *gin.Engine) { } } + // 获取统一登录菜单 + router.GET("/v1/menu/myCodes", backend.MenusList) + adminApi := router.Group("/admin/api", middlewares.ValidateRequest()) { oauth := adminApi.Group("/oauth")