From d02cceb775840e443fdd0934dd830b3b076261ed Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Sat, 20 Sep 2025 14:20:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9cid=E5=9B=9E=E8=B0=83?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- handler/cid.go | 31 +++++++++++++++++++++---------- proto/req.go | 5 +++++ 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/handler/cid.go b/handler/cid.go index 4ca9df6..3007544 100644 --- a/handler/cid.go +++ b/handler/cid.go @@ -206,32 +206,43 @@ func CIDCallback(c *gin.Context) { // 获取用户ID token := c.Query("token") cid_id := c.Query("id") - //fmt.Println("token:", token, "cid_id:", cid_id) //将cid转换为int cid, _ := strconv.Atoi(cid_id) - - if token == "" || cid == 0 { - c.JSON(200, gin.H{"error": "parameter error", "code": proto.ParameterError, "message": "failed"}) + var req proto.CIDCallBackReq + var resp proto.GeneralResp + if err := c.ShouldBindQuery(&req); err != nil { + resp.Code, resp.Message = proto.ParameterError, err.Error() + c.JSON(http.StatusOK, resp) return } + if req.ID == 0 || req.Token == "" { + resp.Code, resp.Message = proto.ParameterError, "token or id is empty" + c.JSON(http.StatusOK, resp) + return + } + res := dao.FindCIDByIDAndToken(cid, token) if res.ID == 0 { - c.JSON(200, gin.H{"error": "CID not found by id and token", "code": proto.OperationFailed, "message": "failed"}) + resp.Code, resp.Message = proto.ParameterError, "CID not found by id and token:"+req.Token+", id:"+strconv.Itoa(int(res.ID)) + c.JSON(http.StatusOK, resp) return } //user := dao.FindUserByUserID(res.Auth_id) user := service.GetUserByIDFromUserCenter(res.Auth_id) if user.Run == false { - c.JSON(200, gin.H{"error": "no run Permissions", "code": proto.NoRunPermissions, "message": "the user has no run Permissions"}) + resp.Code, resp.Message = proto.NoRunPermissions, "the user has no run Permissions" + c.JSON(http.StatusOK, resp) return } if res.ID != 0 { - user_info := dao.FindUserByID(res.Auth_id) - go RunShellCID(user_info[0].Name, res.Url, res.Script, int(res.ID), res.Auth_id) - c.JSON(200, gin.H{"code": proto.SuccessCode, "message": "success", "data": "success"}) + go RunShellCID(res.Name, res.Url, res.Script, int(res.ID), res.Auth_id) + resp.Code, resp.Message, resp.Data = proto.SuccessCode, "success", res.Name + c.JSON(http.StatusOK, resp) + return } else { - c.JSON(200, gin.H{"error": "CID not found by id and token", "code": proto.OperationFailed, "message": "failed"}) + resp.Code, resp.Message = proto.OperationFailed, "CID not found by id and token" + c.JSON(http.StatusOK, resp) return } } diff --git a/proto/req.go b/proto/req.go index 699e44e..2f90440 100644 --- a/proto/req.go +++ b/proto/req.go @@ -5,3 +5,8 @@ type GeneralResp struct { Message string `json:"message"` Data any `json:"data"` } + +type CIDCallBackReq struct { + Token string `json:"token" form:"token"` + ID int `json:"id" form:"id"` +}