add
This commit is contained in:
@@ -17,6 +17,12 @@ VerifyCode:
|
||||
SignName: "海南海宇大数据"
|
||||
TemplateCode: "SMS_302641455"
|
||||
ValidTime: 300
|
||||
Captcha:
|
||||
AccessKeyID: "LTAI5tKGB3TVJbMHSoZN3yr9"
|
||||
AccessKeySecret: "OCQ30GWp4yENMjmfOAaagksE18bp65"
|
||||
EndpointURL: "captcha.cn-shanghai.aliyuncs.com"
|
||||
SceneID: "wynt39to"
|
||||
EKey: ""
|
||||
Encrypt:
|
||||
SecretKey: "ff83609b2b24fc73196aac3d3dfb874f"
|
||||
WestConfig:
|
||||
|
||||
@@ -19,6 +19,12 @@ VerifyCode:
|
||||
SignName: "海南海宇大数据"
|
||||
TemplateCode: "SMS_302641455"
|
||||
ValidTime: 300
|
||||
Captcha:
|
||||
AccessKeyID: "LTAI5tKGB3TVJbMHSoZN3yr9"
|
||||
AccessKeySecret: "OCQ30GWp4yENMjmfOAaagksE18bp65"
|
||||
EndpointURL: "captcha.cn-shanghai.aliyuncs.com"
|
||||
SceneID: "wynt39to"
|
||||
EKey: ""
|
||||
Encrypt:
|
||||
SecretKey: "ff83609b2b24fc73196aac3d3dfb874f"
|
||||
WestConfig:
|
||||
|
||||
@@ -11,6 +11,7 @@ type Config struct {
|
||||
CacheRedis cache.CacheConf
|
||||
JwtAuth JwtAuth // JWT 鉴权相关配置
|
||||
VerifyCode VerifyCode
|
||||
Captcha CaptchaConfig
|
||||
Encrypt Encrypt
|
||||
Alipay AlipayConfig
|
||||
Wxpay WxpayConfig
|
||||
@@ -42,6 +43,13 @@ type VerifyCode struct {
|
||||
TemplateCode string
|
||||
ValidTime int
|
||||
}
|
||||
type CaptchaConfig struct {
|
||||
AccessKeyID string
|
||||
AccessKeySecret string
|
||||
EndpointURL string
|
||||
SceneID string
|
||||
EKey string
|
||||
}
|
||||
type Encrypt struct {
|
||||
SecretKey string
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package captcha
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"tyass-server/app/main/api/internal/logic/captcha"
|
||||
"tyass-server/app/main/api/internal/svc"
|
||||
"tyass-server/common/result"
|
||||
)
|
||||
|
||||
func GetEncryptedSceneIdHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := captcha.NewGetEncryptedSceneIdLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetEncryptedSceneId()
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
notification "tyass-server/app/main/api/internal/handler/notification"
|
||||
pay "tyass-server/app/main/api/internal/handler/pay"
|
||||
product "tyass-server/app/main/api/internal/handler/product"
|
||||
captchaHandler "tyass-server/app/main/api/internal/handler/captcha"
|
||||
query "tyass-server/app/main/api/internal/handler/query"
|
||||
user "tyass-server/app/main/api/internal/handler/user"
|
||||
"tyass-server/app/main/api/internal/svc"
|
||||
@@ -914,6 +915,17 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
rest.WithPrefix("/api/v1"),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/captcha/encryptedSceneId",
|
||||
Handler: captchaHandler.GetEncryptedSceneIdHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithPrefix("/api/v1"),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
|
||||
"tyass-server/app/main/api/internal/svc"
|
||||
"tyass-server/app/main/api/internal/types"
|
||||
"tyass-server/pkg/captcha"
|
||||
|
||||
openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
||||
dysmsapi "github.com/alibabacloud-go/dysmsapi-20170525/v3/client"
|
||||
@@ -35,6 +36,17 @@ func NewSendSmsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendSmsLo
|
||||
}
|
||||
|
||||
func (l *SendSmsLogic) SendSms(req *types.SendSmsReq) error {
|
||||
// 图形验证码校验
|
||||
captchaCfg := l.svcCtx.Config.Captcha
|
||||
if err := captcha.Verify(captcha.Config{
|
||||
AccessKeyID: captchaCfg.AccessKeyID,
|
||||
AccessKeySecret: captchaCfg.AccessKeySecret,
|
||||
EndpointURL: captchaCfg.EndpointURL,
|
||||
SceneID: captchaCfg.SceneID,
|
||||
}, req.CaptchaVerifyParam); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
secretKey := l.svcCtx.Config.Encrypt.SecretKey
|
||||
encryptedMobile, err := crypto.EncryptMobile(req.Mobile, secretKey)
|
||||
if err != nil {
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package captcha
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tyass-server/app/main/api/internal/svc"
|
||||
"tyass-server/app/main/api/internal/types"
|
||||
"tyass-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
|
||||
encrypted, err := captcha.GenerateEncryptedSceneID(cfg.SceneID, cfg.EKey, 3600)
|
||||
if err != nil {
|
||||
l.Errorf("generate encrypted scene id error: %+v", err)
|
||||
return nil, err
|
||||
}
|
||||
return &types.GetEncryptedSceneIdResp{
|
||||
EncryptedSceneId: encrypted,
|
||||
}, nil
|
||||
}
|
||||
@@ -2055,6 +2055,10 @@ type QueryServiceResp struct {
|
||||
RefreshAfter int64 `json:"refreshAfter"`
|
||||
}
|
||||
|
||||
type GetEncryptedSceneIdResp struct {
|
||||
EncryptedSceneId string `json:"encryptedSceneId"`
|
||||
}
|
||||
|
||||
type QueryShareDetailReq struct {
|
||||
Id string `path:"id"`
|
||||
}
|
||||
@@ -2220,6 +2224,7 @@ type GetAppVersionResp struct {
|
||||
}
|
||||
|
||||
type SendSmsReq struct {
|
||||
Mobile string `json:"mobile" validate:"required,mobile"`
|
||||
ActionType string `json:"actionType" validate:"required,oneof=login register query agentApply realName bindMobile"`
|
||||
Mobile string `json:"mobile" validate:"required,mobile"`
|
||||
ActionType string `json:"actionType" validate:"required,oneof=login register query agentApply realName bindMobile"`
|
||||
CaptchaVerifyParam string `json:"captchaVerifyParam"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user