feat(server/reward): TG 绑定 token 签发/消费 + GET /v1/tasks/telegram/start

This commit is contained in:
wangjia
2026-07-13 07:49:31 +08:00
parent d23f7bca8f
commit e23cd5e1bd
4 changed files with 130 additions and 0 deletions
+13
View File
@@ -5,7 +5,10 @@ import (
"crypto/rand"
"database/sql"
"log/slog"
"sync"
"time"
"github.com/redis/go-redis/v9"
)
type Granter interface {
@@ -20,6 +23,11 @@ type Service struct {
g Granter
cfg Config
now func() time.Time
rdb *redis.Client
tg tgConfig
memMu sync.Mutex
memTok map[string]int64
}
func NewService(db *sql.DB, st *Store, g Granter, cfg Config, now func() time.Time) *Service {
@@ -134,3 +142,8 @@ func (s *Service) OnFirstPaidTx(ctx context.Context, tx *sql.Tx, inviteeID int64
}
return s.st.MarkPaidRewardedTx(ctx, tx, inviteeID, now)
}
// TelegramDeepLink 拼 t.me 深链,携带绑定 token。
func (s *Service) TelegramDeepLink(tok string) string {
return "https://t.me/" + s.tg.botUser + "?start=" + tok
}