mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-04 09:05:59 +08:00
ws and push update
This commit is contained in:
@@ -27,7 +27,7 @@ const (
|
||||
TerminalMobile = "Mobile"
|
||||
)
|
||||
|
||||
var PlatformID2Name = map[int32]string{
|
||||
var PlatformID2Name = map[int]string{
|
||||
IOSPlatformID: IOSPlatformStr,
|
||||
AndroidPlatformID: AndroidPlatformStr,
|
||||
WindowsPlatformID: WindowsPlatformStr,
|
||||
@@ -36,7 +36,7 @@ var PlatformID2Name = map[int32]string{
|
||||
MiniWebPlatformID: MiniWebPlatformStr,
|
||||
LinuxPlatformID: LinuxPlatformStr,
|
||||
}
|
||||
var PlatformName2ID = map[string]int32{
|
||||
var PlatformName2ID = map[string]int{
|
||||
IOSPlatformStr: IOSPlatformID,
|
||||
AndroidPlatformStr: AndroidPlatformID,
|
||||
WindowsPlatformStr: WindowsPlatformID,
|
||||
@@ -55,10 +55,10 @@ var Platform2class = map[string]string{
|
||||
LinuxPlatformStr: TerminalPC,
|
||||
}
|
||||
|
||||
func PlatformIDToName(num int32) string {
|
||||
func PlatformIDToName(num int) string {
|
||||
return PlatformID2Name[num]
|
||||
}
|
||||
func PlatformNameToID(name string) int32 {
|
||||
func PlatformNameToID(name string) int {
|
||||
return PlatformName2ID[name]
|
||||
}
|
||||
func PlatformNameToClass(name string) string {
|
||||
|
||||
@@ -111,7 +111,7 @@ func (d *DataBases) DelAppleDeviceToken(accountAddress string) (err error) {
|
||||
}
|
||||
|
||||
//Store userid and platform class to redis
|
||||
func (d *DataBases) AddTokenFlag(userID string, platformID int32, token string, flag int) error {
|
||||
func (d *DataBases) AddTokenFlag(userID string, platformID int, token string, flag int) error {
|
||||
key := uidPidToken + userID + ":" + constant.PlatformIDToName(platformID)
|
||||
log2.NewDebug("", "add token key is ", key)
|
||||
_, err1 := d.Exec("HSet", key, token, flag)
|
||||
@@ -123,12 +123,12 @@ func (d *DataBases) GetTokenMapByUidPid(userID, platformID string) (map[string]i
|
||||
log2.NewDebug("", "get token key is ", key)
|
||||
return redis.IntMap(d.Exec("HGETALL", key))
|
||||
}
|
||||
func (d *DataBases) SetTokenMapByUidPid(userID string, platformID int32, m map[string]int) error {
|
||||
func (d *DataBases) SetTokenMapByUidPid(userID string, platformID int, m map[string]int) error {
|
||||
key := uidPidToken + userID + ":" + constant.PlatformIDToName(platformID)
|
||||
_, err := d.Exec("hmset", key, redis.Args{}.Add().AddFlat(m)...)
|
||||
return err
|
||||
}
|
||||
func (d *DataBases) DeleteTokenByUidPid(userID string, platformID int32, fields []string) error {
|
||||
func (d *DataBases) DeleteTokenByUidPid(userID string, platformID int, fields []string) error {
|
||||
key := uidPidToken + userID + ":" + constant.PlatformIDToName(platformID)
|
||||
_, err := d.Exec("HDEL", key, redis.Args{}.Add().AddFlat(fields)...)
|
||||
return err
|
||||
|
||||
@@ -37,7 +37,7 @@ func BuildClaims(uid, platform string, ttl int64) Claims {
|
||||
}}
|
||||
}
|
||||
|
||||
func CreateToken(userID string, platformID int32) (string, int64, error) {
|
||||
func CreateToken(userID string, platformID int) (string, int64, error) {
|
||||
claims := BuildClaims(userID, constant.PlatformIDToName(platformID), config.Config.TokenPolicy.AccessExpire)
|
||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
|
||||
tokenString, err := token.SignedString([]byte(config.Config.TokenPolicy.AccessSecret))
|
||||
@@ -233,7 +233,7 @@ func WsVerifyToken(token, uid string, platformID string, operationID string) (bo
|
||||
if claims.UID != uid {
|
||||
return false, utils.Wrap(&constant.ErrTokenUnknown, "uid is not same to token uid"), "uid is not same to token uid"
|
||||
}
|
||||
if claims.Platform != constant.PlatformIDToName(utils.StringToInt32(platformID)) {
|
||||
if claims.Platform != constant.PlatformIDToName(utils.StringToInt(platformID)) {
|
||||
return false, utils.Wrap(&constant.ErrTokenUnknown, "platform is not same to token platform"), "platform is not same to token platform"
|
||||
}
|
||||
log.NewDebug(operationID, utils.GetSelfFuncName(), " check ok ", claims.UID, uid, claims.Platform)
|
||||
|
||||
Reference in New Issue
Block a user