feat: 接入短信服务,修复 SMS 客户端 API 路径
Some checks failed
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Has been cancelled
Some checks failed
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Has been cancelled
- cmd/api/main.go: 新增 initSMS() 初始化短信客户端并注入 verificationService - pkg/sms/client.go: 修复 API 路径缺少 /sms 前缀(/api/... → /sms/api/...) - docker-compose.prod.yml: 添加线上短信服务环境变量
This commit is contained in:
@@ -27,6 +27,7 @@ import (
|
||||
"github.com/break/junhong_cmp_fiber/pkg/database"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/logger"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/queue"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/sms"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/storage"
|
||||
)
|
||||
|
||||
@@ -306,11 +307,42 @@ func initAuthComponents(cfg *config.Config, redisClient *redis.Client, appLogger
|
||||
refreshTTL := time.Duration(cfg.JWT.RefreshTokenTTL) * time.Second
|
||||
tokenManager := auth.NewTokenManager(redisClient, accessTTL, refreshTTL)
|
||||
|
||||
verificationSvc := verification.NewService(redisClient, nil, appLogger)
|
||||
smsClient := initSMS(cfg, appLogger)
|
||||
verificationSvc := verification.NewService(redisClient, smsClient, appLogger)
|
||||
|
||||
return jwtManager, tokenManager, verificationSvc
|
||||
}
|
||||
|
||||
func initSMS(cfg *config.Config, appLogger *zap.Logger) *sms.Client {
|
||||
if cfg.SMS.GatewayURL == "" {
|
||||
appLogger.Info("短信服务未配置,跳过初始化")
|
||||
return nil
|
||||
}
|
||||
|
||||
timeout := cfg.SMS.Timeout
|
||||
if timeout == 0 {
|
||||
timeout = 10 * time.Second
|
||||
}
|
||||
|
||||
httpClient := sms.NewStandardHTTPClient(0)
|
||||
client := sms.NewClient(
|
||||
cfg.SMS.GatewayURL,
|
||||
cfg.SMS.Username,
|
||||
cfg.SMS.Password,
|
||||
cfg.SMS.Signature,
|
||||
timeout,
|
||||
appLogger,
|
||||
httpClient,
|
||||
)
|
||||
|
||||
appLogger.Info("短信服务已初始化",
|
||||
zap.String("gateway_url", cfg.SMS.GatewayURL),
|
||||
zap.String("signature", cfg.SMS.Signature),
|
||||
)
|
||||
|
||||
return client
|
||||
}
|
||||
|
||||
func initStorage(cfg *config.Config, appLogger *zap.Logger) *storage.Service {
|
||||
if cfg.Storage.Provider == "" || cfg.Storage.S3.Endpoint == "" {
|
||||
appLogger.Info("对象存储未配置,跳过初始化")
|
||||
|
||||
Reference in New Issue
Block a user