up add sms

This commit is contained in:
Mrx
2026-02-25 16:38:58 +08:00
parent ed5ebc5648
commit 60a0770917
14 changed files with 321 additions and 23 deletions

View File

@@ -2,11 +2,12 @@ package auth
import (
"context"
"ycc-server/common/xerr"
"ycc-server/pkg/lzkit/crypto"
"fmt"
"math/rand"
"time"
"ycc-server/common/xerr"
"ycc-server/pkg/captcha"
"ycc-server/pkg/lzkit/crypto"
"github.com/pkg/errors"
@@ -35,6 +36,20 @@ func NewSendSmsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendSmsLo
}
func (l *SendSmsLogic) SendSms(req *types.SendSmsReq) error {
// 1. 阿里云滑块验证码校验(防盗刷)
cfg := l.svcCtx.Config.Captcha
if cfg.SceneID != "" {
if err := captcha.Verify(captcha.Config{
AccessKeyID: cfg.AccessKeyID,
AccessKeySecret: cfg.AccessKeySecret,
EndpointURL: cfg.EndpointURL,
SceneID: cfg.SceneID,
}, req.CaptchaVerifyParam); err != nil {
return err
}
}
// 2. 加密手机号
secretKey := l.svcCtx.Config.Encrypt.SecretKey
encryptedMobile, err := crypto.EncryptMobile(req.Mobile, secretKey)
if err != nil {

View File

@@ -0,0 +1,48 @@
package captcha
import (
"context"
"ycc-server/app/main/api/internal/svc"
"ycc-server/app/main/api/internal/types"
"ycc-server/pkg/captcha"
"github.com/zeromicro/go-zero/core/logx"
)
type GetEncryptedSceneIdLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetEncryptedSceneIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetEncryptedSceneIdLogic {
return &GetEncryptedSceneIdLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetEncryptedSceneIdLogic) GetEncryptedSceneId() (*types.GetEncryptedSceneIdResp, error) {
cfg := l.svcCtx.Config.Captcha
// 如果没有配置 ekey返回空使用非加密模式
if cfg.EKey == "" {
l.Logger.Info("[Captcha] 未配置 EKey使用非加密模式")
return &types.GetEncryptedSceneIdResp{
EncryptedSceneId: "",
}, nil
}
// 生成加密场景ID有效期1小时
encrypted, err := captcha.GenerateEncryptedSceneID(cfg.SceneID, cfg.EKey, 3600)
if err != nil {
l.Logger.Errorf("[Captcha] 生成加密场景ID失败: %+v", err)
return nil, err
}
return &types.GetEncryptedSceneIdResp{
EncryptedSceneId: encrypted,
}, nil
}