sms_tool
This commit is contained in:
parent
9a27e529eb
commit
82caad9679
@ -75,7 +75,29 @@ func (c *SmsClient) GetCode(ctx context.Context, key string) (code string, err e
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SaveCode 保存验证码
|
// 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 {
|
if c.Cache == nil {
|
||||||
return errors.New("缓存不能为空")
|
return errors.New("缓存不能为空")
|
||||||
}
|
}
|
||||||
@ -96,7 +118,7 @@ func (c *SmsClient) SaveCode(ctx context.Context, key string, code string, expir
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//保存code
|
//保存code
|
||||||
err = c.Cache.Set(ctx, key, code, expire)
|
err = c.SaveCode(ctx, key, code, expire)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -110,15 +132,6 @@ func (c *SmsClient) SaveCode(ctx context.Context, key string, code string, expir
|
|||||||
return nil
|
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 校验验证码
|
// VerifyCode 校验验证码
|
||||||
func (c *SmsClient) VerifyCode(ctx context.Context, key string, verifyCode string) (ok bool, err error) {
|
func (c *SmsClient) VerifyCode(ctx context.Context, key string, verifyCode string) (ok bool, err error) {
|
||||||
//获取验证码
|
//获取验证码
|
||||||
|
Loading…
x
Reference in New Issue
Block a user