key.go
1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package redisdata
import (
"fmt"
"time"
)
const (
KEY_PREFIX string = "oppmg_" //统一前缀
KEY_USER_TOKEN string = "token" //登录token存储
KEY_CAPTCHA_AUTH string = "captch_auth" //统一用户中心返回的验证码凭证
KEY_USER_PERMISSION string = "user_permission" //用户操作权限
)
const (
LOGIN_TOKEN_EXP = 1800 * time.Second //token 过期时间30分钟
CAPTCHA_AUTH_EXP = 300 * time.Second // 验证码凭证 过期时间5分钟
)
type RedisLoginToken struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
CurrentCompany int64 `json:"current_company"`
}
func GetKeyLoginToken(userid int64, companyid int64) string {
key := fmt.Sprintf("%s%s:%d_%d", KEY_PREFIX, KEY_USER_TOKEN, userid, companyid)
return key
}
func GetKeyCaptchAuth(phone string) string {
key := fmt.Sprintf("%s%s:%s", KEY_PREFIX, KEY_CAPTCHA_AUTH, phone)
return key
}
func GetKeyUserPermission(userCompanyId int64) string {
key := fmt.Sprintf("%s%s:%d", KEY_PREFIX, KEY_USER_PERMISSION, userCompanyId)
return key
}