feat: 添加短信验证码发送记录功能

This commit is contained in:
2025-12-23 23:47:39 +08:00
parent a125f15f58
commit 5709255e39
19 changed files with 668 additions and 14 deletions

View File

@@ -392,14 +392,25 @@ func (m *users) SendPhoneCode(ctx context.Context, phone string) error {
}
// 生成/覆盖验证码:同一手机号再次发送时以最新验证码为准
expiresAt := now.Add(5 * time.Minute)
m.codeByPhone[phone] = phoneCodeEntry{
code: code,
expiresAt: now.Add(5 * time.Minute),
expiresAt: expiresAt,
}
m.lastSentAtByPhone[phone] = now
// log phone and code
log.Infof("SendPhoneCode to %s: code=%s", phone, code)
if _db != nil {
// 记录短信验证码发送日志(用于后台审计与排查)。
_ = _db.WithContext(ctx).Create(&models.SmsCodeSend{
Phone: phone,
Code: code,
SentAt: now,
ExpiresAt: expiresAt,
}).Error
}
return nil
}