diff --git a/config/config.yaml b/config/config.yaml index 5490d9146..0e8748c03 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -234,6 +234,8 @@ push: appKey: "" intent: "" enable: false + channelID: "" + channelName: "" fcm: #firebase cloud message 消息推送 serviceAccount: "openim-5c6c0-firebase-adminsdk-ppwol-8765884a78.json" #帐号文件,此处需要改修配置,并且这个文件放在 config目录下 enable: false diff --git a/internal/demo/register/check_login.go b/internal/demo/register/check_login.go index 6592172ca..8cb051baf 100644 --- a/internal/demo/register/check_login.go +++ b/internal/demo/register/check_login.go @@ -48,17 +48,7 @@ func CheckLoginLimit(c *gin.Context) { var Limited bool var LimitError error - Limited, LimitError = imdb.IsLimitLoginIp(ip) - if LimitError != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), LimitError, ip) - c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.ErrDB.ErrCode, "errMsg": LimitError}) - return - } - if Limited { - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), Limited, ip, req.UserID) - c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.LoginLimit, "errMsg": "ip limited Login"}) - return - } + // 指定账户指定ip才能登录 Limited, LimitError = imdb.IsLimitUserLoginIp(user.UserID, ip) if LimitError != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), LimitError, ip) @@ -70,6 +60,20 @@ func CheckLoginLimit(c *gin.Context) { c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.LoginLimit, "errMsg": "user ip limited Login"}) return } + + // 该ip不能登录 + Limited, LimitError = imdb.IsLimitLoginIp(ip) + if LimitError != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), LimitError, ip) + c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.ErrDB.ErrCode, "errMsg": LimitError}) + return + } + if Limited { + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), Limited, ip, req.UserID) + c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.LoginLimit, "errMsg": "ip limited Login"}) + return + } + Limited, LimitError = imdb.UserIsBlock(user.UserID) if LimitError != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), LimitError, user.UserID) diff --git a/internal/push/getui/push.go b/internal/push/getui/push.go index d19f80424..5e7786e6a 100644 --- a/internal/push/getui/push.go +++ b/internal/push/getui/push.go @@ -88,9 +88,11 @@ type Android struct { } type Notification struct { - Title string `json:"title"` - Body string `json:"body"` - ClickType string `json:"click_type"` + Title string `json:"title"` + Body string `json:"body"` + ChannelID string `json:"channelID"` + ChannelName string `json:"ChannelName"` + ClickType string `json:"click_type"` } type Options struct { @@ -135,9 +137,11 @@ func (g *Getui) Push(userIDList []string, title, detailContent, operationID stri }{Alias: []string{userIDList[0]}}, } pushReq.PushMessage.Notification = Notification{ - Title: title, - Body: detailContent, - ClickType: "startapp", + Title: title, + Body: detailContent, + ClickType: "startapp", + ChannelID: config.Config.Push.Getui.ChannelID, + ChannelName: config.Config.Push.Getui.ChannelName, } pushReq.PushChannel.Ios.Aps.Sound = "default" pushReq.PushChannel.Ios.Aps.Alert = Alert{ diff --git a/pkg/common/config/config.go b/pkg/common/config/config.go index a9b0fd343..d28362808 100644 --- a/pkg/common/config/config.go +++ b/pkg/common/config/config.go @@ -208,6 +208,8 @@ type config struct { Enable bool `yaml:"enable"` Intent string `yaml:"intent"` MasterSecret string `yaml:"masterSecret"` + ChannelID string `yaml:"channelID"` + ChannelName string `yaml:"channelName"` } Fcm struct { ServiceAccount string `yaml:"serviceAccount"` diff --git a/pkg/common/constant/constant.go b/pkg/common/constant/constant.go index aa7a747cf..3642b31c3 100644 --- a/pkg/common/constant/constant.go +++ b/pkg/common/constant/constant.go @@ -337,4 +337,4 @@ const StatisticsTimeInterval = 60 const MaxNotificationNum = 100 -const CurrentVersion = "v2.3.3-rc0" +const CurrentVersion = "v2.3.3" diff --git a/pkg/common/db/mysql_model/im_mysql_model/ip_model.go b/pkg/common/db/mysql_model/im_mysql_model/ip_model.go index d9ff1bfcb..d87a08796 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/ip_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/ip_model.go @@ -26,13 +26,22 @@ func IsLimitLoginIp(LoginIp string) (bool, error) { return count > 0, nil } -func IsLimitUserLoginIp(userID string, LoginIp string) (bool, error) { +func IsLimitUserLoginIp(userID string, loginIp string) (limit bool, err error) { //如果已经存在则放行 var count int64 - if err := db.DB.MysqlDB.DefaultGormDB().Table("user_ip_limits").Where("ip=? and user_id=?", LoginIp, userID).Count(&count).Error; err != nil { - return false, err + result := db.DB.MysqlDB.DefaultGormDB().Table("user_ip_limits").Where("user_id=?", userID).Count(&count) + if err := result.Error; err != nil { + return true, err } - return count == 0, nil + if count < 1 { + return false, nil + } + result = db.DB.MysqlDB.DefaultGormDB().Table("user_ip_limits").Where("user_id=? and ip = ?", userID, loginIp).Count(&count) + if err := result.Error; err != nil { + return true, err + } + + return count > 0, nil } func QueryIPLimits(ip string) (*db.IpLimit, error) { diff --git a/pkg/grpc-etcdv3/getcdv3/resolver.go b/pkg/grpc-etcdv3/getcdv3/resolver.go index 8f6a383d6..d2fda0cd9 100644 --- a/pkg/grpc-etcdv3/getcdv3/resolver.go +++ b/pkg/grpc-etcdv3/getcdv3/resolver.go @@ -6,7 +6,6 @@ import ( "Open_IM/pkg/utils" "context" "fmt" - "go.etcd.io/etcd/api/v3/mvccpb" clientv3 "go.etcd.io/etcd/client/v3" @@ -271,8 +270,38 @@ func (r *Resolver) watch(prefix string, addrList []resolver.Address) { } } +var Conn4UniqueList []*grpc.ClientConn +var Conn4UniqueListMtx sync.RWMutex +var IsUpdateStart bool +var IsUpdateStartMtx sync.RWMutex + func GetDefaultGatewayConn4Unique(schema, etcdaddr, operationID string) []*grpc.ClientConn { - grpcConns := getConn4Unique(schema, etcdaddr, config.Config.RpcRegisterName.OpenImRelayName) + IsUpdateStartMtx.Lock() + if IsUpdateStart == false { + Conn4UniqueList = getConn4Unique(schema, etcdaddr, config.Config.RpcRegisterName.OpenImRelayName) + go func() { + for { + select { + case <-time.After(time.Second * time.Duration(30)): + Conn4UniqueListMtx.Lock() + Conn4UniqueList = getConn4Unique(schema, etcdaddr, config.Config.RpcRegisterName.OpenImRelayName) + Conn4UniqueListMtx.Unlock() + } + } + }() + } + IsUpdateStart = true + IsUpdateStartMtx.Unlock() + + Conn4UniqueListMtx.Lock() + var clientConnList []*grpc.ClientConn + for _, v := range Conn4UniqueList { + clientConnList = append(clientConnList, v) + } + Conn4UniqueListMtx.Unlock() + + //grpcConns := getConn4Unique(schema, etcdaddr, config.Config.RpcRegisterName.OpenImRelayName) + grpcConns := clientConnList if len(grpcConns) > 0 { return grpcConns }