Forráskód Böngészése

telegram 一键登录

urbanu 1 hónapja
szülő
commit
a8278fcdb2
4 módosított fájl, 20 hozzáadás és 4 törlés
  1. 2 0
      .gitignore
  2. 6 2
      apis/daytask/auth.go
  3. 9 0
      apis/daytask/home.go
  4. 3 2
      commons/model/entity/dt_config.go

+ 2 - 0
.gitignore

@@ -5,6 +5,8 @@
 *.so
 go.sum
 day_task_server
+create_test_user.go
+insert_test_user.sql
 
 # Folders
 _obj

+ 6 - 2
apis/daytask/auth.go

@@ -557,8 +557,12 @@ func (s *Server) OAuthLogin(c *gin.Context) {
 		nickname = req.Provider + "用户"
 	}
 
-	// 为OAuth用户生成唯一占位手机号(oauth_provider_openid前16位)
-	oauthPhone := fmt.Sprintf("oauth_%s_%s", req.Provider, req.OpenId[:16])
+	// 为OAuth用户生成唯一占位手机号
+	openIdPart := req.OpenId
+	if len(openIdPart) > 16 {
+		openIdPart = openIdPart[:16]
+	}
+	oauthPhone := fmt.Sprintf("oauth_%s_%s", req.Provider, openIdPart)
 
 	user := &entity.DtUser{
 		Uid:        generateUid(),

+ 9 - 0
apis/daytask/home.go

@@ -3,6 +3,7 @@ package daytask
 import (
 	"app/commons/model/entity"
 	"app/commons/services"
+	"fmt"
 	"strings"
 	"github.com/gin-gonic/gin"
 )
@@ -291,6 +292,14 @@ func (s *Server) OAuthConfig(c *gin.Context) {
 		result["zaloAppId"] = zaloConfig.Value
 	}
 
+	// 获取 Telegram Bot Name
+	var telegramConfig entity.DtConfig
+	if err := db.Where("`key` = ?", entity.ConfigKeyTelegramBotName).First(&telegramConfig).Error; err == nil {
+		result["telegramBotName"] = telegramConfig.Value
+	} else {
+		fmt.Printf("Telegram config error: %v, key: %s\n", err, entity.ConfigKeyTelegramBotName)
+	}
+
 	ctx.OK(result)
 }
 

+ 3 - 2
commons/model/entity/dt_config.go

@@ -37,6 +37,7 @@ const (
 	ConfigKeyKefuEmail         = "kefu_email"       // 客服邮箱
 	ConfigKeyKefuTelegram      = "kefu_telegram"    // 客服Telegram
 	ConfigKeyKefuPhone         = "kefu_phone"       // 客服电话
-	ConfigKeyGoogleClientId    = "google_client_id" // Google OAuth Client ID
-	ConfigKeyZaloAppId         = "zalo_app_id"      // Zalo App ID
+	ConfigKeyGoogleClientId    = "google_client_id"    // Google OAuth Client ID
+	ConfigKeyZaloAppId         = "zalo_app_id"        // Zalo App ID
+	ConfigKeyTelegramBotName   = "telegram_bot_name"  // Telegram Bot 用户名
 )