package pub import ( "app/commons/services" "github.com/gin-gonic/gin" ) // TelegramBind 绑定Telegram账户到平台用户 // POST /api/v1/pub/telegram/bind func (s *Server) TelegramBind(ctx *gin.Context) { c := s.FromContext(ctx) if c.UserId() <= 0 { c.Fail("请先登录平台账户") return } type request struct { Token string `json:"token" binding:"required"` } req := new(request) if err := c.ShouldBindBodyWithJSON(req); err != nil { c.Fail("参数错误:请提供绑定码") return } bindService := &services.TgBindService{} bind, err := bindService.BindTelegramUser(c.UserId(), req.Token) if err != nil { c.Fail(err.Error()) return } c.Resp(gin.H{ "telegramId": bind.TelegramId, "telegramUsername": bind.TelegramUsername, "bindTime": bind.BindTime, }) } // TelegramBindStatus 查询Telegram绑定状态 // GET /api/v1/pub/telegram/bind/status?telegramId=xxx func (s *Server) TelegramBindStatus(ctx *gin.Context) { c := s.FromContext(ctx) telegramId := c.QueryInt64("telegramId", 0) if telegramId <= 0 { c.Fail("参数错误:telegramId无效") return } bindService := &services.TgBindService{} bound, userId := bindService.IsUserBound(telegramId) c.Resp(gin.H{ "bound": bound, "userId": userId, }) }