feat: support send ali code

This commit is contained in:
2025-12-20 22:38:02 +08:00
parent 2382c72f57
commit 0221a21bc4
6 changed files with 317 additions and 25 deletions

View File

@@ -14,6 +14,7 @@ import (
"quyun/v2/app/requests"
"quyun/v2/database"
"quyun/v2/database/models"
"quyun/v2/providers/ali"
"github.com/pkg/errors"
"github.com/samber/lo"
@@ -28,6 +29,7 @@ type users struct {
lastSentAtByPhone map[string]time.Time `inject:"false"`
codeByPhone map[string]phoneCodeEntry `inject:"false"`
smsNotifyClient *ali.SMSNotifyClient
}
// prepare
@@ -310,8 +312,9 @@ func (m *users) SendPhoneCode(ctx context.Context, phone string) error {
return errors.New("验证码发送过于频繁,请稍后再试")
}
code, err := m.gen4Digits()
code, err := m.smsNotifyClient.SendTo(phone)
if err != nil {
log.WithError(err).Errorf("SendPhoneCode to %s", phone)
return err
}
@@ -324,7 +327,6 @@ func (m *users) SendPhoneCode(ctx context.Context, phone string) error {
// log phone and code
log.Infof("SendPhoneCode to %s: code=%s", phone, code)
// TODO: 这里应调用实际短信服务商发送 code当前仅做内存发码与校验支撑。
return nil
}