diff --git a/app/mix/service/logic/veriCode.go b/app/mix/service/logic/veriCode.go index d88179d4..b7ff73bf 100644 --- a/app/mix/service/logic/veriCode.go +++ b/app/mix/service/logic/veriCode.go @@ -3,41 +3,32 @@ package logic import ( "fmt" "math/rand" - "service/api/consts" vericodeproto "service/api/proto/vericode/proto" "service/app/mix/dao" "service/dbstruct" - "service/library/apollo" - "service/library/configcenter" "service/library/idgenerator" "service/library/logger" "service/library/mycrypto" - "service/library/redis" - "service/library/sms" interceptor "service/library/taginterceptor" "time" - dysmsapi "github.com/alibabacloud-go/dysmsapi-20170525/v3/client" "github.com/gin-gonic/gin" - goproto "google.golang.org/protobuf/proto" ) type SendSmsFunction func(mobilephone string, vericode string) error type VeriCode struct { - store *dao.Store - cfg *configcenter.DysmsapiConfig + store *dao.Store + //cfg *configcenter.DysmsapiConfig zthySendSmsFunc SendSmsFunction } -func NewVeriCode(store *dao.Store, cfg *configcenter.DysmsapiConfig, zthySendSmsFunc SendSmsFunction) (a *VeriCode) { +func NewVeriCode(store *dao.Store, zthySendSmsFunc SendSmsFunction) (a *VeriCode) { a = &VeriCode{ - store: store, - cfg: cfg, + store: store, + //cfg: cfg, zthySendSmsFunc: zthySendSmsFunc, } - // 临时增加流控标志 - redis.GetRedisClient().Set("sms_index", int64(0), 0) return } @@ -97,45 +88,12 @@ func (p *VeriCode) OpSendVeriCode(ctx *gin.Context, req *vericodeproto.OpSendReq return err } - // 分流比率 - smsSplitRatio, err := apollo.GetIntValue(consts.SmsSplitRatioKey, apollo.ApolloOpts().SetNamespace("application")) + //3.zthy发送短信 + err := p.zthySendSmsFunc(req.MobilePhone, vericode) if err != nil { - logger.Error("Apollo read failed : %v", err) + logger.Error("SendSms failed : %v", err) return err } - smsIndex, err := redis.GetRedisClient().GetInt64("sms_index") - if err != nil { - logger.Error("GetInt64 failed : %v", err) - return err - } - err = redis.GetRedisClient().Set("sms_index", (smsIndex+1)%10, 0) - if err != nil { - logger.Error("SetInt64 failed : %v", err) - return err - } - if smsIndex < int64(smsSplitRatio) { - //3.zthy发送短信 - err = p.zthySendSmsFunc(req.MobilePhone, vericode) - if err != nil { - logger.Error("SendSms failed : %v", err) - return err - } - } else { - //3.阿里云发送短信 - templateParam := "{\"code\": \"" + vericode + "\"}" - request := &dysmsapi.SendSmsRequest{ - PhoneNumbers: goproto.String(req.MobilePhone), - SignName: goproto.String(p.cfg.SignName), - TemplateCode: goproto.String(p.cfg.TemplateCode), - TemplateParam: goproto.String(templateParam), - } - err = sms.SendSms(request) - if err != nil { - logger.Error("SendSms failed : %v", err) - return err - } - } - return nil } diff --git a/app/mix/service/service.go b/app/mix/service/service.go index 7d823edb..66d4d1af 100644 --- a/app/mix/service/service.go +++ b/app/mix/service/service.go @@ -199,7 +199,7 @@ func (s *Service) Init(c any) (err error) { yeepaycli.Init(cfg.Yeepay) _DefaultToken = logic.NewToken(store, cfg.Crypto) - _DefaultVeriCode = logic.NewVeriCode(store, cfg.Dysmsapi, DefaultZthyService.SendSms) + _DefaultVeriCode = logic.NewVeriCode(store, DefaultZthyService.SendSms) _DefaultVeriCodeSendTimes = logic.NewVeriCodeSendTimes(store) _DefaultAccount = logic.NewAccount(store) _DefaultProduct = logic.NewProduct(store)