修改cid回调接口

This commit is contained in:
junleea 2025-09-20 14:20:19 +08:00
parent f334668e4b
commit d02cceb775
2 changed files with 26 additions and 10 deletions

View File

@ -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
}
}

View File

@ -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"`
}