fadd
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"os"
|
||||
"time"
|
||||
"tydata-server/common/xerr"
|
||||
"tydata-server/pkg/captcha"
|
||||
"tydata-server/pkg/lzkit/crypto"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
@@ -53,6 +54,23 @@ func (l *SendSmsLogic) SendSms(req *types.SendSmsReq) error {
|
||||
return errors.Wrapf(xerr.NewErrMsg("一分钟内不能重复发送验证码"), "短信发送, 手机号1分钟内重复请求发送验证码: %s", encryptedMobile)
|
||||
}
|
||||
|
||||
// 验证码校验
|
||||
if os.Getenv("ENV") != "development" {
|
||||
if req.CaptchaVerifyParam == "" {
|
||||
return errors.Wrapf(xerr.NewErrMsg("图形验证码校验失败"), "短信发送, 验证码参数为空: %s", encryptedMobile)
|
||||
}
|
||||
captchaCfg := l.svcCtx.Config.Captcha
|
||||
err = captcha.Verify(captcha.Config{
|
||||
AccessKeyID: captchaCfg.AccessKeyID,
|
||||
AccessKeySecret: captchaCfg.AccessKeySecret,
|
||||
EndpointURL: captchaCfg.EndpointURL,
|
||||
SceneID: captchaCfg.SceneID,
|
||||
}, req.CaptchaVerifyParam)
|
||||
if err != nil {
|
||||
return errors.Wrapf(xerr.NewErrMsg("图形验证码校验失败"), "短信发送, 验证码校验失败: %s", encryptedMobile)
|
||||
}
|
||||
}
|
||||
|
||||
// 开发环境固定验证码为138888
|
||||
env := os.Getenv("ENV")
|
||||
var code string
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package captcha
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tydata-server/app/main/api/internal/svc"
|
||||
"tydata-server/app/main/api/internal/types"
|
||||
"tydata-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() (resp *types.GetEncryptedSceneIdResp, err error) {
|
||||
captchaCfg := l.svcCtx.Config.Captcha
|
||||
|
||||
encryptedSceneId, err := captcha.GenerateEncryptedSceneID(captchaCfg.SceneID, captchaCfg.EKey, 3600)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.GetEncryptedSceneIdResp{
|
||||
EncryptedSceneId: encryptedSceneId,
|
||||
}, nil
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"tydata-server/app/main/model"
|
||||
"tydata-server/common/ctxdata"
|
||||
"tydata-server/common/xerr"
|
||||
"tydata-server/pkg/captcha"
|
||||
"tydata-server/pkg/lzkit/crypto"
|
||||
"tydata-server/pkg/lzkit/validator"
|
||||
|
||||
@@ -60,8 +61,23 @@ var productProcessors = map[string]func(*QueryServiceLogic, *types.QueryServiceR
|
||||
}
|
||||
|
||||
func (l *QueryServiceLogic) PreprocessLogic(req *types.QueryServiceReq, product string) (*types.QueryServiceResp, error) {
|
||||
if os.Getenv("ENV") != "development" {
|
||||
if req.CaptchaVerifyParam == "" {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("图形验证码校验失败"), "查询服务, 验证码参数为空: %s", req.Product)
|
||||
}
|
||||
captchaCfg := l.svcCtx.Config.Captcha
|
||||
err := captcha.Verify(captcha.Config{
|
||||
AccessKeyID: captchaCfg.AccessKeyID,
|
||||
AccessKeySecret: captchaCfg.AccessKeySecret,
|
||||
EndpointURL: captchaCfg.EndpointURL,
|
||||
SceneID: captchaCfg.SceneID,
|
||||
}, req.CaptchaVerifyParam)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("图形验证码校验失败"), "查询服务, 验证码校验失败: %s", req.Product)
|
||||
}
|
||||
}
|
||||
if processor, exists := productProcessors[product]; exists {
|
||||
return processor(l, req) // 调用对应的处理函数
|
||||
return processor(l, req)
|
||||
}
|
||||
return nil, errors.New("未找到相应的处理程序")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user