...
|
...
|
@@ -2,7 +2,6 @@ package redisdata |
|
|
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
"oppmg/common/log"
|
|
|
"oppmg/common/redis"
|
|
|
"oppmg/protocol"
|
...
|
...
|
@@ -26,12 +25,12 @@ func SetLoginToken(param protocol.LoginAuthToken, userid int64, companyid int64) |
|
|
}
|
|
|
value, _ = json.Marshal(data)
|
|
|
exp = param.RefreshExpires - nowTime
|
|
|
key = fmt.Sprintf("%s%s:%d", KEY_PREFIX, KEY_USER_TOKEN, userid)
|
|
|
key = GetKeyLoginToken(userid, companyid)
|
|
|
err = client.Set(key, string(value), time.Duration(exp)*time.Second).Err()
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
func GetLoginToken(userid int64) (RedisLoginToken, error) {
|
|
|
func GetLoginToken(userid int64, companyid int64) (RedisLoginToken, error) {
|
|
|
client := redis.GetRedis()
|
|
|
var (
|
|
|
key string
|
...
|
...
|
@@ -39,7 +38,7 @@ func GetLoginToken(userid int64) (RedisLoginToken, error) { |
|
|
err error
|
|
|
result RedisLoginToken
|
|
|
)
|
|
|
key = fmt.Sprintf("%s%s:%d", KEY_PREFIX, KEY_USER_TOKEN, userid)
|
|
|
key = GetKeyLoginToken(userid, companyid)
|
|
|
value, err = client.Get(key).Result()
|
|
|
if err != nil {
|
|
|
return result, err
|
...
|
...
|
@@ -53,9 +52,9 @@ func GetLoginToken(userid int64) (RedisLoginToken, error) { |
|
|
return result, nil
|
|
|
}
|
|
|
|
|
|
func ExistLoginToken(userid int64) bool {
|
|
|
func ExistLoginToken(userid int64, companyid int64) bool {
|
|
|
client := redis.GetRedis()
|
|
|
key := fmt.Sprintf("%s%s:%d", KEY_PREFIX, KEY_USER_TOKEN, userid)
|
|
|
key := GetKeyLoginToken(userid, companyid)
|
|
|
value := client.Exists(key).Val()
|
|
|
if value > 0 {
|
|
|
return true
|
...
|
...
|
@@ -63,17 +62,17 @@ func ExistLoginToken(userid int64) bool { |
|
|
return false
|
|
|
}
|
|
|
|
|
|
func DeleteLoginToken(userid int64) error {
|
|
|
func DeleteLoginToken(userid int64, companyid int64) error {
|
|
|
client := redis.GetRedis()
|
|
|
key := fmt.Sprintf("%s%s:%d", KEY_PREFIX, KEY_USER_TOKEN, userid)
|
|
|
key := GetKeyLoginToken(userid, companyid)
|
|
|
err := client.Del(key).Err()
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
// 刷新token 的有效期
|
|
|
func RefreshLoginTokenExpires(userid int64) error {
|
|
|
func RefreshLoginTokenExpires(userid int64, companyid int64) error {
|
|
|
client := redis.GetRedis()
|
|
|
key := fmt.Sprintf("%s%s:%d", KEY_PREFIX, KEY_USER_TOKEN, userid)
|
|
|
key := GetKeyLoginToken(userid, companyid)
|
|
|
result, err := client.Exists(key).Result()
|
|
|
if err != nil {
|
|
|
return err
|
...
|
...
|
|