From 82caad967990e5f823934f4c914cf17d7804e2ae Mon Sep 17 00:00:00 2001 From: lzh <18320341470> Date: Wed, 18 Jun 2025 16:42:55 +0800 Subject: [PATCH] sms_tool --- sms_tool/sms_client.go | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/sms_tool/sms_client.go b/sms_tool/sms_client.go index 8790318..1979a65 100644 --- a/sms_tool/sms_client.go +++ b/sms_tool/sms_client.go @@ -75,7 +75,29 @@ func (c *SmsClient) GetCode(ctx context.Context, key string) (code string, err e } // SaveCode 保存验证码 -func (c *SmsClient) SaveCode(ctx context.Context, key string, code string, expire time.Duration, frequency time.Duration) (err error) { +func (c *SmsClient) SaveCode(ctx context.Context, key string, code string, expire time.Duration) (err error) { + if c.Cache == nil { + return errors.New("缓存不能为空") + } + //保存code + err = c.Cache.Set(ctx, key, code, expire) + if err != nil { + return err + } + return nil +} + +// DeleteCode 删除验证码 +func (c *SmsClient) DeleteCode(ctx context.Context, key string) (err error) { + if c.Cache == nil { + return errors.New("缓存不能为空") + } + err = c.Cache.Del(ctx, key) + return err +} + +// SaveCodeWithFrequency 保存验证码并限制请求频率 +func (c *SmsClient) SaveCodeWithFrequency(ctx context.Context, key string, code string, expire time.Duration, frequency time.Duration) (err error) { if c.Cache == nil { return errors.New("缓存不能为空") } @@ -96,7 +118,7 @@ func (c *SmsClient) SaveCode(ctx context.Context, key string, code string, expir } } //保存code - err = c.Cache.Set(ctx, key, code, expire) + err = c.SaveCode(ctx, key, code, expire) if err != nil { return err } @@ -110,15 +132,6 @@ func (c *SmsClient) SaveCode(ctx context.Context, key string, code string, expir return nil } -// DeleteCode 删除验证码 -func (c *SmsClient) DeleteCode(ctx context.Context, key string) (err error) { - if c.Cache == nil { - return errors.New("缓存不能为空") - } - err = c.Cache.Del(ctx, key) - return err -} - // VerifyCode 校验验证码 func (c *SmsClient) VerifyCode(ctx context.Context, key string, verifyCode string) (ok bool, err error) { //获取验证码