49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
package sms
|
|
|
|
import (
|
|
"context"
|
|
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
// MockSMSService 模拟短信服务(用于开发和测试)
|
|
type MockSMSService struct {
|
|
logger *zap.Logger
|
|
}
|
|
|
|
// NewMockSMSService 创建模拟短信服务
|
|
func NewMockSMSService(logger *zap.Logger) *MockSMSService {
|
|
return &MockSMSService{
|
|
logger: logger,
|
|
}
|
|
}
|
|
|
|
// SendVerificationCode 模拟发送验证码
|
|
func (s *MockSMSService) SendVerificationCode(ctx context.Context, phone string, code string) error {
|
|
s.logger.Info("Mock SMS sent",
|
|
zap.String("phone", phone),
|
|
zap.String("code", code))
|
|
return nil
|
|
}
|
|
|
|
// SendBalanceAlert 模拟余额预警
|
|
func (s *MockSMSService) SendBalanceAlert(ctx context.Context, phone string, balance float64, threshold float64, alertType string, enterpriseName ...string) error {
|
|
s.logger.Info("Mock balance alert SMS",
|
|
zap.String("phone", phone),
|
|
zap.Float64("balance", balance),
|
|
zap.String("alert_type", alertType))
|
|
return nil
|
|
}
|
|
|
|
// GenerateCode 生成验证码
|
|
func (s *MockSMSService) GenerateCode(length int) string {
|
|
if length <= 0 {
|
|
length = 6
|
|
}
|
|
result := ""
|
|
for i := 0; i < length; i++ {
|
|
result += "1"
|
|
}
|
|
return result
|
|
}
|