sms

package
v0.0.0-...-851e7b8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 14, 2020 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RedisModel

type RedisModel struct {
	Mobile     string    `json:"mobile"`
	Key        string    `json:"key"`
	Code       string    `json:"code"`
	Action     string    `json:"action"`
	CreateTime time.Time `json:"createTime"`
}

RedisModel is redis tool for transform data from redis to struct

func (*RedisModel) Marshal

func (r *RedisModel) Marshal() ([]byte, error)

Marshal is difined to marshal data to bytes 转化字节用户redis存储

func (*RedisModel) Unmarshal

func (r *RedisModel) Unmarshal(data []byte) error

Unmarshal can be used for json data unmarshal 解码字节码,用于redis校验

type SMS

type SMS struct{}

SMS is SMS tool model

func (*SMS) GenerateCode

func (s *SMS) GenerateCode(mobile string, action string) (string, string, error)

GenerateCode is defined to create a new sms code in random 生成短信验证码并存储在redis中,验证码有效时间为一个小时,验证码1小时后将被redis清除

生成的验证码使用key来查询
返回:生成的验证码 验证码存储的redis key 错误信息

func (*SMS) GetSMSConfigs

func (s *SMS) GetSMSConfigs() (*conf.SMSConfig, error)

GetSMSConfigs is defined to get sms configs from yaml 获取验证码模板和相关配置信息

func (*SMS) Send

func (s *SMS) Send(action string, mobile string, validationCode string) error

Send is a method defined to send sms through api gateway 我们使用了253.com的短信api验证接口,如果你需要修改,那么修改sendSMS,而不是修改这里

253短信验证码接口的文档 https://github.com/cl253/chuanglan253-go

请千万不要直接修改这里,这里什么都没做,简单验证了参数

func (*SMS) Validate

func (s *SMS) Validate(mobile string, action string, key string, code string) (bool, error)

Validate is defined to check if user answer is valid or not 校验验证码与redis中的是否匹配 验证码校验后,直接返回成功与否结果 每个验证码仅支持校验一次,如果校验完成,将自动从redis中移除这个key,不在支持二次校验

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL