修改cid回调接口
This commit is contained in:
parent
f334668e4b
commit
d02cceb775
|
|
@ -206,32 +206,43 @@ func CIDCallback(c *gin.Context) {
|
||||||
// 获取用户ID
|
// 获取用户ID
|
||||||
token := c.Query("token")
|
token := c.Query("token")
|
||||||
cid_id := c.Query("id")
|
cid_id := c.Query("id")
|
||||||
//fmt.Println("token:", token, "cid_id:", cid_id)
|
|
||||||
//将cid转换为int
|
//将cid转换为int
|
||||||
cid, _ := strconv.Atoi(cid_id)
|
cid, _ := strconv.Atoi(cid_id)
|
||||||
|
var req proto.CIDCallBackReq
|
||||||
if token == "" || cid == 0 {
|
var resp proto.GeneralResp
|
||||||
c.JSON(200, gin.H{"error": "parameter error", "code": proto.ParameterError, "message": "failed"})
|
if err := c.ShouldBindQuery(&req); err != nil {
|
||||||
|
resp.Code, resp.Message = proto.ParameterError, err.Error()
|
||||||
|
c.JSON(http.StatusOK, resp)
|
||||||
return
|
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)
|
res := dao.FindCIDByIDAndToken(cid, token)
|
||||||
if res.ID == 0 {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//user := dao.FindUserByUserID(res.Auth_id)
|
//user := dao.FindUserByUserID(res.Auth_id)
|
||||||
user := service.GetUserByIDFromUserCenter(res.Auth_id)
|
user := service.GetUserByIDFromUserCenter(res.Auth_id)
|
||||||
if user.Run == false {
|
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
|
return
|
||||||
}
|
}
|
||||||
if res.ID != 0 {
|
if res.ID != 0 {
|
||||||
user_info := dao.FindUserByID(res.Auth_id)
|
go RunShellCID(res.Name, res.Url, res.Script, int(res.ID), res.Auth_id)
|
||||||
go RunShellCID(user_info[0].Name, res.Url, res.Script, int(res.ID), res.Auth_id)
|
resp.Code, resp.Message, resp.Data = proto.SuccessCode, "success", res.Name
|
||||||
c.JSON(200, gin.H{"code": proto.SuccessCode, "message": "success", "data": "success"})
|
c.JSON(http.StatusOK, resp)
|
||||||
|
return
|
||||||
} else {
|
} 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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,3 +5,8 @@ type GeneralResp struct {
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
Data any `json:"data"`
|
Data any `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CIDCallBackReq struct {
|
||||||
|
Token string `json:"token" form:"token"`
|
||||||
|
ID int `json:"id" form:"id"`
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue