fix: SMS 验证码使用纯数字,兼容 UniSMS 通用模板
UniSMS 通用模板要求 code 为纯数字,原来用 UUID 截取会包含字母。 新增 GenerateNumericCode 函数,SMS 验证码专用。 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -33,6 +34,14 @@ func GenerateVerificationCode(length int) string {
|
||||
return code[:length]
|
||||
}
|
||||
|
||||
func GenerateNumericCode(length int) string {
|
||||
digits := make([]byte, length)
|
||||
for i := range digits {
|
||||
digits[i] = '0' + byte(rand.Intn(10))
|
||||
}
|
||||
return string(digits)
|
||||
}
|
||||
|
||||
func RegisterVerificationCodeWithKey(key string, code string, purpose string) {
|
||||
verificationMutex.Lock()
|
||||
defer verificationMutex.Unlock()
|
||||
|
||||
@@ -319,7 +319,7 @@ func SendSmsVerification(c *gin.Context) {
|
||||
common.ApiErrorI18n(c, i18n.MsgUserPhoneAlreadyTaken)
|
||||
return
|
||||
}
|
||||
code := common.GenerateVerificationCode(6)
|
||||
code := common.GenerateNumericCode(6)
|
||||
common.RegisterVerificationCodeWithKey(phone, code, common.SmsVerificationPurpose)
|
||||
err := common.SendSMS(phone, code)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user