feat: 添加短信验证码发送记录功能
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user