generateVerifyCode 生成验证码,并放置于 Redis 中
(key string)
| 72 | |
| 73 | // generateVerifyCode 生成验证码,并放置于 Redis 中 |
| 74 | func (vc *VerifyCode) generateVerifyCode(key string) string { |
| 75 | |
| 76 | // 生成随机码 |
| 77 | code := helpers.RandomNumber(config.GetInt("verifycode.code_length")) |
| 78 | |
| 79 | // 为方便开发,本地环境使用固定验证码 |
| 80 | if app.IsLocal() { |
| 81 | code = config.GetString("verifycode.debug_code") |
| 82 | } |
| 83 | |
| 84 | logger.DebugJSON("验证码", "生成验证码", map[string]string{key: code}) |
| 85 | |
| 86 | // 将验证码及 KEY(邮箱或手机号)存放到 Redis 中并设置过期时间 |
| 87 | vc.Store.Set(key, code) |
| 88 | return code |
| 89 | } |
| 90 | |
| 91 | // SendEmail 发送邮件验证码,调用示例: |
| 92 | // |