From a1067492b72349a1b5a63c3b5dfa464c3f231056 Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Fri, 25 Feb 2022 18:35:04 +0800 Subject: [PATCH 01/67] server msg id update --- internal/rpc/msg/send_msg.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/rpc/msg/send_msg.go b/internal/rpc/msg/send_msg.go index 114746da2..a57a6e892 100644 --- a/internal/rpc/msg/send_msg.go +++ b/internal/rpc/msg/send_msg.go @@ -245,7 +245,7 @@ func (rpc *rpcChat) sendMsgToKafka(m *pbChat.MsgDataToMQ, key string) error { } func GetMsgID(sendID string) string { t := time.Now().Format("2006-01-02 15:04:05") - return t + "-" + sendID + "-" + strconv.Itoa(rand.Int()) + return utils.Md5(t + "-" + sendID + "-" + strconv.Itoa(rand.Int())) } func returnMsg(replay *pbChat.SendMsgResp, pb *pbChat.SendMsgReq, errCode int32, errMsg, serverMsgID string, sendTime int64) (*pbChat.SendMsgResp, error) { From 55c8399084b78c3d73c455b6540ea1fa083ccce1 Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Fri, 25 Feb 2022 19:19:23 +0800 Subject: [PATCH 02/67] remove mysql for test --- internal/msg_transfer/logic/init.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/msg_transfer/logic/init.go b/internal/msg_transfer/logic/init.go index cce434d99..7d1cad671 100644 --- a/internal/msg_transfer/logic/init.go +++ b/internal/msg_transfer/logic/init.go @@ -20,6 +20,6 @@ func Init() { } func Run() { //register mysqlConsumerHandler to - go persistentCH.persistentConsumerGroup.RegisterHandleAndConsumer(&persistentCH) + //go persistentCH.persistentConsumerGroup.RegisterHandleAndConsumer(&persistentCH) go historyCH.historyConsumerGroup.RegisterHandleAndConsumer(&historyCH) } From 8c9d1b7dec123c1f192d27e9b39a157ee8d1efdb Mon Sep 17 00:00:00 2001 From: wenxu12345 <44203734@qq.com> Date: Fri, 25 Feb 2022 19:29:39 +0800 Subject: [PATCH 03/67] statistics --- pkg/statistics/statistics.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 pkg/statistics/statistics.go diff --git a/pkg/statistics/statistics.go b/pkg/statistics/statistics.go new file mode 100644 index 000000000..51ff4c871 --- /dev/null +++ b/pkg/statistics/statistics.go @@ -0,0 +1,20 @@ +package statistics + +import "time" + +type Statistics struct { + Count *uint64 + Dr int +} + +func (s *Statistics) output() { + for { + time.Sleep(time.Duration(s.Dr) * time.Second) + + } +} + +func NewStatistics(count *uint64, dr int) *Statistics { + p := &Statistics{Count: count} + go p.output() +} From 4f01b0b2adb336b172a0c67d71bb24ed8ef264a9 Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Fri, 25 Feb 2022 19:39:42 +0800 Subject: [PATCH 04/67] remove mysql for test --- internal/push/logic/init.go | 12 +++ internal/push/logic/push_to_client.go | 126 +++++++++++++------------- pkg/statistics/statistics.go | 25 +++-- 3 files changed, 92 insertions(+), 71 deletions(-) diff --git a/internal/push/logic/init.go b/internal/push/logic/init.go index b8941cc6f..3581a361e 100644 --- a/internal/push/logic/init.go +++ b/internal/push/logic/init.go @@ -11,6 +11,7 @@ import ( "Open_IM/pkg/common/constant" "Open_IM/pkg/common/kafka" "Open_IM/pkg/common/log" + "time" ) var ( @@ -33,4 +34,15 @@ func init() { func Run() { go rpcServer.run() go pushCh.pushConsumerGroup.RegisterHandleAndConsumer(&pushCh) + go stat() +} +func stat() { + t := time.NewTicker(time.Second * 10) + defer t.Stop() + for { + select { + case <-t.C: + } + log.Debug("", "10 second handle msg to mongo is ") + } } diff --git a/internal/push/logic/push_to_client.go b/internal/push/logic/push_to_client.go index 41c943c4b..fa147e762 100644 --- a/internal/push/logic/push_to_client.go +++ b/internal/push/logic/push_to_client.go @@ -7,16 +7,12 @@ package logic import ( - push "Open_IM/internal/push/jpush" "Open_IM/pkg/common/config" - "Open_IM/pkg/common/constant" "Open_IM/pkg/common/log" "Open_IM/pkg/grpc-etcdv3/getcdv3" pbPush "Open_IM/pkg/proto/push" pbRelay "Open_IM/pkg/proto/relay" - "Open_IM/pkg/utils" "context" - "encoding/json" "strings" ) @@ -34,7 +30,7 @@ type AtContent struct { func MsgToUser(pushMsg *pbPush.PushMsgReq) { var wsResult []*pbRelay.SingleMsgToUser - isOfflinePush := utils.GetSwitchFromOptions(pushMsg.MsgData.Options, constant.IsOfflinePush) + //isOfflinePush := utils.GetSwitchFromOptions(pushMsg.MsgData.Options, constant.IsOfflinePush) log.InfoByKv("Get msg from msg_transfer And push msg", pushMsg.OperationID, "PushData", pushMsg.String()) grpcCons := getcdv3.GetConn4Unique(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOnlineMessageRelayName) //Online push message @@ -51,66 +47,66 @@ func MsgToUser(pushMsg *pbPush.PushMsgReq) { } } log.InfoByKv("push_result", pushMsg.OperationID, "result", wsResult, "sendData", pushMsg.MsgData) - if isOfflinePush && pushMsg.PushToUserID != pushMsg.MsgData.SendID { - for _, v := range wsResult { - if v.ResultCode == 0 { - continue - } - //supported terminal - for _, t := range pushTerminal { - if v.RecvPlatFormID == t { - //Use offline push messaging - var UIDList []string - UIDList = append(UIDList, v.RecvID) - customContent := OpenIMContent{ - SessionType: int(pushMsg.MsgData.SessionType), - From: pushMsg.MsgData.SendID, - To: pushMsg.MsgData.RecvID, - Seq: pushMsg.MsgData.Seq, - } - bCustomContent, _ := json.Marshal(customContent) - jsonCustomContent := string(bCustomContent) - var content string - if pushMsg.MsgData.OfflinePushInfo != nil { - content = pushMsg.MsgData.OfflinePushInfo.Title - - } else { - switch pushMsg.MsgData.ContentType { - case constant.Text: - content = constant.ContentType2PushContent[constant.Text] - case constant.Picture: - content = constant.ContentType2PushContent[constant.Picture] - case constant.Voice: - content = constant.ContentType2PushContent[constant.Voice] - case constant.Video: - content = constant.ContentType2PushContent[constant.Video] - case constant.File: - content = constant.ContentType2PushContent[constant.File] - case constant.AtText: - a := AtContent{} - _ = utils.JsonStringToStruct(string(pushMsg.MsgData.Content), &a) - if utils.IsContain(v.RecvID, a.AtUserList) { - content = constant.ContentType2PushContent[constant.AtText] + constant.ContentType2PushContent[constant.Common] - } else { - content = constant.ContentType2PushContent[constant.GroupMsg] - } - default: - content = constant.ContentType2PushContent[constant.Common] - } - } - - pushResult, err := push.JGAccountListPush(UIDList, content, jsonCustomContent, constant.PlatformIDToName(t)) - if err != nil { - log.NewError(pushMsg.OperationID, "offline push error", pushMsg.String(), err.Error(), constant.PlatformIDToName(t)) - } else { - log.NewDebug(pushMsg.OperationID, "offline push return result is ", string(pushResult), pushMsg.MsgData, constant.PlatformIDToName(t)) - } - - } - } - } - - } + //if isOfflinePush && pushMsg.PushToUserID != pushMsg.MsgData.SendID { + // for _, v := range wsResult { + // if v.ResultCode == 0 { + // continue + // } + // //supported terminal + // for _, t := range pushTerminal { + // if v.RecvPlatFormID == t { + // //Use offline push messaging + // var UIDList []string + // UIDList = append(UIDList, v.RecvID) + // customContent := OpenIMContent{ + // SessionType: int(pushMsg.MsgData.SessionType), + // From: pushMsg.MsgData.SendID, + // To: pushMsg.MsgData.RecvID, + // Seq: pushMsg.MsgData.Seq, + // } + // bCustomContent, _ := json.Marshal(customContent) + // jsonCustomContent := string(bCustomContent) + // var content string + // if pushMsg.MsgData.OfflinePushInfo != nil { + // content = pushMsg.MsgData.OfflinePushInfo.Title + // + // } else { + // switch pushMsg.MsgData.ContentType { + // case constant.Text: + // content = constant.ContentType2PushContent[constant.Text] + // case constant.Picture: + // content = constant.ContentType2PushContent[constant.Picture] + // case constant.Voice: + // content = constant.ContentType2PushContent[constant.Voice] + // case constant.Video: + // content = constant.ContentType2PushContent[constant.Video] + // case constant.File: + // content = constant.ContentType2PushContent[constant.File] + // case constant.AtText: + // a := AtContent{} + // _ = utils.JsonStringToStruct(string(pushMsg.MsgData.Content), &a) + // if utils.IsContain(v.RecvID, a.AtUserList) { + // content = constant.ContentType2PushContent[constant.AtText] + constant.ContentType2PushContent[constant.Common] + // } else { + // content = constant.ContentType2PushContent[constant.GroupMsg] + // } + // default: + // content = constant.ContentType2PushContent[constant.Common] + // } + // } + // + // pushResult, err := push.JGAccountListPush(UIDList, content, jsonCustomContent, constant.PlatformIDToName(t)) + // if err != nil { + // log.NewError(pushMsg.OperationID, "offline push error", pushMsg.String(), err.Error(), constant.PlatformIDToName(t)) + // } else { + // log.NewDebug(pushMsg.OperationID, "offline push return result is ", string(pushResult), pushMsg.MsgData, constant.PlatformIDToName(t)) + // } + // + // } + // } + // } + // + //} } //func SendMsgByWS(m *pbChat.WSToMsgSvrChatMsg) { diff --git a/pkg/statistics/statistics.go b/pkg/statistics/statistics.go index 51ff4c871..eb018fbf0 100644 --- a/pkg/statistics/statistics.go +++ b/pkg/statistics/statistics.go @@ -1,20 +1,33 @@ package statistics -import "time" +import ( + "Open_IM/pkg/common/log" + "time" +) type Statistics struct { - Count *uint64 - Dr int + Count *uint64 + ModuleName string + PrintArgs string + SleepTime int } func (s *Statistics) output() { + t := time.NewTicker(time.Duration(s.SleepTime) * time.Second) + defer t.Stop() + var sum uint64 for { - time.Sleep(time.Duration(s.Dr) * time.Second) + sum = *s.Count + select { + case <-t.C: + } + log.Debug(s.ModuleName, s.PrintArgs, *s.Count-sum) } } -func NewStatistics(count *uint64, dr int) *Statistics { - p := &Statistics{Count: count} +func NewStatistics(count *uint64, moduleName, printArgs string, sleepTime int) *Statistics { + p := &Statistics{Count: count, ModuleName: moduleName, SleepTime: sleepTime, PrintArgs: printArgs} go p.output() + return p } From 2775d9b78a7ef68d32ed75d9384ab848c48e1b6e Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Fri, 25 Feb 2022 19:49:38 +0800 Subject: [PATCH 05/67] test --- internal/msg_gateway/gate/init.go | 4 ++++ internal/msg_gateway/gate/logic.go | 1 + internal/push/logic/init.go | 16 ++++------------ internal/push/logic/push_to_client.go | 1 + 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/internal/msg_gateway/gate/init.go b/internal/msg_gateway/gate/init.go index 03f82f3ad..47d1dcedb 100644 --- a/internal/msg_gateway/gate/init.go +++ b/internal/msg_gateway/gate/init.go @@ -3,6 +3,8 @@ package gate import ( "Open_IM/pkg/common/config" "Open_IM/pkg/common/log" + "Open_IM/pkg/statistics" + "fmt" "github.com/go-playground/validator/v10" "sync" ) @@ -12,6 +14,7 @@ var ( validate *validator.Validate ws WServer rpcSvr RPCServer + count uint64 ) func Init(rpcPort, wsPort int) { @@ -19,6 +22,7 @@ func Init(rpcPort, wsPort int) { log.NewPrivateLog(config.Config.ModuleName.LongConnSvrName) rwLock = new(sync.RWMutex) validate = validator.New() + statistics.NewStatistics(&count, config.Config.ModuleName.LongConnSvrName, fmt.Sprintf("%d second recv to msg_gateway count", count), 10) ws.onInit(wsPort) rpcSvr.onInit(rpcPort) } diff --git a/internal/msg_gateway/gate/logic.go b/internal/msg_gateway/gate/logic.go index d1756093c..2aa19f609 100644 --- a/internal/msg_gateway/gate/logic.go +++ b/internal/msg_gateway/gate/logic.go @@ -142,6 +142,7 @@ func (ws *WServer) pullMsgBySeqListResp(conn *UserConn, m *Req, pb *sdk_ws.PullM } func (ws *WServer) sendMsgReq(conn *UserConn, m *Req) { + count++ log.NewInfo(m.OperationID, "Ws call success to sendMsgReq start", m.MsgIncr, m.ReqIdentifier, m.SendID) nReply := new(pbChat.SendMsgResp) isPass, errCode, errMsg, pData := ws.argsValidate(m, constant.WSSendMsg) diff --git a/internal/push/logic/init.go b/internal/push/logic/init.go index 3581a361e..253aea2b2 100644 --- a/internal/push/logic/init.go +++ b/internal/push/logic/init.go @@ -11,7 +11,8 @@ import ( "Open_IM/pkg/common/constant" "Open_IM/pkg/common/kafka" "Open_IM/pkg/common/log" - "time" + "Open_IM/pkg/statistics" + "fmt" ) var ( @@ -19,6 +20,7 @@ var ( pushCh PushConsumerHandler pushTerminal []int32 producer *kafka.Producer + count uint64 ) func Init(rpcPort int) { @@ -29,20 +31,10 @@ func Init(rpcPort int) { } func init() { producer = kafka.NewKafkaProducer(config.Config.Kafka.Ws2mschat.Addr, config.Config.Kafka.Ws2mschat.Topic) + statistics.NewStatistics(&count, config.Config.ModuleName.PushName, fmt.Sprintf("%d second push to msg_gateway count", count), 10) } func Run() { go rpcServer.run() go pushCh.pushConsumerGroup.RegisterHandleAndConsumer(&pushCh) - go stat() -} -func stat() { - t := time.NewTicker(time.Second * 10) - defer t.Stop() - for { - select { - case <-t.C: - } - log.Debug("", "10 second handle msg to mongo is ") - } } diff --git a/internal/push/logic/push_to_client.go b/internal/push/logic/push_to_client.go index fa147e762..b6a624f91 100644 --- a/internal/push/logic/push_to_client.go +++ b/internal/push/logic/push_to_client.go @@ -47,6 +47,7 @@ func MsgToUser(pushMsg *pbPush.PushMsgReq) { } } log.InfoByKv("push_result", pushMsg.OperationID, "result", wsResult, "sendData", pushMsg.MsgData) + count++ //if isOfflinePush && pushMsg.PushToUserID != pushMsg.MsgData.SendID { // for _, v := range wsResult { // if v.ResultCode == 0 { From 739096a9c0673124d474d5e3422a2b8271c5db94 Mon Sep 17 00:00:00 2001 From: wenxu12345 <44203734@qq.com> Date: Fri, 25 Feb 2022 19:50:18 +0800 Subject: [PATCH 06/67] statistics performance --- internal/msg_transfer/logic/history_msg_handler.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/internal/msg_transfer/logic/history_msg_handler.go b/internal/msg_transfer/logic/history_msg_handler.go index b78695c11..f0ba102cd 100644 --- a/internal/msg_transfer/logic/history_msg_handler.go +++ b/internal/msg_transfer/logic/history_msg_handler.go @@ -8,6 +8,7 @@ import ( "Open_IM/pkg/grpc-etcdv3/getcdv3" pbMsg "Open_IM/pkg/proto/chat" pbPush "Open_IM/pkg/proto/push" + "Open_IM/pkg/statistics" "Open_IM/pkg/utils" "context" "github.com/Shopify/sarama" @@ -20,9 +21,14 @@ type fcb func(msg []byte, msgKey string) type HistoryConsumerHandler struct { msgHandle map[string]fcb historyConsumerGroup *kfk.MConsumerGroup + singleMsgCount uint64 + groupMsgCount uint64 } func (mc *HistoryConsumerHandler) Init() { + statistics.NewStatistics(&mc.singleMsgCount, config.Config.ModuleName.MsgTransferName, "singleMsgCount insert to mongo ", 10) + statistics.NewStatistics(&mc.singleMsgCount, config.Config.ModuleName.MsgTransferName, "groupMsgCount insert to mongo ", 10) + mc.msgHandle = make(map[string]fcb) mc.msgHandle[config.Config.Kafka.Ws2mschat.Topic] = mc.handleChatWs2Mongo mc.historyConsumerGroup = kfk.NewMConsumerGroup(&kfk.MConsumerGroupConfig{KafkaVersion: sarama.V0_10_2_0, @@ -55,6 +61,7 @@ func (mc *HistoryConsumerHandler) handleChatWs2Mongo(msg []byte, msgKey string) log.NewError(operationID, "single data insert to mongo err", err.Error(), msgFromMQ.String()) return } + mc.singleMsgCount++ log.NewDebug(msgFromMQ.OperationID, "sendMessageToPush cost time ", utils.GetCurrentTimestampByNano()-time) } if !isSenderSync && msgKey == msgFromMQ.MsgData.SendID { @@ -70,6 +77,7 @@ func (mc *HistoryConsumerHandler) handleChatWs2Mongo(msg []byte, msgKey string) log.NewError(operationID, "group data insert to mongo err", msgFromMQ.String(), msgFromMQ.MsgData.RecvID, err.Error()) return } + mc.groupMsgCount++ } go sendMessageToPush(&msgFromMQ, msgFromMQ.MsgData.RecvID) default: From e1f58f07fe9146d58584e753c23e2f34e0bb7e26 Mon Sep 17 00:00:00 2001 From: wenxu12345 <44203734@qq.com> Date: Fri, 25 Feb 2022 19:55:58 +0800 Subject: [PATCH 07/67] 2.0.1 --- cmd/Open-IM-SDK-Core | 2 +- pkg/statistics/statistics.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/Open-IM-SDK-Core b/cmd/Open-IM-SDK-Core index 992f76df0..1c6c7af53 160000 --- a/cmd/Open-IM-SDK-Core +++ b/cmd/Open-IM-SDK-Core @@ -1 +1 @@ -Subproject commit 992f76df0ee500a0377523b0780d3a85f2275755 +Subproject commit 1c6c7af5393b3e9eefbaf16b673519ca863a6c2c diff --git a/pkg/statistics/statistics.go b/pkg/statistics/statistics.go index eb018fbf0..bda8ded85 100644 --- a/pkg/statistics/statistics.go +++ b/pkg/statistics/statistics.go @@ -21,7 +21,7 @@ func (s *Statistics) output() { select { case <-t.C: } - log.Debug(s.ModuleName, s.PrintArgs, *s.Count-sum) + log.NewWarn(s.ModuleName, s.PrintArgs, *s.Count-sum) } } From ca18958669b98794686e36673a230fb00bf35139 Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Fri, 25 Feb 2022 19:56:00 +0800 Subject: [PATCH 08/67] test config --- config/config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config.yaml b/config/config.yaml index 6e3eaeea6..7d025c863 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -132,7 +132,7 @@ log: storageLocation: ../logs/ rotationTime: 24 remainRotationCount: 5 #日志数量 - remainLogLevel: 6 #日志级别 6表示全都打印,测试阶段建议设置为6 + remainLogLevel: 4 #日志级别 6表示全都打印,测试阶段建议设置为6 elasticSearchSwitch: false elasticSearchAddr: [ 127.0.0.1:9201 ] elasticSearchUser: "" From 00a52475de85eb39cfee7ae58aac8053027165e3 Mon Sep 17 00:00:00 2001 From: wenxu12345 <44203734@qq.com> Date: Fri, 25 Feb 2022 20:01:02 +0800 Subject: [PATCH 09/67] statistics --- internal/msg_transfer/logic/history_msg_handler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/msg_transfer/logic/history_msg_handler.go b/internal/msg_transfer/logic/history_msg_handler.go index f0ba102cd..294b5ed70 100644 --- a/internal/msg_transfer/logic/history_msg_handler.go +++ b/internal/msg_transfer/logic/history_msg_handler.go @@ -27,7 +27,7 @@ type HistoryConsumerHandler struct { func (mc *HistoryConsumerHandler) Init() { statistics.NewStatistics(&mc.singleMsgCount, config.Config.ModuleName.MsgTransferName, "singleMsgCount insert to mongo ", 10) - statistics.NewStatistics(&mc.singleMsgCount, config.Config.ModuleName.MsgTransferName, "groupMsgCount insert to mongo ", 10) + statistics.NewStatistics(&mc.groupMsgCount, config.Config.ModuleName.MsgTransferName, "groupMsgCount insert to mongo ", 10) mc.msgHandle = make(map[string]fcb) mc.msgHandle[config.Config.Kafka.Ws2mschat.Topic] = mc.handleChatWs2Mongo From 05fbbfcf39c9f03bd285c8105bdb1296bd2d9693 Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Mon, 28 Feb 2022 15:28:13 +0800 Subject: [PATCH 10/67] grpc-etcd log --- pkg/grpc-etcdv3/getcdv3/register.go | 12 +++++++----- pkg/grpc-etcdv3/getcdv3/resolver.go | 19 ++++++++++--------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/pkg/grpc-etcdv3/getcdv3/register.go b/pkg/grpc-etcdv3/getcdv3/register.go index 4fd2cd5a7..d1c7957bf 100644 --- a/pkg/grpc-etcdv3/getcdv3/register.go +++ b/pkg/grpc-etcdv3/getcdv3/register.go @@ -1,6 +1,7 @@ package getcdv3 import ( + "Open_IM/pkg/common/log" "context" "fmt" "go.etcd.io/etcd/clientv3" @@ -39,9 +40,9 @@ func RegisterEtcd4Unique(schema, etcdAddr, myHost string, myPort int, serviceNam func RegisterEtcd(schema, etcdAddr, myHost string, myPort int, serviceName string, ttl int) error { cli, err := clientv3.New(clientv3.Config{ Endpoints: strings.Split(etcdAddr, ","), DialTimeout: 5 * time.Second}) - fmt.Println("RegisterEtcd") + + log.Info("", "RegisterEtcd, ", schema, etcdAddr, myHost, myPort, serviceName, ttl) if err != nil { - // return fmt.Errorf("grpclb: create clientv3 client failed: %v", err) return fmt.Errorf("create etcd clientv3 client failed, errmsg:%v, etcd addr:%s", err, etcdAddr) } @@ -66,15 +67,16 @@ func RegisterEtcd(schema, etcdAddr, myHost string, myPort int, serviceName strin if err != nil { return fmt.Errorf("keepalive failed, errmsg:%v, lease id:%d", err, resp.ID) } - fmt.Println("RegisterEtcd ok") + log.Info("", "RegisterEtcd ok ") + go func() { for { select { case v, ok := <-kresp: if ok == true { - // fmt.Println(" kresp ok ", v) + log.Debug("", "KeepAlive kresp ok", v, schema, etcdAddr, myHost, myPort, serviceName, ttl) } else { - fmt.Println(" kresp failed ", v) + log.Error("", "KeepAlive kresp failed", schema, etcdAddr, myHost, myPort, serviceName, ttl) } } } diff --git a/pkg/grpc-etcdv3/getcdv3/resolver.go b/pkg/grpc-etcdv3/getcdv3/resolver.go index aa41f86c4..45f47a717 100644 --- a/pkg/grpc-etcdv3/getcdv3/resolver.go +++ b/pkg/grpc-etcdv3/getcdv3/resolver.go @@ -1,6 +1,7 @@ package getcdv3 import ( + "Open_IM/pkg/common/log" "context" "fmt" "go.etcd.io/etcd/clientv3" @@ -102,7 +103,7 @@ func (r *Resolver) Build(target resolver.Target, cc resolver.ClientConn, opts re if err == nil { var addrList []resolver.Address for i := range resp.Kvs { - fmt.Println("init addr: ", string(resp.Kvs[i].Value)) + log.Debug("", "init addr: ", string(resp.Kvs[i].Value)) addrList = append(addrList, resolver.Address{Addr: string(resp.Kvs[i].Value)}) } r.cc.UpdateState(resolver.State{Addresses: addrList}) @@ -148,27 +149,27 @@ func (r *Resolver) watch(prefix string, addrList []resolver.Address) { if !exists(addrList, string(ev.Kv.Value)) { flag = 1 addrList = append(addrList, resolver.Address{Addr: string(ev.Kv.Value)}) - fmt.Println("after add, new list: ", addrList) + log.Debug("", "after add, new list: ", addrList) } case mvccpb.DELETE: - fmt.Println("remove addr key: ", string(ev.Kv.Key), "value:", string(ev.Kv.Value)) + log.Debug("remove addr key: ", string(ev.Kv.Key), "value:", string(ev.Kv.Value)) i := strings.LastIndexAny(string(ev.Kv.Key), "/") if i < 0 { return } t := string(ev.Kv.Key)[i+1:] - fmt.Println("remove addr key: ", string(ev.Kv.Key), "value:", string(ev.Kv.Value), "addr:", t) + log.Debug("remove addr key: ", string(ev.Kv.Key), "value:", string(ev.Kv.Value), "addr:", t) if s, ok := remove(addrList, t); ok { flag = 1 addrList = s - fmt.Println("after remove, new list: ", addrList) + log.Debug("after remove, new list: ", addrList) } } } if flag == 1 { r.cc.UpdateState(resolver.State{Addresses: addrList}) - fmt.Println("update: ", addrList) + log.Debug("update: ", addrList) } } } @@ -176,7 +177,7 @@ func (r *Resolver) watch(prefix string, addrList []resolver.Address) { func GetConn4Unique(schema, etcdaddr, servicename string) []*grpc.ClientConn { gEtcdCli, err := clientv3.New(clientv3.Config{Endpoints: strings.Split(etcdaddr, ",")}) if err != nil { - fmt.Println("eeeeeeeeeeeee", err.Error()) + log.Error("clientv3.New failed", err.Error()) return nil } @@ -200,7 +201,7 @@ func GetConn4Unique(schema, etcdaddr, servicename string) []*grpc.ClientConn { } } else { gEtcdCli.Close() - fmt.Println("rrrrrrrrrrr", err.Error()) + log.Error("gEtcdCli.Get failed", err.Error()) return nil } gEtcdCli.Close() @@ -236,7 +237,7 @@ func GetConnPool(schema, etcdaddr, servicename string) (*ClientConn, error) { ctx, _ := context.WithDeadline(context.Background(), time.Now().Add(1000*time.Millisecond)) c, err := p.Get(ctx) - fmt.Println(err) + log.Info("", "Get ", err) return c, err } From b30da3eea4191d5a61d3546608e0810e55c82943 Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Mon, 28 Feb 2022 17:03:29 +0800 Subject: [PATCH 11/67] database judge modify --- internal/push/logic/init.go | 2 +- pkg/common/db/mysql_model/im_mysql_model/friend_model.go | 2 +- .../db/mysql_model/im_mysql_model/friend_request_model.go | 2 +- pkg/common/db/mysql_model/im_mysql_model/user_model.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/push/logic/init.go b/internal/push/logic/init.go index 253aea2b2..02d96fda4 100644 --- a/internal/push/logic/init.go +++ b/internal/push/logic/init.go @@ -31,7 +31,7 @@ func Init(rpcPort int) { } func init() { producer = kafka.NewKafkaProducer(config.Config.Kafka.Ws2mschat.Addr, config.Config.Kafka.Ws2mschat.Topic) - statistics.NewStatistics(&count, config.Config.ModuleName.PushName, fmt.Sprintf("%d second push to msg_gateway count", count), 10) + statistics.NewStatistics(&count, config.Config.ModuleName.PushName, fmt.Sprintf("%d second push to msg_gateway count", 10), 10) } func Run() { diff --git a/pkg/common/db/mysql_model/im_mysql_model/friend_model.go b/pkg/common/db/mysql_model/im_mysql_model/friend_model.go index 45650357b..700082353 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/friend_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/friend_model.go @@ -26,7 +26,7 @@ func GetFriendRelationshipFromFriend(OwnerUserID, FriendUserID string) (*db.Frie return nil, err } var friend db.Friend - err = dbConn.Table("friends").Where("owner_user_id=? and friend_user_id=?", OwnerUserID, FriendUserID).Find(&friend).Error + err = dbConn.Table("friends").Where("owner_user_id=? and friend_user_id=?", OwnerUserID, FriendUserID).Take(&friend).Error if err != nil { return nil, err } diff --git a/pkg/common/db/mysql_model/im_mysql_model/friend_request_model.go b/pkg/common/db/mysql_model/im_mysql_model/friend_request_model.go index 609be8687..171a6aedf 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/friend_request_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/friend_request_model.go @@ -53,7 +53,7 @@ func GetFriendApplicationByBothUserID(FromUserID, ToUserID string) (*db.FriendRe return nil, err } var friendRequest db.FriendRequest - err = dbConn.Table("friend_requests").Where("from_user_id=? and to_user_id=?", FromUserID, ToUserID).Find(&friendRequest).Error + err = dbConn.Table("friend_requests").Where("from_user_id=? and to_user_id=?", FromUserID, ToUserID).Take(&friendRequest).Error if err != nil { return nil, err } diff --git a/pkg/common/db/mysql_model/im_mysql_model/user_model.go b/pkg/common/db/mysql_model/im_mysql_model/user_model.go index de5045855..618e0727d 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/user_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/user_model.go @@ -78,7 +78,7 @@ func GetUserByUserID(userID string) (*db.User, error) { return nil, err } var user db.User - err = dbConn.Table("users").Where("user_id=?", userID).First(&user).Error + err = dbConn.Table("users").Where("user_id=?", userID).Take(&user).Error if err != nil { return nil, err } From ed65ad842f3d201ea968b367e5bf58454b16f277 Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Mon, 28 Feb 2022 17:20:40 +0800 Subject: [PATCH 12/67] Replace find with take --- .../im_mysql_model/group_member_model.go | 7 +++++-- .../mysql_model/im_mysql_model/group_model.go | 19 ++++++++----------- .../im_mysql_model/group_request_model.go | 3 +-- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/pkg/common/db/mysql_model/im_mysql_model/group_member_model.go b/pkg/common/db/mysql_model/im_mysql_model/group_member_model.go index 4dafa30a6..63f12c115 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/group_member_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/group_member_model.go @@ -4,6 +4,7 @@ import ( "Open_IM/pkg/common/constant" "Open_IM/pkg/common/db" "Open_IM/pkg/utils" + "errors" "fmt" "time" ) @@ -43,6 +44,7 @@ func GetGroupMemberListByUserID(userID string) ([]db.GroupMember, error) { } var groupMemberList []db.GroupMember err = dbConn.Table("group_members").Where("user_id=?", userID).Find(&groupMemberList).Error + //err = dbConn.Table("group_members").Where("user_id=?", userID).Take(&groupMemberList).Error if err != nil { return nil, err } @@ -82,7 +84,7 @@ func GetGroupMemberInfoByGroupIDAndUserID(groupID, userID string) (*db.GroupMemb return nil, err } var groupMember db.GroupMember - err = dbConn.Table("group_members").Where("group_id=? and user_id=? ", groupID, userID).Limit(1).Find(&groupMember).Error + err = dbConn.Table("group_members").Where("group_id=? and user_id=? ", groupID, userID).Limit(1).Take(&groupMember).Error if err != nil { return nil, err } @@ -149,7 +151,8 @@ func GetGroupOwnerInfoByGroupID(groupID string) (*db.GroupMember, error) { return &v, nil } } - return nil, nil + + return nil, utils.Wrap(errors.New("no owner"), "") } func IsExistGroupMember(groupID, userID string) bool { diff --git a/pkg/common/db/mysql_model/im_mysql_model/group_model.go b/pkg/common/db/mysql_model/im_mysql_model/group_model.go index a9fe13236..587e3672e 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/group_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/group_model.go @@ -45,7 +45,7 @@ func GetGroupInfoByGroupID(groupId string) (*db.Group, error) { return nil, utils.Wrap(err, "") } var groupInfo db.Group - err = dbConn.Table("groups").Where("group_id=?", groupId).Find(&groupInfo).Error + err = dbConn.Table("groups").Where("group_id=?", groupId).Take(&groupInfo).Error if err != nil { return nil, err } @@ -86,11 +86,10 @@ func GetGroups(pageNumber, showNumber int) ([]db.Group, error) { return groups, nil } - func OperateGroupStatus(groupId string, groupStatus int32) error { group := db.Group{ GroupID: groupId, - Status: groupStatus, + Status: groupStatus, } if err := SetGroupInfo(group); err != nil { return err @@ -98,7 +97,6 @@ func OperateGroupStatus(groupId string, groupStatus int32) error { return nil } - func DeleteGroup(groupId string) error { dbConn, err := db.DB.MysqlDB.DefaultGormDB() if err != nil { @@ -129,15 +127,14 @@ func OperateGroupRole(userId, groupId string, roleLevel int32) (string, string, updateInfo := db.GroupMember{ RoleLevel: roleLevel, } - groupMaster := db.GroupMember{ - } + groupMaster := db.GroupMember{} switch roleLevel { case constant.GroupOwner: err = dbConn.Transaction(func(tx *gorm.DB) error { result := dbConn.Table("group_members").Where("group_id = ? and role_level = ?", groupId, constant.GroupOwner).First(&groupMaster).Update(&db.GroupMember{ RoleLevel: constant.GroupOrdinaryUsers, }) - if result.Error != nil { + if result.Error != nil { return result.Error } if result.RowsAffected == 0 { @@ -145,7 +142,7 @@ func OperateGroupRole(userId, groupId string, roleLevel int32) (string, string, } result = dbConn.Table("group_members").First(&groupMember).Update(updateInfo) - if result.Error != nil { + if result.Error != nil { return result.Error } if result.RowsAffected == 0 { @@ -161,7 +158,7 @@ func OperateGroupRole(userId, groupId string, roleLevel int32) (string, string, return result.Error } if result.RowsAffected == 0 { - return errors.New(fmt.Sprintf("user %s not exist in group %s or already operate", userId, groupId)) + return errors.New(fmt.Sprintf("user %s not exist in group %s or already operate", userId, groupId)) } if groupMaster.UserID == userId { return errors.New(fmt.Sprintf("user %s is master of %s, cant set to ordinary user", userId, groupId)) @@ -171,7 +168,7 @@ func OperateGroupRole(userId, groupId string, roleLevel int32) (string, string, return result.Error } if result.RowsAffected == 0 { - return errors.New(fmt.Sprintf("user %s not exist in group %s or already operate", userId, groupId)) + return errors.New(fmt.Sprintf("user %s not exist in group %s or already operate", userId, groupId)) } } return nil @@ -219,4 +216,4 @@ func GetGroupMaster(groupId string) (db.GroupMember, error) { return groupMember, err } return groupMember, nil -} \ No newline at end of file +} diff --git a/pkg/common/db/mysql_model/im_mysql_model/group_request_model.go b/pkg/common/db/mysql_model/im_mysql_model/group_request_model.go index 745ad0034..836f3f0bf 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/group_request_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/group_request_model.go @@ -63,7 +63,7 @@ func GetGroupRequestByGroupIDAndUserID(groupID, userID string) (*db.GroupRequest return nil, err } var groupRequest db.GroupRequest - err = dbConn.Table("group_requests").Where("user_id=? and group_id=?", userID, groupID).Find(&groupRequest).Error + err = dbConn.Table("group_requests").Where("user_id=? and group_id=?", userID, groupID).Take(&groupRequest).Error if err != nil { return nil, err } @@ -128,7 +128,6 @@ func GetUserReqGroupByUserID(userID string) ([]db.GroupRequest, error) { return groupRequestList, err } - // //func GroupApplicationResponse(pb *group.GroupApplicationResponseReq) (*group.CommonResp, error) { // From 04f8a7247d51273b17a9e9350ba4c29d22a5eac3 Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Mon, 28 Feb 2022 17:28:00 +0800 Subject: [PATCH 13/67] replace find with take --- .../db/mysql_model/im_mysql_model/user_model.go | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/pkg/common/db/mysql_model/im_mysql_model/user_model.go b/pkg/common/db/mysql_model/im_mysql_model/user_model.go index 618e0727d..7492d6a38 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/user_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/user_model.go @@ -51,18 +51,6 @@ func UserRegister(user db.User) error { return nil } -type User struct { - UserID string `gorm:"column:user_id;primaryKey;"` - Nickname string `gorm:"column:name"` - FaceUrl string `gorm:"column:icon"` - Gender int32 `gorm:"column:gender"` - PhoneNumber string `gorm:"column:phone_number"` - Birth string `gorm:"column:birth"` - Email string `gorm:"column:email"` - Ex string `gorm:"column:ex"` - CreateTime time.Time `gorm:"column:create_time"` -} - func DeleteUser(userID string) (i int64) { dbConn, err := db.DB.MysqlDB.DefaultGormDB() if err != nil { From 67d7ee275194820f2231bff819264501d9597ec2 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Mon, 28 Feb 2022 17:47:53 +0800 Subject: [PATCH 14/67] fix bug --- internal/api/third/minio_init.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/api/third/minio_init.go b/internal/api/third/minio_init.go index 4f54996ba..5aae5d4e8 100644 --- a/internal/api/third/minio_init.go +++ b/internal/api/third/minio_init.go @@ -34,7 +34,7 @@ func init() { if err == nil && exists { log.NewInfo("", utils.GetSelfFuncName(), "We already own %s\n", config.Config.Credential.Minio.Bucket) } else { - log.NewError("", utils.GetSelfFuncName(), "create bucket failed and bucket not exists", err.Error()) + log.NewError("", utils.GetSelfFuncName(), "create bucket failed and bucket not exists") return } } From f01a6e82dca2d40ae236d6812fb83f5a59d438ee Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Mon, 28 Feb 2022 17:52:13 +0800 Subject: [PATCH 15/67] fix minio bug --- internal/api/third/minio_init.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/api/third/minio_init.go b/internal/api/third/minio_init.go index 5aae5d4e8..d073524f3 100644 --- a/internal/api/third/minio_init.go +++ b/internal/api/third/minio_init.go @@ -30,10 +30,14 @@ func init() { } err = minioClient.MakeBucket(context.Background(), config.Config.Credential.Minio.Bucket, opt) if err != nil { + log.NewInfo("", utils.GetSelfFuncName(), err.Error()) exists, err := minioClient.BucketExists(context.Background(), config.Config.Credential.Minio.Bucket) if err == nil && exists { log.NewInfo("", utils.GetSelfFuncName(), "We already own %s\n", config.Config.Credential.Minio.Bucket) } else { + if err != nil { + log.NewError("", utils.GetSelfFuncName(), err.Error()) + } log.NewError("", utils.GetSelfFuncName(), "create bucket failed and bucket not exists") return } From 0bed7ee669da994060c7219b765138d191656205 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Mon, 28 Feb 2022 17:57:03 +0800 Subject: [PATCH 16/67] merge code --- config/config.yaml | 38 ++++++-- .../api/third/minio_storage_credential.go | 18 ++-- internal/demo/register/reset_password.go | 4 +- internal/rpc/auth/callback.go | 1 + internal/rpc/friend/callback.go | 1 + internal/rpc/group/callback.go | 9 ++ internal/rpc/group/group.go | 9 +- internal/rpc/msg/callback.go | 94 +++++++++++++++++++ internal/rpc/msg/send_msg.go | 50 ++++++---- internal/rpc/user/callback.go | 1 + internal/utils/callback.go | 1 + pkg/call_back_struct/common.go | 16 ++++ pkg/call_back_struct/group.go | 9 ++ pkg/call_back_struct/message.go | 60 ++++++++++++ pkg/common/config/config.go | 20 +++- pkg/common/constant/constant.go | 10 ++ pkg/common/constant/error.go | 2 + pkg/common/http/http_client.go | 10 ++ pkg/common/log/logrus.go | 15 ++- pkg/proto/sdk_ws/ws.proto | 30 ++++++ 20 files changed, 341 insertions(+), 57 deletions(-) create mode 100644 internal/rpc/auth/callback.go create mode 100644 internal/rpc/friend/callback.go create mode 100644 internal/rpc/group/callback.go create mode 100644 internal/rpc/msg/callback.go create mode 100644 internal/rpc/user/callback.go create mode 100644 internal/utils/callback.go create mode 100644 pkg/call_back_struct/group.go diff --git a/config/config.yaml b/config/config.yaml index 7d025c863..da3264de7 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -8,7 +8,7 @@ etcd: etcdAddr: [ 127.0.0.1:2379 ] #单机部署时,默认即可 mysql: - dbMysqlAddress: [ 127.0.0.1:13306 ] #mysql地址 目前仅支持单机,默认即可 + dbMysqlAddress: [ 43.128.5.63:13306 ] #mysql地址 目前仅支持单机,默认即可 dbMysqlUserName: root #mysql用户名,建议修改 dbMysqlPassword: openIM # mysql密码,建议修改 dbMysqlDatabaseName: openIM_v2 #默认即可 @@ -19,7 +19,7 @@ mysql: dbMaxLifeTime: 120 mongo: - dbAddress: [ 127.0.0.1:37017 ] #redis地址 目前仅支持单机,默认即可 + dbAddress: [ 43.128.5.63:37017 ] #redis地址 目前仅支持单机,默认即可 dbDirect: false dbTimeout: 10 dbDatabase: openIM #mongo db 默认即可 @@ -30,7 +30,7 @@ mongo: dbRetainChatRecords: 3650 #mongo保存离线消息时间(天),根据需求修改 redis: - dbAddress: 127.0.0.1:16379 #redis地址 目前仅支持单机,默认即可 + dbAddress: 43.128.5.63:16379 #redis地址 目前仅支持单机,默认即可 dbMaxIdle: 128 dbMaxActive: 0 dbIdleTimeout: 120 @@ -178,13 +178,6 @@ tokenpolicy: # Token effective time day as a unit accessExpire: 3650 #token过期时间(天) 默认即可 -messagecallback: - callbackSwitch: false - callbackUrl: "http://www.xxx.com/msg/judge" - #TimeOut use second as unit - callbackTimeOut: 10 -messagejudge: - isJudgeFriend: true # c2c: # callbackBeforeSendMsg: # switch: false @@ -199,6 +192,31 @@ iospush: pushSound: "xxx" badgeCount: true +callback: + callbackUrl : "http://xxx.com" + # 开启关闭操作前后回调的配置 + callbackbeforeSendSingleMsg: + enable: true # 回调是否启用 + callbackTimeOut: 5 # 回调超时时间 + CallbackFailedContinue: true # 回调超时是否继续执行代码 + callbackAfterSendSingleMsg: + enable: true + callbackTimeOut: 5 + CallbackFailedContinue: true + callbackBeforeSendGroupMsg: + enable: true + callbackTimeOut: 5 + CallbackFailedContinue: true + callbackAfterSendGroupMsg: + enable: true + callbackTimeOut: 5 + CallbackFailedContinue: true + callbackWordFilter: + enable: true + callbackTimeOut: 5 + CallbackFailedContinue: true + + notification: groupCreated: conversation: diff --git a/internal/api/third/minio_storage_credential.go b/internal/api/third/minio_storage_credential.go index 4d5800e06..f34f64c94 100644 --- a/internal/api/third/minio_storage_credential.go +++ b/internal/api/third/minio_storage_credential.go @@ -5,6 +5,7 @@ import ( "Open_IM/pkg/common/config" "Open_IM/pkg/common/constant" "Open_IM/pkg/common/log" + "Open_IM/pkg/common/token_verify" _ "Open_IM/pkg/common/token_verify" "Open_IM/pkg/utils" "github.com/gin-gonic/gin" @@ -23,12 +24,12 @@ func MinioStorageCredential(c *gin.Context) { c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()}) return } - //ok, _ := token_verify.GetUserIDFromToken(c.Request.Header.Get("token")) - //if !ok { - // log.NewError("", utils.GetSelfFuncName(), "GetUserIDFromToken false ", c.Request.Header.Get("token")) - // c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"}) - // return - //} + ok, _ := token_verify.GetUserIDFromToken(c.Request.Header.Get("token")) + if !ok { + log.NewError("", utils.GetSelfFuncName(), "GetUserIDFromToken false ", c.Request.Header.Get("token")) + c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"}) + return + } var stsOpts cr.STSAssumeRoleOptions stsOpts.AccessKey = config.Config.Credential.Minio.AccessKeyID stsOpts.SecretKey = config.Config.Credential.Minio.SecretAccessKey @@ -45,11 +46,6 @@ func MinioStorageCredential(c *gin.Context) { c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()}) return } - if err != nil { - log.NewError("0", utils.GetSelfFuncName(), err.Error()) - c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()}) - return - } resp.SessionToken = v.SessionToken resp.SecretAccessKey = v.SecretAccessKey resp.AccessKeyID = v.AccessKeyID diff --git a/internal/demo/register/reset_password.go b/internal/demo/register/reset_password.go index 0ff7115a0..b668f4f62 100644 --- a/internal/demo/register/reset_password.go +++ b/internal/demo/register/reset_password.go @@ -12,10 +12,10 @@ import ( ) type resetPasswordRequest struct { - VerificationCode string `json:"verificationCode"` + VerificationCode string `json:"verificationCode" binding:"required"` Email string `json:"email"` PhoneNumber string `json:"phoneNumber"` - NewPassword string `json:"newPassword"` + NewPassword string `json:"newPassword" binding:"required"` OperationID string `json:"operationID"` } diff --git a/internal/rpc/auth/callback.go b/internal/rpc/auth/callback.go new file mode 100644 index 000000000..8832b06d1 --- /dev/null +++ b/internal/rpc/auth/callback.go @@ -0,0 +1 @@ +package auth diff --git a/internal/rpc/friend/callback.go b/internal/rpc/friend/callback.go new file mode 100644 index 000000000..cf8ea69c8 --- /dev/null +++ b/internal/rpc/friend/callback.go @@ -0,0 +1 @@ +package friend diff --git a/internal/rpc/group/callback.go b/internal/rpc/group/callback.go new file mode 100644 index 000000000..8e0fcfb7b --- /dev/null +++ b/internal/rpc/group/callback.go @@ -0,0 +1,9 @@ +package group + +import ( + pbGroup "Open_IM/pkg/proto/group" +) + +func callbackBeforeCreateGroup(req *pbGroup.CreateGroupReq) (bool, error) { + return true, nil +} diff --git a/internal/rpc/group/group.go b/internal/rpc/group/group.go index 40255d071..7d4b85094 100644 --- a/internal/rpc/group/group.go +++ b/internal/rpc/group/group.go @@ -76,7 +76,12 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR log.NewError(req.OperationID, "CheckAccess false ", req.OpUserID, req.OwnerUserID) return &pbGroup.CreateGroupResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil } - + canCreate, err := callbackBeforeCreateGroup(req) + if err != nil || !canCreate { + if err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), "callbackBeforeCreateGroup failed", ) + } + } //Time stamp + MD5 to generate group chat id groupId := utils.Md5(strconv.FormatInt(time.Now().UnixNano(), 10)) //to group @@ -84,7 +89,7 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR utils.CopyStructFields(&groupInfo, req.GroupInfo) groupInfo.CreatorUserID = req.OpUserID groupInfo.GroupID = groupId - err := imdb.InsertIntoGroup(groupInfo) + err = imdb.InsertIntoGroup(groupInfo) if err != nil { log.NewError(req.OperationID, "InsertIntoGroup failed, ", err.Error(), groupInfo) return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, http.WrapError(constant.ErrDB) diff --git a/internal/rpc/msg/callback.go b/internal/rpc/msg/callback.go new file mode 100644 index 000000000..d55d9046e --- /dev/null +++ b/internal/rpc/msg/callback.go @@ -0,0 +1,94 @@ +package msg + +import ( + cbApi "Open_IM/pkg/call_back_struct" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/constant" + "Open_IM/pkg/common/http" + "Open_IM/pkg/common/log" + pbChat "Open_IM/pkg/proto/chat" + "Open_IM/pkg/utils" +) + +func callbackBeforeSendSingleMsg(msg *pbChat.SendMsgReq) (canSend bool, err error) { + log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg) + if !config.Config.Callback.CallbackbeforeSendSingleMsg.Enable || msg.MsgData.ContentType != constant.Text { + return true, nil + } + req := cbApi.CallbackBeforeSendSingleMsgReq{CommonCallbackReq:cbApi.CommonCallbackReq{ + }} + resp := &cbApi.CallbackBeforeSendSingleMsgResp{CommonCallbackResp:cbApi.CommonCallbackResp{ + }} + utils.CopyStructFields(req, msg.MsgData) + if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackbeforeSendSingleMsg.CallbackTimeOut); err != nil && !config.Config.Callback.CallbackbeforeSendSingleMsg.CallbackFailedContinue{ + return false, err + } + if resp.ActionCode == constant.ActionForbidden { + return false, nil + } + return true, nil +} + + +func callbackAfterSendSingleMsg(msg *pbChat.SendMsgReq) error { + log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg) + if !config.Config.Callback.CallbackAfterSendSingleMsg.Enable || msg.MsgData.ContentType != constant.Text { + return nil + } + req := cbApi.CallbackAfterSendSingleMsgReq{CommonCallbackReq: cbApi.CommonCallbackReq{}} + resp := &cbApi.CallbackAfterSendSingleMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}} + utils.CopyStructFields(req, msg.MsgData) + if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackAfterSendSingleMsg.CallbackTimeOut); err != nil && config.Config.Callback.CallbackAfterSendSingleMsg.CallbackFailedContinue{ + return err + } + return nil +} + + +func callbackBeforeSendGroupMsg(msg *pbChat.SendMsgReq) (canSend bool, err error) { + log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg) + if !config.Config.Callback.CallbackBeforeSendGroupMsg.Enable || msg.MsgData.ContentType != constant.Text { + return true, nil + } + req := cbApi.CallbackBeforeSendSingleMsgReq{CommonCallbackReq: cbApi.CommonCallbackReq{}} + resp := &cbApi.CallbackBeforeSendGroupMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}} + utils.CopyStructFields(req, msg.MsgData) + if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackBeforeSendGroupMsg.CallbackTimeOut); err != nil && !config.Config.Callback.CallbackBeforeSendGroupMsg.CallbackFailedContinue{ + return false, nil + } + if resp.ActionCode == constant.ActionForbidden { + return false, nil + } + return true, nil +} + +func callbackAfterSendGroupMsg(msg *pbChat.SendMsgReq) error { + log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg) + if !config.Config.Callback.CallbackAfterSendGroupMsg.Enable || msg.MsgData.ContentType != constant.Text { + return nil + } + return nil +} + + +func callBackWordFilter(msg *pbChat.SendMsgReq) (canSend bool, err error) { + log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg) + if !config.Config.Callback.CallbackWordFilter.Enable || msg.MsgData.ContentType != constant.Text { + return true, nil + } + req := cbApi.CallBackWordFilterReq{ + CommonCallbackReq: cbApi.CommonCallbackReq{}, + } + resp := cbApi.CallBackWordFilterResp{CommonCallbackResp: cbApi.CommonCallbackResp{}} + utils.CopyStructFields(&req, msg.MsgData) + if err := http.PostReturn(msg.OperationID, req, &resp, config.Config.Callback.CallbackWordFilter.CallbackTimeOut); err != nil { + return false, err + } + msg.MsgData.Content = resp.Content + return true, nil +} + + + + + diff --git a/internal/rpc/msg/send_msg.go b/internal/rpc/msg/send_msg.go index a57a6e892..390f151f9 100644 --- a/internal/rpc/msg/send_msg.go +++ b/internal/rpc/msg/send_msg.go @@ -4,7 +4,6 @@ import ( "Open_IM/pkg/common/config" "Open_IM/pkg/common/constant" "Open_IM/pkg/common/db" - http2 "Open_IM/pkg/common/http" "Open_IM/pkg/common/log" "Open_IM/pkg/grpc-etcdv3/getcdv3" pbChat "Open_IM/pkg/proto/chat" @@ -12,11 +11,9 @@ import ( sdk_ws "Open_IM/pkg/proto/sdk_ws" "Open_IM/pkg/utils" "context" - "encoding/json" "github.com/garyburd/redigo/redis" "github.com/golang/protobuf/proto" "math/rand" - "net/http" "strconv" "strings" "time" @@ -127,25 +124,26 @@ func (rpc *rpcChat) SendMsg(_ context.Context, pb *pbChat.SendMsgReq) (*pbChat.S if !isHistory { mReq.IsOnlineOnly = true } - mResp := MsgCallBackResp{} - if config.Config.MessageCallBack.CallbackSwitch { - bMsg, err := http2.Post(config.Config.MessageCallBack.CallbackUrl, mReq, config.Config.MessageCallBack.CallBackTimeOut) - if err != nil { - log.ErrorByKv("callback to Business server err", pb.OperationID, "args", pb.String(), "err", err.Error()) - return returnMsg(&replay, pb, http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError), "", 0) - } else if err = json.Unmarshal(bMsg, &mResp); err != nil { - log.ErrorByKv("ws json Unmarshal err", pb.OperationID, "args", pb.String(), "err", err.Error()) - return returnMsg(&replay, pb, 200, err.Error(), "", 0) - } else { - if mResp.ErrCode != 0 { - return returnMsg(&replay, pb, mResp.ResponseErrCode, mResp.ErrMsg, "", 0) - } else { - pb.MsgData.Content = []byte(mResp.ResponseResult.ModifiedMsg) - } - } + + // callback + canSend, err := callBackWordFilter(pb) + if err != nil { + log.NewError(pb.OperationID, utils.GetSelfFuncName(), "CallbackBeforeSendMsg failed", err.Error(), pb.MsgData) + } + if !canSend { + log.NewDebug(pb.OperationID, utils.GetSelfFuncName(), "callback result", canSend, "end rpc and return") + return returnMsg(&replay, pb, 201, "callback result stop rpc and return", "", 0) } switch pb.MsgData.SessionType { case constant.SingleChatType: + canSend, err := callbackBeforeSendSingleMsg(pb) + if err != nil { + log.NewError(pb.OperationID, utils.GetSelfFuncName(), "CallBackAfterSendMsg failed", err.Error()) + } + if !canSend { + log.NewDebug(pb.OperationID, utils.GetSelfFuncName(), "callback result", canSend, "end rpc and return") + return returnMsg(&replay, pb, 201, "callback result stop rpc and return", "", 0) + } isSend := modifyMessageByUserMessageReceiveOpt(pb.MsgData.RecvID, pb.MsgData.SendID, constant.SingleChatType, pb) if isSend { msgToMQ.MsgData = pb.MsgData @@ -163,8 +161,19 @@ func (rpc *rpcChat) SendMsg(_ context.Context, pb *pbChat.SendMsgReq) (*pbChat.S return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0) } } + if err := callbackAfterSendSingleMsg(pb); err != nil { + log.NewError(pb.OperationID, utils.GetSelfFuncName(), "CallBackAfterSendMsg failed", err.Error()) + } return returnMsg(&replay, pb, 0, "", msgToMQ.MsgData.ServerMsgID, msgToMQ.MsgData.SendTime) case constant.GroupChatType: + canSend, err := callbackBeforeSendGroupMsg(pb) + if err != nil { + log.NewError(pb.OperationID, utils.GetSelfFuncName(), "CallBackAfterSendMsg failed", err.Error()) + } + if !canSend { + log.NewDebug(pb.OperationID, utils.GetSelfFuncName(), "callback result", canSend, "end rpc and return") + return returnMsg(&replay, pb, 201, "callback result stop rpc and return", "", 0) + } etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName) client := pbGroup.NewGroupClient(etcdConn) req := &pbGroup.GetGroupAllMemberReq{ @@ -230,6 +239,9 @@ func (rpc *rpcChat) SendMsg(_ context.Context, pb *pbChat.SendMsgReq) (*pbChat.S } } + if err := callbackAfterSendGroupMsg(pb); err != nil { + log.NewError(pb.OperationID, utils.GetSelfFuncName(), "CallBackAfterSendMsg failed", err.Error()) + } return returnMsg(&replay, pb, 0, "", msgToMQ.MsgData.ServerMsgID, msgToMQ.MsgData.SendTime) default: return returnMsg(&replay, pb, 203, "unkonwn sessionType", "", 0) diff --git a/internal/rpc/user/callback.go b/internal/rpc/user/callback.go new file mode 100644 index 000000000..a00006b65 --- /dev/null +++ b/internal/rpc/user/callback.go @@ -0,0 +1 @@ +package user diff --git a/internal/utils/callback.go b/internal/utils/callback.go new file mode 100644 index 000000000..d4b585bf7 --- /dev/null +++ b/internal/utils/callback.go @@ -0,0 +1 @@ +package utils diff --git a/pkg/call_back_struct/common.go b/pkg/call_back_struct/common.go index 90b77eda8..fa7e4d4d3 100644 --- a/pkg/call_back_struct/common.go +++ b/pkg/call_back_struct/common.go @@ -1 +1,17 @@ package call_back_struct + +type CommonCallbackReq struct { + CallbackCommand string `json:"callbackCommand"` + ServerMsgID string `json:"serverID"` + ClientID string `json:"clientID"` + OperationID string `json:"operationID"` +} + +type CommonCallbackResp struct { + ActionCode int `json:"actionCode"` + ErrCode int `json:"errCode"` + ErrMsg string `json:"errMsg"` + OperationID string `json:"operationID"` +} + + diff --git a/pkg/call_back_struct/group.go b/pkg/call_back_struct/group.go new file mode 100644 index 000000000..3681dddcc --- /dev/null +++ b/pkg/call_back_struct/group.go @@ -0,0 +1,9 @@ +package call_back_struct + +type CallbackBeforeCreateGroupReq struct { + CommonCallbackReq +} + +type CallbackAfterCreateGroupResp struct { + CommonCallbackResp +} \ No newline at end of file diff --git a/pkg/call_back_struct/message.go b/pkg/call_back_struct/message.go index 90b77eda8..26473182e 100644 --- a/pkg/call_back_struct/message.go +++ b/pkg/call_back_struct/message.go @@ -1 +1,61 @@ package call_back_struct + +type singleMsg struct { + SendID string `json:"sendID"` + RecvID string `json:"recvID"` + ClientMsgID string `json:"clientMsgID"` + ServerMsgID string `json:"serverMsgId"` + SendTime int64 `json:"sendTime"` + CreateTime int64 `json:"createTime"` +} + +type CallbackBeforeSendSingleMsgReq struct { + CommonCallbackReq + singleMsg +} + +type CallbackBeforeSendSingleMsgResp struct { + CommonCallbackResp +} + +type CallbackAfterSendSingleMsgReq struct { + CommonCallbackReq + singleMsg +} + +type CallbackAfterSendSingleMsgResp struct { + CommonCallbackResp +} + +type groupMsg struct { + +} + +type CallbackBeforeSendGroupMsgReq struct { + CommonCallbackReq +} + +type CallbackBeforeSendGroupMsgResp struct { + CommonCallbackResp +} + +type CallbackAfterSendGroupMsgReq struct { + CommonCallbackReq +} + +type CallbackAfterSendGroupMsgResp struct { + CommonCallbackResp +} + +type CallBackWordFilterReq struct { + CommonCallbackReq + Content []byte `json:"content"` + SendID string `json:"SendID"` + RecvID string `json:"RecvID"` + GroupID string `json:"GroupID"` +} + +type CallBackWordFilterResp struct { + CommonCallbackResp + Content []byte `json:"content"` +} diff --git a/pkg/common/config/config.go b/pkg/common/config/config.go index ae0d3cadc..4782276e7 100644 --- a/pkg/common/config/config.go +++ b/pkg/common/config/config.go @@ -19,6 +19,12 @@ var ( var Config config +type callBackConfig struct { + Enable bool `yaml:"enable"` + CallbackTimeOut int `yaml:"callbackTimeOut"` + CallbackFailedContinue bool `CallbackFailedContinue` +} + type config struct { ServerIP string `yaml:"serverip"` ServerVersion string `yaml:"serverversion"` @@ -167,11 +173,6 @@ type config struct { AccessSecret string `yaml:"accessSecret"` AccessExpire int64 `yaml:"accessExpire"` } - MessageCallBack struct { - CallbackSwitch bool `yaml:"callbackSwitch"` - CallbackUrl string `yaml:"callbackUrl"` - CallBackTimeOut int `yaml:"callbackTimeOut"` - } MessageJudge struct { IsJudgeFriend bool `yaml:"isJudgeFriend"` } @@ -179,6 +180,15 @@ type config struct { PushSound string `yaml:"pushSound"` BadgeCount bool `yaml:"badgeCount"` } + + Callback struct { + CallbackUrl string `yaml:"callbackUrl"` + CallbackbeforeSendSingleMsg callBackConfig `yaml:"callbackSendGroupMsg"` + CallbackAfterSendSingleMsg callBackConfig `yaml:"callbackSendSingleMsg"` + CallbackBeforeSendGroupMsg callBackConfig `yaml:"CallbackBeforeSendGroupMsg"` + CallbackAfterSendGroupMsg callBackConfig `yaml:"callbackAfterSendGroupMsg"` + CallbackWordFilter callBackConfig `yaml:"callbackWordFilter"` + } `yaml:"callback"` Notification struct { ///////////////////////group///////////////////////////// GroupCreated struct { diff --git a/pkg/common/constant/constant.go b/pkg/common/constant/constant.go index c5e2d38b9..9d0c9724b 100644 --- a/pkg/common/constant/constant.go +++ b/pkg/common/constant/constant.go @@ -136,6 +136,16 @@ const ( VerificationCodeForReset = 2 VerificationCodeForRegisterSuffix = "_forRegister" VerificationCodeForResetSuffix = "_forReset" + + //callbackCommand + CallbackBeforeSendSingleMsgCommand = "callbackBeforeSendSingleMsg" + CallbackAfterSendSingleMsgCommand = "callbackAfterSendSingleMsg" + CallbackBeforeSendGroupMsgCommand = "callbackBeforeSendGroupMsg" + CallbackAfterSendGroupMsgCommand = "callbackAfterSendGroupMsgCommand" + CallbackWordFilterCommand = "callbackWordFilterCommand" + //actionCode + ActionAllow = 0 + ActionForbidden = 1 ) var ContentType2PushContent = map[int64]string{ diff --git a/pkg/common/constant/error.go b/pkg/common/constant/error.go index 339f2c953..548720a37 100644 --- a/pkg/common/constant/error.go +++ b/pkg/common/constant/error.go @@ -51,6 +51,7 @@ var ( ErrAccess = ErrInfo{ErrCode: 801, ErrMsg: AccessMsg.Error()} ErrDB = ErrInfo{ErrCode: 802, ErrMsg: DBMsg.Error()} ErrArgs = ErrInfo{ErrCode: 8003, ErrMsg: ArgsMsg.Error()} + ErrCallback = ErrInfo{ErrCode: 809, ErrMsg: CallBackMsg.Error()} ) var ( @@ -64,6 +65,7 @@ var ( AccessMsg = errors.New("no permission") DBMsg = errors.New("db failed") ArgsMsg = errors.New("args failed") + CallBackMsg = errors.New("callback failed") ThirdPartyMsg = errors.New("third party error") ) diff --git a/pkg/common/http/http_client.go b/pkg/common/http/http_client.go index 4d480770a..38d18c119 100644 --- a/pkg/common/http/http_client.go +++ b/pkg/common/http/http_client.go @@ -53,3 +53,13 @@ func Post(url string, data interface{}, timeOutSecond int) (content []byte, err } return result, nil } + +func PostReturn(url string, input, output interface{}, timeOut int) error { + b, err := Post(url, input, timeOut) + if err != nil { + return err + } + if err = json.Unmarshal(b, output); err != nil { + return err + } +} diff --git a/pkg/common/log/logrus.go b/pkg/common/log/logrus.go index a5e0ae7dd..63485e8d9 100644 --- a/pkg/common/log/logrus.go +++ b/pkg/common/log/logrus.go @@ -2,7 +2,6 @@ package log import ( "Open_IM/pkg/common/config" - "bufio" "fmt" "os" "time" @@ -33,13 +32,13 @@ func loggerInit(moduleName string) *Logger { //All logs will be printed logger.SetLevel(logrus.Level(config.Config.Log.RemainLogLevel)) //Close std console output - src, err := os.OpenFile(os.DevNull, os.O_APPEND|os.O_WRONLY, os.ModeAppend) - if err != nil { - panic(err.Error()) - } - writer := bufio.NewWriter(src) - logger.SetOutput(writer) - //logger.SetOutput(os.Stdout) + //src, err := os.OpenFile(os.DevNull, os.O_APPEND|os.O_WRONLY, os.ModeAppend) + //if err != nil { + // panic(err.Error()) + //} + //writer := bufio.NewWriter(src) + //logger.SetOutput(writer) + logger.SetOutput(os.Stdout) //Log Console Print Style Setting logger.SetFormatter(&nested.Formatter{ TimestampFormat: "2006-01-02 15:04:05.000", diff --git a/pkg/proto/sdk_ws/ws.proto b/pkg/proto/sdk_ws/ws.proto index 5d200cce6..cb622b96c 100644 --- a/pkg/proto/sdk_ws/ws.proto +++ b/pkg/proto/sdk_ws/ws.proto @@ -338,6 +338,36 @@ message ConversationUpdateTips{ } +///callback +message CommonCallbackURLReq { + string CallbackCommand = 1 [json_name = "code"]; + string OpenIMServerID = 2; + string OperationID = 3; +} + +message CommonCallbackURLResp { + string Code = 1 [json_name = "code"]; + string Msg = 2 [json_name = "msg"]; + string OperationID = 3 [json_name = "operationID"]; +} + +message CallbackBeforeSendMsgReq { + commonReq CommonCallbackURLReq = 1; + +} + +message CallbackBeforeSendMsgResp { + commonResp CommonCallbackURLResp = 1; + string FromUserID = 2; +} + +message CallbackAfterAddFriendReq { + commonReq CommonCallbackURLReq = 1; +} + +message CallbackAfterAddFriendResp { + commonResp CommonCallbackURLResp = 1; +} ///cms From 123aad2707b7117fcc4920e9d40b11f3fa20e296 Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Mon, 28 Feb 2022 19:10:32 +0800 Subject: [PATCH 17/67] statistics log --- pkg/statistics/statistics.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/statistics/statistics.go b/pkg/statistics/statistics.go index bda8ded85..23fd0e901 100644 --- a/pkg/statistics/statistics.go +++ b/pkg/statistics/statistics.go @@ -21,7 +21,7 @@ func (s *Statistics) output() { select { case <-t.C: } - log.NewWarn(s.ModuleName, s.PrintArgs, *s.Count-sum) + log.NewWarn(s.ModuleName, s.PrintArgs, *s.Count-sum, *s.Count) } } From 63625007416da72e2e65069006c4fe0c27faf1c6 Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Tue, 1 Mar 2022 15:14:56 +0800 Subject: [PATCH 18/67] Statistics --- pkg/statistics/statistics.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/statistics/statistics.go b/pkg/statistics/statistics.go index 23fd0e901..58d376986 100644 --- a/pkg/statistics/statistics.go +++ b/pkg/statistics/statistics.go @@ -21,7 +21,7 @@ func (s *Statistics) output() { select { case <-t.C: } - log.NewWarn(s.ModuleName, s.PrintArgs, *s.Count-sum, *s.Count) + log.NewWarn(s.ModuleName, s.PrintArgs, *s.Count-sum, "total:", *s.Count) } } From de7dae445564974583bbe586fef40e48d4d0feb9 Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Tue, 1 Mar 2022 15:17:43 +0800 Subject: [PATCH 19/67] statistics --- pkg/statistics/statistics.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/statistics/statistics.go b/pkg/statistics/statistics.go index 58d376986..26690b696 100644 --- a/pkg/statistics/statistics.go +++ b/pkg/statistics/statistics.go @@ -21,8 +21,7 @@ func (s *Statistics) output() { select { case <-t.C: } - log.NewWarn(s.ModuleName, s.PrintArgs, *s.Count-sum, "total:", *s.Count) - + log.NewWarn("", "system stat ", s.ModuleName, s.PrintArgs, *s.Count-sum, "total:", *s.Count) } } From c4ec54f6e440b95a09c47e8a804b5fcbc613fe9e Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Tue, 1 Mar 2022 15:22:02 +0800 Subject: [PATCH 20/67] Statistics --- pkg/statistics/statistics.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/statistics/statistics.go b/pkg/statistics/statistics.go index 26690b696..bea4479bd 100644 --- a/pkg/statistics/statistics.go +++ b/pkg/statistics/statistics.go @@ -21,7 +21,7 @@ func (s *Statistics) output() { select { case <-t.C: } - log.NewWarn("", "system stat ", s.ModuleName, s.PrintArgs, *s.Count-sum, "total:", *s.Count) + log.NewWarn("", " system stat ", s.ModuleName, s.PrintArgs, *s.Count-sum, "total:", *s.Count) } } From 58163cefa0970f8b2037df1f73601427bb7a3f64 Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Tue, 1 Mar 2022 15:32:47 +0800 Subject: [PATCH 21/67] set max open file num --- script/msg_gateway_start.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/script/msg_gateway_start.sh b/script/msg_gateway_start.sh index 1df53cfdd..978cc11fb 100644 --- a/script/msg_gateway_start.sh +++ b/script/msg_gateway_start.sh @@ -3,6 +3,8 @@ source ./style_info.cfg source ./path_info.cfg source ./function.sh +ulimit -n 200000 + list1=$(cat $config_path | grep openImOnlineRelayPort | awk -F '[:]' '{print $NF}') list2=$(cat $config_path | grep openImWsPort | awk -F '[:]' '{print $NF}') list_to_string $list1 From 0e9e02de0baf5d88b97b266344143264541185ef Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Tue, 1 Mar 2022 15:53:33 +0800 Subject: [PATCH 22/67] statistics code --- internal/api/third/minio_init.go | 2 +- internal/msg_gateway/gate/init.go | 14 ++++++++------ internal/msg_gateway/gate/logic.go | 2 +- internal/msg_gateway/gate/ws_server.go | 2 ++ 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/internal/api/third/minio_init.go b/internal/api/third/minio_init.go index d073524f3..9d5e404de 100644 --- a/internal/api/third/minio_init.go +++ b/internal/api/third/minio_init.go @@ -45,7 +45,7 @@ func init() { //err = minioClient.SetBucketPolicy(context.Background(), config.Config.Credential.Minio.Bucket, policy.BucketPolicyReadWrite) //if err != nil { // log.NewError("", utils.GetSelfFuncName(), "SetBucketPolicy failed please set in ", err.Error()) - // return + // return`z //} log.NewInfo("", utils.GetSelfFuncName(), "minio create and set policy success") } diff --git a/internal/msg_gateway/gate/init.go b/internal/msg_gateway/gate/init.go index 47d1dcedb..a98027561 100644 --- a/internal/msg_gateway/gate/init.go +++ b/internal/msg_gateway/gate/init.go @@ -10,11 +10,12 @@ import ( ) var ( - rwLock *sync.RWMutex - validate *validator.Validate - ws WServer - rpcSvr RPCServer - count uint64 + rwLock *sync.RWMutex + validate *validator.Validate + ws WServer + rpcSvr RPCServer + sendMsgCount uint64 + userCount uint64 ) func Init(rpcPort, wsPort int) { @@ -22,7 +23,8 @@ func Init(rpcPort, wsPort int) { log.NewPrivateLog(config.Config.ModuleName.LongConnSvrName) rwLock = new(sync.RWMutex) validate = validator.New() - statistics.NewStatistics(&count, config.Config.ModuleName.LongConnSvrName, fmt.Sprintf("%d second recv to msg_gateway count", count), 10) + statistics.NewStatistics(&sendMsgCount, config.Config.ModuleName.LongConnSvrName, fmt.Sprintf("%d second recv to msg_gateway sendMsgCount", sendMsgCount), 10) + statistics.NewStatistics(&userCount, config.Config.ModuleName.LongConnSvrName, fmt.Sprintf("%d second add user conn", userCount), 10) ws.onInit(wsPort) rpcSvr.onInit(rpcPort) } diff --git a/internal/msg_gateway/gate/logic.go b/internal/msg_gateway/gate/logic.go index 2aa19f609..df3b1a356 100644 --- a/internal/msg_gateway/gate/logic.go +++ b/internal/msg_gateway/gate/logic.go @@ -142,7 +142,7 @@ func (ws *WServer) pullMsgBySeqListResp(conn *UserConn, m *Req, pb *sdk_ws.PullM } func (ws *WServer) sendMsgReq(conn *UserConn, m *Req) { - count++ + sendMsgCount++ log.NewInfo(m.OperationID, "Ws call success to sendMsgReq start", m.MsgIncr, m.ReqIdentifier, m.SendID) nReply := new(pbChat.SendMsgResp) isPass, errCode, errMsg, pData := ws.argsValidate(m, constant.WSSendMsg) diff --git a/internal/msg_gateway/gate/ws_server.go b/internal/msg_gateway/gate/ws_server.go index 2197fbbc2..ba14561ef 100644 --- a/internal/msg_gateway/gate/ws_server.go +++ b/internal/msg_gateway/gate/ws_server.go @@ -184,6 +184,7 @@ func (ws *WServer) addUserConn(uid string, platformID int32, conn *UserConn, tok count = count + len(v) } log.WarnByKv("WS Add operation", "", "wsUser added", ws.wsUserToConn, "connection_uid", uid, "connection_platform", constant.PlatformIDToName(platformID), "online_user_num", len(ws.wsUserToConn), "online_conn_num", count) + userCount = uint64(len(ws.wsUserToConn)) } @@ -210,6 +211,7 @@ func (ws *WServer) delUserConn(conn *UserConn) { } else { log.WarnByKv("WS delete operation", "", "wsUser deleted", ws.wsUserToConn, "disconnection_uid", uid, "disconnection_platform", platform, "online_user_num", len(ws.wsUserToConn)) } + userCount = uint64(len(ws.wsUserToConn)) delete(ws.wsConnToUser, conn) } From 72ed38156af22fc51a06c395a3b20b697074e2fa Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Tue, 1 Mar 2022 17:48:53 +0800 Subject: [PATCH 23/67] test code --- internal/msg_gateway/gate/ws_server.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/internal/msg_gateway/gate/ws_server.go b/internal/msg_gateway/gate/ws_server.go index ba14561ef..0f751b58d 100644 --- a/internal/msg_gateway/gate/ws_server.go +++ b/internal/msg_gateway/gate/ws_server.go @@ -5,7 +5,6 @@ import ( "Open_IM/pkg/common/constant" "Open_IM/pkg/common/db" "Open_IM/pkg/common/log" - "Open_IM/pkg/common/token_verify" "Open_IM/pkg/utils" "bytes" "encoding/gob" @@ -258,16 +257,16 @@ func (ws *WServer) headerCheck(w http.ResponseWriter, r *http.Request) bool { status := http.StatusUnauthorized query := r.URL.Query() if len(query["token"]) != 0 && len(query["sendID"]) != 0 && len(query["platformID"]) != 0 { - if ok, err := token_verify.VerifyToken(query["token"][0], query["sendID"][0]); !ok { - e := err.(*constant.ErrInfo) - log.ErrorByKv("Token verify failed", "", "query", query) - w.Header().Set("Sec-Websocket-Version", "13") - http.Error(w, e.ErrMsg, int(e.ErrCode)) - return false - } else { - log.InfoByKv("Connection Authentication Success", "", "token", query["token"][0], "userID", query["sendID"][0]) - return true - } + //if ok, err := token_verify.VerifyToken(query["token"][0], query["sendID"][0]); !ok { + // e := err.(*constant.ErrInfo) + // log.ErrorByKv("Token verify failed", "", "query", query) + // w.Header().Set("Sec-Websocket-Version", "13") + // http.Error(w, e.ErrMsg, int(e.ErrCode)) + // return false + //} else { + log.InfoByKv("Connection Authentication Success", "", "token", query["token"][0], "userID", query["sendID"][0]) + return true + //} } else { log.ErrorByKv("Args err", "", "query", query) w.Header().Set("Sec-Websocket-Version", "13") From 84a01569d644cee9fe91b88f1ab79c9dd49fee71 Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Wed, 2 Mar 2022 09:45:12 +0800 Subject: [PATCH 24/67] limit mongo memory --- docker-compose.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docker-compose.yaml b/docker-compose.yaml index 5497faa43..154c61faa 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -24,6 +24,10 @@ services: - ./components/mongodb/data/db:/data/db - ./components/mongodb/data/logs:/data/logs - ./components/mongodb/data/conf:/etc/mongo + environment: + - TZ=Asia/Shanghai + # cache + - wiredTigerCacheSizeGB=1 # environment: # - MONGO_INITDB_ROOT_USERNAME=openIM # - MONGO_INITDB_ROOT_PASSWORD=openIM From dcfd802757f92c3ab3655dc2102d1e1a84c196e5 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Wed, 2 Mar 2022 19:07:17 +0800 Subject: [PATCH 25/67] callback add --- config/config.yaml | 6 ++-- internal/api/third/minio_init.go | 1 + internal/rpc/msg/callback.go | 48 ++++++++++++++++++--------- internal/rpc/msg/send_msg.go | 2 +- internal/rpc/statistics/statistics.go | 41 +++++++++++++++-------- pkg/call_back_struct/message.go | 24 +++++++++----- 6 files changed, 80 insertions(+), 42 deletions(-) diff --git a/config/config.yaml b/config/config.yaml index da3264de7..d8ff4060d 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -8,7 +8,7 @@ etcd: etcdAddr: [ 127.0.0.1:2379 ] #单机部署时,默认即可 mysql: - dbMysqlAddress: [ 43.128.5.63:13306 ] #mysql地址 目前仅支持单机,默认即可 + dbMysqlAddress: [ 127.0.0.1:13306 ] #mysql地址 目前仅支持单机,默认即可 dbMysqlUserName: root #mysql用户名,建议修改 dbMysqlPassword: openIM # mysql密码,建议修改 dbMysqlDatabaseName: openIM_v2 #默认即可 @@ -19,7 +19,7 @@ mysql: dbMaxLifeTime: 120 mongo: - dbAddress: [ 43.128.5.63:37017 ] #redis地址 目前仅支持单机,默认即可 + dbAddress: [ 127.0.0.1:37017 ] #redis地址 目前仅支持单机,默认即可 dbDirect: false dbTimeout: 10 dbDatabase: openIM #mongo db 默认即可 @@ -30,7 +30,7 @@ mongo: dbRetainChatRecords: 3650 #mongo保存离线消息时间(天),根据需求修改 redis: - dbAddress: 43.128.5.63:16379 #redis地址 目前仅支持单机,默认即可 + dbAddress: 127.0.0.1:16379 #redis地址 目前仅支持单机,默认即可 dbMaxIdle: 128 dbMaxActive: 0 dbIdleTimeout: 120 diff --git a/internal/api/third/minio_init.go b/internal/api/third/minio_init.go index d073524f3..bcec45402 100644 --- a/internal/api/third/minio_init.go +++ b/internal/api/third/minio_init.go @@ -42,6 +42,7 @@ func init() { return } } + // 自动化桶public的代码 //err = minioClient.SetBucketPolicy(context.Background(), config.Config.Credential.Minio.Bucket, policy.BucketPolicyReadWrite) //if err != nil { // log.NewError("", utils.GetSelfFuncName(), "SetBucketPolicy failed please set in ", err.Error()) diff --git a/internal/rpc/msg/callback.go b/internal/rpc/msg/callback.go index d55d9046e..19d8ca4f4 100644 --- a/internal/rpc/msg/callback.go +++ b/internal/rpc/msg/callback.go @@ -12,16 +12,19 @@ import ( func callbackBeforeSendSingleMsg(msg *pbChat.SendMsgReq) (canSend bool, err error) { log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg) - if !config.Config.Callback.CallbackbeforeSendSingleMsg.Enable || msg.MsgData.ContentType != constant.Text { + if !config.Config.Callback.CallbackbeforeSendSingleMsg.Enable { return true, nil } req := cbApi.CallbackBeforeSendSingleMsgReq{CommonCallbackReq:cbApi.CommonCallbackReq{ }} resp := &cbApi.CallbackBeforeSendSingleMsgResp{CommonCallbackResp:cbApi.CommonCallbackResp{ }} + defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, resp) utils.CopyStructFields(req, msg.MsgData) - if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackbeforeSendSingleMsg.CallbackTimeOut); err != nil && !config.Config.Callback.CallbackbeforeSendSingleMsg.CallbackFailedContinue{ - return false, err + if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackbeforeSendSingleMsg.CallbackTimeOut); err != nil{ + if !config.Config.Callback.CallbackbeforeSendSingleMsg.CallbackFailedContinue { + return false, err + } } if resp.ActionCode == constant.ActionForbidden { return false, nil @@ -32,13 +35,14 @@ func callbackBeforeSendSingleMsg(msg *pbChat.SendMsgReq) (canSend bool, err erro func callbackAfterSendSingleMsg(msg *pbChat.SendMsgReq) error { log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg) - if !config.Config.Callback.CallbackAfterSendSingleMsg.Enable || msg.MsgData.ContentType != constant.Text { + if !config.Config.Callback.CallbackAfterSendSingleMsg.Enable { return nil } req := cbApi.CallbackAfterSendSingleMsgReq{CommonCallbackReq: cbApi.CommonCallbackReq{}} resp := &cbApi.CallbackAfterSendSingleMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}} + defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, resp) utils.CopyStructFields(req, msg.MsgData) - if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackAfterSendSingleMsg.CallbackTimeOut); err != nil && config.Config.Callback.CallbackAfterSendSingleMsg.CallbackFailedContinue{ + if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackAfterSendSingleMsg.CallbackTimeOut); err != nil{ return err } return nil @@ -47,14 +51,17 @@ func callbackAfterSendSingleMsg(msg *pbChat.SendMsgReq) error { func callbackBeforeSendGroupMsg(msg *pbChat.SendMsgReq) (canSend bool, err error) { log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg) - if !config.Config.Callback.CallbackBeforeSendGroupMsg.Enable || msg.MsgData.ContentType != constant.Text { + if !config.Config.Callback.CallbackBeforeSendGroupMsg.Enable { return true, nil } req := cbApi.CallbackBeforeSendSingleMsgReq{CommonCallbackReq: cbApi.CommonCallbackReq{}} resp := &cbApi.CallbackBeforeSendGroupMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}} + defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, resp) utils.CopyStructFields(req, msg.MsgData) - if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackBeforeSendGroupMsg.CallbackTimeOut); err != nil && !config.Config.Callback.CallbackBeforeSendGroupMsg.CallbackFailedContinue{ - return false, nil + if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackBeforeSendGroupMsg.CallbackTimeOut); err != nil { + if !config.Config.Callback.CallbackBeforeSendGroupMsg.CallbackFailedContinue { + return false, nil + } } if resp.ActionCode == constant.ActionForbidden { return false, nil @@ -64,9 +71,16 @@ func callbackBeforeSendGroupMsg(msg *pbChat.SendMsgReq) (canSend bool, err error func callbackAfterSendGroupMsg(msg *pbChat.SendMsgReq) error { log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg) - if !config.Config.Callback.CallbackAfterSendGroupMsg.Enable || msg.MsgData.ContentType != constant.Text { + if !config.Config.Callback.CallbackAfterSendGroupMsg.Enable { return nil } + req := cbApi.CallbackAfterSendGroupMsgReq{CommonCallbackReq: cbApi.CommonCallbackReq{}} + resp := &cbApi.CallbackAfterSendGroupMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}} + defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, resp) + utils.CopyStructFields(req, msg.MsgData) + if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackAfterSendGroupMsg.CallbackTimeOut); err != nil { + return err + } return nil } @@ -76,13 +90,17 @@ func callBackWordFilter(msg *pbChat.SendMsgReq) (canSend bool, err error) { if !config.Config.Callback.CallbackWordFilter.Enable || msg.MsgData.ContentType != constant.Text { return true, nil } - req := cbApi.CallBackWordFilterReq{ - CommonCallbackReq: cbApi.CommonCallbackReq{}, - } - resp := cbApi.CallBackWordFilterResp{CommonCallbackResp: cbApi.CommonCallbackResp{}} + req := cbApi.CallbackWordFilterReq{CommonCallbackReq: cbApi.CommonCallbackReq{}} + resp := &cbApi.CallbackWordFilterResp{CommonCallbackResp: cbApi.CommonCallbackResp{}} + defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, resp) utils.CopyStructFields(&req, msg.MsgData) - if err := http.PostReturn(msg.OperationID, req, &resp, config.Config.Callback.CallbackWordFilter.CallbackTimeOut); err != nil { - return false, err + if err := http.PostReturn(msg.OperationID, req, resp, config.Config.Callback.CallbackWordFilter.CallbackTimeOut); err != nil { + if !config.Config.Callback.CallbackWordFilter.CallbackFailedContinue { + return false, err + } + } + if resp.ActionCode == constant.ActionForbidden { + return false, nil } msg.MsgData.Content = resp.Content return true, nil diff --git a/internal/rpc/msg/send_msg.go b/internal/rpc/msg/send_msg.go index 390f151f9..86a28d480 100644 --- a/internal/rpc/msg/send_msg.go +++ b/internal/rpc/msg/send_msg.go @@ -131,7 +131,7 @@ func (rpc *rpcChat) SendMsg(_ context.Context, pb *pbChat.SendMsgReq) (*pbChat.S log.NewError(pb.OperationID, utils.GetSelfFuncName(), "CallbackBeforeSendMsg failed", err.Error(), pb.MsgData) } if !canSend { - log.NewDebug(pb.OperationID, utils.GetSelfFuncName(), "callback result", canSend, "end rpc and return") + log.NewDebug(pb.OperationID, utils.GetSelfFuncName(), "callback result", canSend, "end rpc and return", pb.MsgData) return returnMsg(&replay, pb, 201, "callback result stop rpc and return", "", 0) } switch pb.MsgData.SessionType { diff --git a/internal/rpc/statistics/statistics.go b/internal/rpc/statistics/statistics.go index 9554bf116..e8b1383f9 100644 --- a/internal/rpc/statistics/statistics.go +++ b/internal/rpc/statistics/statistics.go @@ -164,28 +164,41 @@ func GetRangeDate(from, to time.Time) [][2]time.Time { } // month case !isInOneMonth(from, to): - for i := 0; ; i++ { - if i == 0 { - fromTime := from - toTime := getFirstDateOfNextNMonth(fromTime, 1) + if to.Sub(from) < time.Hour * 24 * 30 { + for i := 0; ; i++ { + fromTime := from.Add(time.Hour * 24 * time.Duration(i)) + toTime := from.Add(time.Hour * 24 * time.Duration(i+1)) + if toTime.After(to.Add(time.Hour * 24)) { + break + } times = append(times, [2]time.Time{ fromTime, toTime, }) - } else { - fromTime := getFirstDateOfNextNMonth(from, i) - toTime := getFirstDateOfNextNMonth(fromTime, 1) - if toTime.After(to) { - toTime = to + } + } else { + for i := 0; ; i++ { + if i == 0 { + fromTime := from + toTime := getFirstDateOfNextNMonth(fromTime, 1) + times = append(times, [2]time.Time{ + fromTime, toTime, + }) + } else { + fromTime := getFirstDateOfNextNMonth(from, i) + toTime := getFirstDateOfNextNMonth(fromTime, 1) + if toTime.After(to) { + toTime = to + times = append(times, [2]time.Time{ + fromTime, toTime, + }) + break + } times = append(times, [2]time.Time{ fromTime, toTime, }) - break } - times = append(times, [2]time.Time{ - fromTime, toTime, - }) - } + } } } return times diff --git a/pkg/call_back_struct/message.go b/pkg/call_back_struct/message.go index 26473182e..253c2561e 100644 --- a/pkg/call_back_struct/message.go +++ b/pkg/call_back_struct/message.go @@ -1,12 +1,16 @@ package call_back_struct -type singleMsg struct { +type msg struct { SendID string `json:"sendID"` - RecvID string `json:"recvID"` ClientMsgID string `json:"clientMsgID"` ServerMsgID string `json:"serverMsgId"` - SendTime int64 `json:"sendTime"` CreateTime int64 `json:"createTime"` + Content []byte `json:"content"` +} + +type singleMsg struct { + msg + RecvID string `json:"recvID"` } type CallbackBeforeSendSingleMsgReq struct { @@ -16,6 +20,7 @@ type CallbackBeforeSendSingleMsgReq struct { type CallbackBeforeSendSingleMsgResp struct { CommonCallbackResp + singleMsg } type CallbackAfterSendSingleMsgReq struct { @@ -28,18 +33,22 @@ type CallbackAfterSendSingleMsgResp struct { } type groupMsg struct { - + msg + GroupID string `json:"groupID"` } type CallbackBeforeSendGroupMsgReq struct { CommonCallbackReq + groupMsg } type CallbackBeforeSendGroupMsgResp struct { CommonCallbackResp + groupMsg } type CallbackAfterSendGroupMsgReq struct { + groupMsg CommonCallbackReq } @@ -47,15 +56,12 @@ type CallbackAfterSendGroupMsgResp struct { CommonCallbackResp } -type CallBackWordFilterReq struct { +type CallbackWordFilterReq struct { CommonCallbackReq Content []byte `json:"content"` - SendID string `json:"SendID"` - RecvID string `json:"RecvID"` - GroupID string `json:"GroupID"` } -type CallBackWordFilterResp struct { +type CallbackWordFilterResp struct { CommonCallbackResp Content []byte `json:"content"` } From c0c08fe373344542aaf6f95e28b58cc6b7f713e2 Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Wed, 2 Mar 2022 20:59:54 +0800 Subject: [PATCH 26/67] adjust log --- internal/msg_gateway/gate/ws_server.go | 2 +- internal/push/logic/push_to_client.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/msg_gateway/gate/ws_server.go b/internal/msg_gateway/gate/ws_server.go index 0f751b58d..ff7e739c8 100644 --- a/internal/msg_gateway/gate/ws_server.go +++ b/internal/msg_gateway/gate/ws_server.go @@ -182,7 +182,7 @@ func (ws *WServer) addUserConn(uid string, platformID int32, conn *UserConn, tok for _, v := range ws.wsUserToConn { count = count + len(v) } - log.WarnByKv("WS Add operation", "", "wsUser added", ws.wsUserToConn, "connection_uid", uid, "connection_platform", constant.PlatformIDToName(platformID), "online_user_num", len(ws.wsUserToConn), "online_conn_num", count) + log.Debug("WS Add operation", "", "wsUser added", ws.wsUserToConn, "connection_uid", uid, "connection_platform", constant.PlatformIDToName(platformID), "online_user_num", len(ws.wsUserToConn), "online_conn_num", count) userCount = uint64(len(ws.wsUserToConn)) } diff --git a/internal/push/logic/push_to_client.go b/internal/push/logic/push_to_client.go index b6a624f91..11d090ac5 100644 --- a/internal/push/logic/push_to_client.go +++ b/internal/push/logic/push_to_client.go @@ -31,10 +31,10 @@ type AtContent struct { func MsgToUser(pushMsg *pbPush.PushMsgReq) { var wsResult []*pbRelay.SingleMsgToUser //isOfflinePush := utils.GetSwitchFromOptions(pushMsg.MsgData.Options, constant.IsOfflinePush) - log.InfoByKv("Get msg from msg_transfer And push msg", pushMsg.OperationID, "PushData", pushMsg.String()) + log.Debug("Get msg from msg_transfer And push msg", pushMsg.OperationID, "PushData", pushMsg.String()) grpcCons := getcdv3.GetConn4Unique(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOnlineMessageRelayName) //Online push message - log.InfoByKv("test", pushMsg.OperationID, "len grpc", len(grpcCons), "data", pushMsg.String()) + log.Debug("test", pushMsg.OperationID, "len grpc", len(grpcCons), "data", pushMsg.String()) for _, v := range grpcCons { msgClient := pbRelay.NewOnlineMessageRelayServiceClient(v) reply, err := msgClient.OnlinePushMsg(context.Background(), &pbRelay.OnlinePushMsgReq{OperationID: pushMsg.OperationID, MsgData: pushMsg.MsgData, PushToUserID: pushMsg.PushToUserID}) From e6b302abf9c51bccd121b563f09339a1a7f6f4f9 Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Wed, 2 Mar 2022 21:02:21 +0800 Subject: [PATCH 27/67] log --- pkg/common/http/http_client.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/common/http/http_client.go b/pkg/common/http/http_client.go index 38d18c119..e227da91e 100644 --- a/pkg/common/http/http_client.go +++ b/pkg/common/http/http_client.go @@ -62,4 +62,5 @@ func PostReturn(url string, input, output interface{}, timeOut int) error { if err = json.Unmarshal(b, output); err != nil { return err } + return nil } From 25f24801d6acb46c81364dd2c0a342af7f01dc92 Mon Sep 17 00:00:00 2001 From: FG <1432970085@qq.com> Date: Wed, 2 Mar 2022 22:52:39 +0800 Subject: [PATCH 28/67] log --- pkg/common/log/logrus.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pkg/common/log/logrus.go b/pkg/common/log/logrus.go index 63485e8d9..a5e0ae7dd 100644 --- a/pkg/common/log/logrus.go +++ b/pkg/common/log/logrus.go @@ -2,6 +2,7 @@ package log import ( "Open_IM/pkg/common/config" + "bufio" "fmt" "os" "time" @@ -32,13 +33,13 @@ func loggerInit(moduleName string) *Logger { //All logs will be printed logger.SetLevel(logrus.Level(config.Config.Log.RemainLogLevel)) //Close std console output - //src, err := os.OpenFile(os.DevNull, os.O_APPEND|os.O_WRONLY, os.ModeAppend) - //if err != nil { - // panic(err.Error()) - //} - //writer := bufio.NewWriter(src) - //logger.SetOutput(writer) - logger.SetOutput(os.Stdout) + src, err := os.OpenFile(os.DevNull, os.O_APPEND|os.O_WRONLY, os.ModeAppend) + if err != nil { + panic(err.Error()) + } + writer := bufio.NewWriter(src) + logger.SetOutput(writer) + //logger.SetOutput(os.Stdout) //Log Console Print Style Setting logger.SetFormatter(&nested.Formatter{ TimestampFormat: "2006-01-02 15:04:05.000", From d8a729c961f55a552d81c71de6d6bafb5c862810 Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Thu, 3 Mar 2022 10:53:44 +0800 Subject: [PATCH 29/67] config update --- config/config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config.yaml b/config/config.yaml index 7d025c863..9d1f7f71b 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -180,7 +180,7 @@ tokenpolicy: messagecallback: callbackSwitch: false - callbackUrl: "http://www.xxx.com/msg/judge" + callbackUrl: "http://www.uuu.com/msg/judge" #TimeOut use second as unit callbackTimeOut: 10 messagejudge: From 97ec9602f7e83b012e3026e8bcc9a65904fd1c3f Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Thu, 3 Mar 2022 12:11:38 +0800 Subject: [PATCH 30/67] callback note --- internal/rpc/msg/send_msg.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/rpc/msg/send_msg.go b/internal/rpc/msg/send_msg.go index 86a28d480..b4581456a 100644 --- a/internal/rpc/msg/send_msg.go +++ b/internal/rpc/msg/send_msg.go @@ -126,14 +126,14 @@ func (rpc *rpcChat) SendMsg(_ context.Context, pb *pbChat.SendMsgReq) (*pbChat.S } // callback - canSend, err := callBackWordFilter(pb) - if err != nil { - log.NewError(pb.OperationID, utils.GetSelfFuncName(), "CallbackBeforeSendMsg failed", err.Error(), pb.MsgData) - } - if !canSend { - log.NewDebug(pb.OperationID, utils.GetSelfFuncName(), "callback result", canSend, "end rpc and return", pb.MsgData) - return returnMsg(&replay, pb, 201, "callback result stop rpc and return", "", 0) - } + //canSend, err := callBackWordFilter(pb) + //if err != nil { + // log.NewError(pb.OperationID, utils.GetSelfFuncName(), "CallbackBeforeSendMsg failed", err.Error(), pb.MsgData) + //} + //if !canSend { + // log.NewDebug(pb.OperationID, utils.GetSelfFuncName(), "callback result", canSend, "end rpc and return", pb.MsgData) + // return returnMsg(&replay, pb, 201, "callback result stop rpc and return", "", 0) + //} switch pb.MsgData.SessionType { case constant.SingleChatType: canSend, err := callbackBeforeSendSingleMsg(pb) From f1c11ac1144cfd68c761a49beb0d8580eaa9f58b Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Thu, 3 Mar 2022 14:18:28 +0800 Subject: [PATCH 31/67] add callback --- config/config.yaml | 2 -- internal/rpc/msg/callback.go | 17 ++++++++++------- pkg/call_back_struct/message.go | 6 +++--- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/config/config.yaml b/config/config.yaml index d8ff4060d..ff98b2692 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -202,7 +202,6 @@ callback: callbackAfterSendSingleMsg: enable: true callbackTimeOut: 5 - CallbackFailedContinue: true callbackBeforeSendGroupMsg: enable: true callbackTimeOut: 5 @@ -210,7 +209,6 @@ callback: callbackAfterSendGroupMsg: enable: true callbackTimeOut: 5 - CallbackFailedContinue: true callbackWordFilter: enable: true callbackTimeOut: 5 diff --git a/internal/rpc/msg/callback.go b/internal/rpc/msg/callback.go index 19d8ca4f4..310a80f67 100644 --- a/internal/rpc/msg/callback.go +++ b/internal/rpc/msg/callback.go @@ -62,9 +62,10 @@ func callbackBeforeSendGroupMsg(msg *pbChat.SendMsgReq) (canSend bool, err error if !config.Config.Callback.CallbackBeforeSendGroupMsg.CallbackFailedContinue { return false, nil } - } - if resp.ActionCode == constant.ActionForbidden { - return false, nil + } else { + if resp.ActionCode == constant.ActionForbidden { + return false, nil + } } return true, nil } @@ -94,15 +95,17 @@ func callBackWordFilter(msg *pbChat.SendMsgReq) (canSend bool, err error) { resp := &cbApi.CallbackWordFilterResp{CommonCallbackResp: cbApi.CommonCallbackResp{}} defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, resp) utils.CopyStructFields(&req, msg.MsgData) + req.Content = string(msg.MsgData.Content) if err := http.PostReturn(msg.OperationID, req, resp, config.Config.Callback.CallbackWordFilter.CallbackTimeOut); err != nil { if !config.Config.Callback.CallbackWordFilter.CallbackFailedContinue { return false, err } + } else { + msg.MsgData.Content = []byte(resp.Content) + if resp.ActionCode == constant.ActionForbidden { + return false, nil + } } - if resp.ActionCode == constant.ActionForbidden { - return false, nil - } - msg.MsgData.Content = resp.Content return true, nil } diff --git a/pkg/call_back_struct/message.go b/pkg/call_back_struct/message.go index 253c2561e..97d31a09f 100644 --- a/pkg/call_back_struct/message.go +++ b/pkg/call_back_struct/message.go @@ -5,7 +5,7 @@ type msg struct { ClientMsgID string `json:"clientMsgID"` ServerMsgID string `json:"serverMsgId"` CreateTime int64 `json:"createTime"` - Content []byte `json:"content"` + Content string `json:"content"` } type singleMsg struct { @@ -58,10 +58,10 @@ type CallbackAfterSendGroupMsgResp struct { type CallbackWordFilterReq struct { CommonCallbackReq - Content []byte `json:"content"` + Content string `json:"content"` } type CallbackWordFilterResp struct { CommonCallbackResp - Content []byte `json:"content"` + Content string `json:"content"` } From d13a6b0c3683cc30620ee8756de8c979c6a4afda Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Thu, 3 Mar 2022 14:42:50 +0800 Subject: [PATCH 32/67] add callback --- config/config.yaml | 2 +- internal/rpc/msg/callback.go | 13 +++++++++---- internal/rpc/msg/send_msg.go | 16 ++++++++-------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/config/config.yaml b/config/config.yaml index ff98b2692..f7e966eb8 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -193,7 +193,7 @@ iospush: badgeCount: true callback: - callbackUrl : "http://xxx.com" + callbackUrl : "http://127.0.0.1:8070" # 开启关闭操作前后回调的配置 callbackbeforeSendSingleMsg: enable: true # 回调是否启用 diff --git a/internal/rpc/msg/callback.go b/internal/rpc/msg/callback.go index 310a80f67..6bdc29bb2 100644 --- a/internal/rpc/msg/callback.go +++ b/internal/rpc/msg/callback.go @@ -21,13 +21,15 @@ func callbackBeforeSendSingleMsg(msg *pbChat.SendMsgReq) (canSend bool, err erro }} defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, resp) utils.CopyStructFields(req, msg.MsgData) + req.Content = string(msg.MsgData.Content) if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackbeforeSendSingleMsg.CallbackTimeOut); err != nil{ if !config.Config.Callback.CallbackbeforeSendSingleMsg.CallbackFailedContinue { return false, err } - } - if resp.ActionCode == constant.ActionForbidden { - return false, nil + } else { + if resp.ActionCode == constant.ActionForbidden { + return false, nil + } } return true, nil } @@ -42,6 +44,7 @@ func callbackAfterSendSingleMsg(msg *pbChat.SendMsgReq) error { resp := &cbApi.CallbackAfterSendSingleMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}} defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, resp) utils.CopyStructFields(req, msg.MsgData) + req.Content = string(msg.MsgData.Content) if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackAfterSendSingleMsg.CallbackTimeOut); err != nil{ return err } @@ -58,6 +61,7 @@ func callbackBeforeSendGroupMsg(msg *pbChat.SendMsgReq) (canSend bool, err error resp := &cbApi.CallbackBeforeSendGroupMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}} defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, resp) utils.CopyStructFields(req, msg.MsgData) + req.Content = string(msg.MsgData.Content) if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackBeforeSendGroupMsg.CallbackTimeOut); err != nil { if !config.Config.Callback.CallbackBeforeSendGroupMsg.CallbackFailedContinue { return false, nil @@ -79,6 +83,7 @@ func callbackAfterSendGroupMsg(msg *pbChat.SendMsgReq) error { resp := &cbApi.CallbackAfterSendGroupMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}} defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, resp) utils.CopyStructFields(req, msg.MsgData) + req.Content = string(msg.MsgData.Content) if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackAfterSendGroupMsg.CallbackTimeOut); err != nil { return err } @@ -101,10 +106,10 @@ func callBackWordFilter(msg *pbChat.SendMsgReq) (canSend bool, err error) { return false, err } } else { - msg.MsgData.Content = []byte(resp.Content) if resp.ActionCode == constant.ActionForbidden { return false, nil } + msg.MsgData.Content = []byte(resp.Content) } return true, nil } diff --git a/internal/rpc/msg/send_msg.go b/internal/rpc/msg/send_msg.go index b4581456a..86a28d480 100644 --- a/internal/rpc/msg/send_msg.go +++ b/internal/rpc/msg/send_msg.go @@ -126,14 +126,14 @@ func (rpc *rpcChat) SendMsg(_ context.Context, pb *pbChat.SendMsgReq) (*pbChat.S } // callback - //canSend, err := callBackWordFilter(pb) - //if err != nil { - // log.NewError(pb.OperationID, utils.GetSelfFuncName(), "CallbackBeforeSendMsg failed", err.Error(), pb.MsgData) - //} - //if !canSend { - // log.NewDebug(pb.OperationID, utils.GetSelfFuncName(), "callback result", canSend, "end rpc and return", pb.MsgData) - // return returnMsg(&replay, pb, 201, "callback result stop rpc and return", "", 0) - //} + canSend, err := callBackWordFilter(pb) + if err != nil { + log.NewError(pb.OperationID, utils.GetSelfFuncName(), "CallbackBeforeSendMsg failed", err.Error(), pb.MsgData) + } + if !canSend { + log.NewDebug(pb.OperationID, utils.GetSelfFuncName(), "callback result", canSend, "end rpc and return", pb.MsgData) + return returnMsg(&replay, pb, 201, "callback result stop rpc and return", "", 0) + } switch pb.MsgData.SessionType { case constant.SingleChatType: canSend, err := callbackBeforeSendSingleMsg(pb) From 85dbf4f98f2325dff94226d1800072c8b030b7cd Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Thu, 3 Mar 2022 15:52:19 +0800 Subject: [PATCH 33/67] alter port --- config/config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config.yaml b/config/config.yaml index f7e966eb8..21435f5bd 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -193,7 +193,7 @@ iospush: badgeCount: true callback: - callbackUrl : "http://127.0.0.1:8070" + callbackUrl : "http://127.0.0.1:8080" # 开启关闭操作前后回调的配置 callbackbeforeSendSingleMsg: enable: true # 回调是否启用 From 2d55e2edd52191c564f1a16a730e8ca12cb13c67 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Thu, 3 Mar 2022 15:59:31 +0800 Subject: [PATCH 34/67] alter cfg --- config/config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config.yaml b/config/config.yaml index 21435f5bd..09b190a46 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -132,7 +132,7 @@ log: storageLocation: ../logs/ rotationTime: 24 remainRotationCount: 5 #日志数量 - remainLogLevel: 4 #日志级别 6表示全都打印,测试阶段建议设置为6 + remainLogLevel: 6 #日志级别 6表示全都打印,测试阶段建议设置为6 elasticSearchSwitch: false elasticSearchAddr: [ 127.0.0.1:9201 ] elasticSearchUser: "" From e2b5b7016c58d66619a9767856fbd769ad3e33af Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Thu, 3 Mar 2022 16:08:46 +0800 Subject: [PATCH 35/67] add debug log --- config/config.yaml | 8 ++++---- internal/rpc/msg/callback.go | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/config/config.yaml b/config/config.yaml index 09b190a46..4c31b0c7c 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -196,18 +196,18 @@ callback: callbackUrl : "http://127.0.0.1:8080" # 开启关闭操作前后回调的配置 callbackbeforeSendSingleMsg: - enable: true # 回调是否启用 + enable: false # 回调是否启用 callbackTimeOut: 5 # 回调超时时间 CallbackFailedContinue: true # 回调超时是否继续执行代码 callbackAfterSendSingleMsg: - enable: true + enable: false callbackTimeOut: 5 callbackBeforeSendGroupMsg: - enable: true + enable: false callbackTimeOut: 5 CallbackFailedContinue: true callbackAfterSendGroupMsg: - enable: true + enable: false callbackTimeOut: 5 callbackWordFilter: enable: true diff --git a/internal/rpc/msg/callback.go b/internal/rpc/msg/callback.go index 6bdc29bb2..5b2dc05d0 100644 --- a/internal/rpc/msg/callback.go +++ b/internal/rpc/msg/callback.go @@ -101,8 +101,9 @@ func callBackWordFilter(msg *pbChat.SendMsgReq) (canSend bool, err error) { defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, resp) utils.CopyStructFields(&req, msg.MsgData) req.Content = string(msg.MsgData.Content) - if err := http.PostReturn(msg.OperationID, req, resp, config.Config.Callback.CallbackWordFilter.CallbackTimeOut); err != nil { + if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackWordFilter.CallbackTimeOut); err != nil { if !config.Config.Callback.CallbackWordFilter.CallbackFailedContinue { + log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), "config disable, stop this operation") return false, err } } else { From 6cef26f893652754fe083231a4727a5a0d588dbf Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Thu, 3 Mar 2022 16:23:59 +0800 Subject: [PATCH 36/67] alter callback fg --- config/config.yaml | 2 +- internal/demo/register/login.go | 2 +- internal/demo/register/set_password.go | 2 +- internal/rpc/msg/callback.go | 10 +++++----- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/config/config.yaml b/config/config.yaml index 4c31b0c7c..578113f19 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -193,7 +193,7 @@ iospush: badgeCount: true callback: - callbackUrl : "http://127.0.0.1:8080" + callbackUrl : "http://127.0.0.1:8080/callback" # 开启关闭操作前后回调的配置 callbackbeforeSendSingleMsg: enable: false # 回调是否启用 diff --git a/internal/demo/register/login.go b/internal/demo/register/login.go index 3a477e12e..e6de926dc 100644 --- a/internal/demo/register/login.go +++ b/internal/demo/register/login.go @@ -53,7 +53,7 @@ func Login(c *gin.Context) { openIMGetUserToken.Secret = config.Config.Secret openIMGetUserToken.UserID = account openIMGetUserTokenResp := api.UserTokenResp{} - bMsg, err := http2.Post(url, openIMGetUserToken, config.Config.MessageCallBack.CallBackTimeOut) + bMsg, err := http2.Post(url, openIMGetUserToken, 2) if err != nil { log.NewError(params.OperationID, "request openIM get user token error", account, "err", err.Error()) c.JSON(http.StatusOK, gin.H{"errCode": constant.GetIMTokenErr, "errMsg": err.Error()}) diff --git a/internal/demo/register/set_password.go b/internal/demo/register/set_password.go index 3fb996a56..7540d9830 100644 --- a/internal/demo/register/set_password.go +++ b/internal/demo/register/set_password.go @@ -57,7 +57,7 @@ func SetPassword(c *gin.Context) { openIMRegisterReq.Nickname = account openIMRegisterReq.Secret = config.Config.Secret openIMRegisterResp := api.UserRegisterResp{} - bMsg, err := http2.Post(url, openIMRegisterReq, config.Config.MessageCallBack.CallBackTimeOut) + bMsg, err := http2.Post(url, openIMRegisterReq, 2) if err != nil { log.NewError(params.OperationID, "request openIM register error", account, "err", err.Error()) c.JSON(http.StatusOK, gin.H{"errCode": constant.RegisterFailed, "errMsg": err.Error()}) diff --git a/internal/rpc/msg/callback.go b/internal/rpc/msg/callback.go index 5b2dc05d0..3ba0dac08 100644 --- a/internal/rpc/msg/callback.go +++ b/internal/rpc/msg/callback.go @@ -11,10 +11,10 @@ import ( ) func callbackBeforeSendSingleMsg(msg *pbChat.SendMsgReq) (canSend bool, err error) { - log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg) if !config.Config.Callback.CallbackbeforeSendSingleMsg.Enable { return true, nil } + log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg) req := cbApi.CallbackBeforeSendSingleMsgReq{CommonCallbackReq:cbApi.CommonCallbackReq{ }} resp := &cbApi.CallbackBeforeSendSingleMsgResp{CommonCallbackResp:cbApi.CommonCallbackResp{ @@ -36,10 +36,10 @@ func callbackBeforeSendSingleMsg(msg *pbChat.SendMsgReq) (canSend bool, err erro func callbackAfterSendSingleMsg(msg *pbChat.SendMsgReq) error { - log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg) if !config.Config.Callback.CallbackAfterSendSingleMsg.Enable { return nil } + log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg) req := cbApi.CallbackAfterSendSingleMsgReq{CommonCallbackReq: cbApi.CommonCallbackReq{}} resp := &cbApi.CallbackAfterSendSingleMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}} defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, resp) @@ -53,10 +53,10 @@ func callbackAfterSendSingleMsg(msg *pbChat.SendMsgReq) error { func callbackBeforeSendGroupMsg(msg *pbChat.SendMsgReq) (canSend bool, err error) { - log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg) if !config.Config.Callback.CallbackBeforeSendGroupMsg.Enable { return true, nil } + log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg) req := cbApi.CallbackBeforeSendSingleMsgReq{CommonCallbackReq: cbApi.CommonCallbackReq{}} resp := &cbApi.CallbackBeforeSendGroupMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}} defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, resp) @@ -75,10 +75,10 @@ func callbackBeforeSendGroupMsg(msg *pbChat.SendMsgReq) (canSend bool, err error } func callbackAfterSendGroupMsg(msg *pbChat.SendMsgReq) error { - log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg) if !config.Config.Callback.CallbackAfterSendGroupMsg.Enable { return nil } + log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg) req := cbApi.CallbackAfterSendGroupMsgReq{CommonCallbackReq: cbApi.CommonCallbackReq{}} resp := &cbApi.CallbackAfterSendGroupMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}} defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, resp) @@ -92,10 +92,10 @@ func callbackAfterSendGroupMsg(msg *pbChat.SendMsgReq) error { func callBackWordFilter(msg *pbChat.SendMsgReq) (canSend bool, err error) { - log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg) if !config.Config.Callback.CallbackWordFilter.Enable || msg.MsgData.ContentType != constant.Text { return true, nil } + log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg) req := cbApi.CallbackWordFilterReq{CommonCallbackReq: cbApi.CommonCallbackReq{}} resp := &cbApi.CallbackWordFilterResp{CommonCallbackResp: cbApi.CommonCallbackResp{}} defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, resp) From 9cec4b0c8ebb45ee8dd8f1c2d3a45422e63e9141 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Thu, 3 Mar 2022 16:41:17 +0800 Subject: [PATCH 37/67] alter callback fg --- internal/rpc/msg/callback.go | 25 +++++++++++++------------ pkg/common/constant/constant.go | 3 +++ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/internal/rpc/msg/callback.go b/internal/rpc/msg/callback.go index 3ba0dac08..0c42b01b3 100644 --- a/internal/rpc/msg/callback.go +++ b/internal/rpc/msg/callback.go @@ -16,10 +16,11 @@ func callbackBeforeSendSingleMsg(msg *pbChat.SendMsgReq) (canSend bool, err erro } log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg) req := cbApi.CallbackBeforeSendSingleMsgReq{CommonCallbackReq:cbApi.CommonCallbackReq{ + CallbackCommand: constant.CallbackBeforeSendSingleMsgCommand, }} resp := &cbApi.CallbackBeforeSendSingleMsgResp{CommonCallbackResp:cbApi.CommonCallbackResp{ }} - defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, resp) + defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp) utils.CopyStructFields(req, msg.MsgData) req.Content = string(msg.MsgData.Content) if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackbeforeSendSingleMsg.CallbackTimeOut); err != nil{ @@ -27,7 +28,7 @@ func callbackBeforeSendSingleMsg(msg *pbChat.SendMsgReq) (canSend bool, err erro return false, err } } else { - if resp.ActionCode == constant.ActionForbidden { + if resp.ActionCode == constant.ActionForbidden && resp.ErrCode == constant.CallbackHandleSuccess { return false, nil } } @@ -40,9 +41,9 @@ func callbackAfterSendSingleMsg(msg *pbChat.SendMsgReq) error { return nil } log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg) - req := cbApi.CallbackAfterSendSingleMsgReq{CommonCallbackReq: cbApi.CommonCallbackReq{}} + req := cbApi.CallbackAfterSendSingleMsgReq{CommonCallbackReq: cbApi.CommonCallbackReq{CallbackCommand:constant.CallbackAfterSendSingleMsgCommand}} resp := &cbApi.CallbackAfterSendSingleMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}} - defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, resp) + defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp) utils.CopyStructFields(req, msg.MsgData) req.Content = string(msg.MsgData.Content) if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackAfterSendSingleMsg.CallbackTimeOut); err != nil{ @@ -57,9 +58,9 @@ func callbackBeforeSendGroupMsg(msg *pbChat.SendMsgReq) (canSend bool, err error return true, nil } log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg) - req := cbApi.CallbackBeforeSendSingleMsgReq{CommonCallbackReq: cbApi.CommonCallbackReq{}} + req := cbApi.CallbackBeforeSendSingleMsgReq{CommonCallbackReq: cbApi.CommonCallbackReq{CallbackCommand:constant.CallbackBeforeSendGroupMsgCommand}} resp := &cbApi.CallbackBeforeSendGroupMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}} - defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, resp) + defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp) utils.CopyStructFields(req, msg.MsgData) req.Content = string(msg.MsgData.Content) if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackBeforeSendGroupMsg.CallbackTimeOut); err != nil { @@ -67,7 +68,7 @@ func callbackBeforeSendGroupMsg(msg *pbChat.SendMsgReq) (canSend bool, err error return false, nil } } else { - if resp.ActionCode == constant.ActionForbidden { + if resp.ActionCode == constant.ActionForbidden && resp.ErrCode == constant.CallbackHandleSuccess { return false, nil } } @@ -79,9 +80,9 @@ func callbackAfterSendGroupMsg(msg *pbChat.SendMsgReq) error { return nil } log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg) - req := cbApi.CallbackAfterSendGroupMsgReq{CommonCallbackReq: cbApi.CommonCallbackReq{}} + req := cbApi.CallbackAfterSendGroupMsgReq{CommonCallbackReq: cbApi.CommonCallbackReq{CallbackCommand:constant.CallbackAfterSendGroupMsgCommand}} resp := &cbApi.CallbackAfterSendGroupMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}} - defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, resp) + defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp) utils.CopyStructFields(req, msg.MsgData) req.Content = string(msg.MsgData.Content) if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackAfterSendGroupMsg.CallbackTimeOut); err != nil { @@ -96,9 +97,9 @@ func callBackWordFilter(msg *pbChat.SendMsgReq) (canSend bool, err error) { return true, nil } log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg) - req := cbApi.CallbackWordFilterReq{CommonCallbackReq: cbApi.CommonCallbackReq{}} + req := cbApi.CallbackWordFilterReq{CommonCallbackReq: cbApi.CommonCallbackReq{CallbackCommand:constant.CallbackWordFilterCommand}} resp := &cbApi.CallbackWordFilterResp{CommonCallbackResp: cbApi.CommonCallbackResp{}} - defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, resp) + defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp) utils.CopyStructFields(&req, msg.MsgData) req.Content = string(msg.MsgData.Content) if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackWordFilter.CallbackTimeOut); err != nil { @@ -107,7 +108,7 @@ func callBackWordFilter(msg *pbChat.SendMsgReq) (canSend bool, err error) { return false, err } } else { - if resp.ActionCode == constant.ActionForbidden { + if resp.ActionCode == constant.ActionForbidden && resp.ErrCode == constant.CallbackHandleSuccess { return false, nil } msg.MsgData.Content = []byte(resp.Content) diff --git a/pkg/common/constant/constant.go b/pkg/common/constant/constant.go index 9d0c9724b..fa8646d5e 100644 --- a/pkg/common/constant/constant.go +++ b/pkg/common/constant/constant.go @@ -146,6 +146,9 @@ const ( //actionCode ActionAllow = 0 ActionForbidden = 1 + //callbackHandleCode + CallbackHandleSuccess = 0 + CallbackHandleFailed = 1 ) var ContentType2PushContent = map[int64]string{ From fb4c02ca9bb6f428c0bf9bc2cfc211ce1fecf447 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Thu, 3 Mar 2022 16:47:03 +0800 Subject: [PATCH 38/67] alter callback fg --- internal/rpc/msg/callback.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/rpc/msg/callback.go b/internal/rpc/msg/callback.go index 0c42b01b3..0c80adeaa 100644 --- a/internal/rpc/msg/callback.go +++ b/internal/rpc/msg/callback.go @@ -99,9 +99,9 @@ func callBackWordFilter(msg *pbChat.SendMsgReq) (canSend bool, err error) { log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg) req := cbApi.CallbackWordFilterReq{CommonCallbackReq: cbApi.CommonCallbackReq{CallbackCommand:constant.CallbackWordFilterCommand}} resp := &cbApi.CallbackWordFilterResp{CommonCallbackResp: cbApi.CommonCallbackResp{}} - defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp) utils.CopyStructFields(&req, msg.MsgData) req.Content = string(msg.MsgData.Content) + defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp) if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackWordFilter.CallbackTimeOut); err != nil { if !config.Config.Callback.CallbackWordFilter.CallbackFailedContinue { log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), "config disable, stop this operation") @@ -112,6 +112,7 @@ func callBackWordFilter(msg *pbChat.SendMsgReq) (canSend bool, err error) { return false, nil } msg.MsgData.Content = []byte(resp.Content) + log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg.MsgData.Content) } return true, nil } From 3698f1dab88d98307f73d8600583b11b0612e68e Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Thu, 3 Mar 2022 16:50:06 +0800 Subject: [PATCH 39/67] alter callback fg --- internal/rpc/msg/callback.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/rpc/msg/callback.go b/internal/rpc/msg/callback.go index 0c80adeaa..51478fee6 100644 --- a/internal/rpc/msg/callback.go +++ b/internal/rpc/msg/callback.go @@ -20,9 +20,9 @@ func callbackBeforeSendSingleMsg(msg *pbChat.SendMsgReq) (canSend bool, err erro }} resp := &cbApi.CallbackBeforeSendSingleMsgResp{CommonCallbackResp:cbApi.CommonCallbackResp{ }} - defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp) utils.CopyStructFields(req, msg.MsgData) req.Content = string(msg.MsgData.Content) + defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp) if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackbeforeSendSingleMsg.CallbackTimeOut); err != nil{ if !config.Config.Callback.CallbackbeforeSendSingleMsg.CallbackFailedContinue { return false, err @@ -43,9 +43,9 @@ func callbackAfterSendSingleMsg(msg *pbChat.SendMsgReq) error { log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg) req := cbApi.CallbackAfterSendSingleMsgReq{CommonCallbackReq: cbApi.CommonCallbackReq{CallbackCommand:constant.CallbackAfterSendSingleMsgCommand}} resp := &cbApi.CallbackAfterSendSingleMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}} - defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp) utils.CopyStructFields(req, msg.MsgData) req.Content = string(msg.MsgData.Content) + defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp) if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackAfterSendSingleMsg.CallbackTimeOut); err != nil{ return err } @@ -60,9 +60,9 @@ func callbackBeforeSendGroupMsg(msg *pbChat.SendMsgReq) (canSend bool, err error log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg) req := cbApi.CallbackBeforeSendSingleMsgReq{CommonCallbackReq: cbApi.CommonCallbackReq{CallbackCommand:constant.CallbackBeforeSendGroupMsgCommand}} resp := &cbApi.CallbackBeforeSendGroupMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}} - defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp) utils.CopyStructFields(req, msg.MsgData) req.Content = string(msg.MsgData.Content) + defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp) if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackBeforeSendGroupMsg.CallbackTimeOut); err != nil { if !config.Config.Callback.CallbackBeforeSendGroupMsg.CallbackFailedContinue { return false, nil @@ -82,9 +82,9 @@ func callbackAfterSendGroupMsg(msg *pbChat.SendMsgReq) error { log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg) req := cbApi.CallbackAfterSendGroupMsgReq{CommonCallbackReq: cbApi.CommonCallbackReq{CallbackCommand:constant.CallbackAfterSendGroupMsgCommand}} resp := &cbApi.CallbackAfterSendGroupMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}} - defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp) utils.CopyStructFields(req, msg.MsgData) req.Content = string(msg.MsgData.Content) + defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp) if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackAfterSendGroupMsg.CallbackTimeOut); err != nil { return err } @@ -112,7 +112,7 @@ func callBackWordFilter(msg *pbChat.SendMsgReq) (canSend bool, err error) { return false, nil } msg.MsgData.Content = []byte(resp.Content) - log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg.MsgData.Content) + log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), string(msg.MsgData.Content)) } return true, nil } From 2ed3fd3cba58d41bd183df31a1fe161488e80f0a Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Thu, 3 Mar 2022 17:53:37 +0800 Subject: [PATCH 40/67] alter callback fg --- internal/rpc/msg/callback.go | 36 ++++++++++++++++++++++++++++----- pkg/call_back_struct/common.go | 14 +++++++++---- pkg/call_back_struct/message.go | 24 ++++++++++------------ 3 files changed, 52 insertions(+), 22 deletions(-) diff --git a/internal/rpc/msg/callback.go b/internal/rpc/msg/callback.go index 51478fee6..f50552ad8 100644 --- a/internal/rpc/msg/callback.go +++ b/internal/rpc/msg/callback.go @@ -80,9 +80,24 @@ func callbackAfterSendGroupMsg(msg *pbChat.SendMsgReq) error { return nil } log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg) - req := cbApi.CallbackAfterSendGroupMsgReq{CommonCallbackReq: cbApi.CommonCallbackReq{CallbackCommand:constant.CallbackAfterSendGroupMsgCommand}} + req := cbApi.CallbackAfterSendGroupMsgReq{ + CommonCallbackReq: cbApi.CommonCallbackReq{ + CallbackCommand:constant.CallbackAfterSendGroupMsgCommand, + ServerMsgID: msg.MsgData.ServerMsgID, + ClientMsgID: msg.MsgData.ClientMsgID, + OperationID: msg.OperationID, + + }, + GroupMsg: cbApi.GroupMsg{ + Msg: cbApi.Msg{ + SendID: msg.MsgData. + }, + GroupID: msg.MsgData.GroupID, + } + } resp := &cbApi.CallbackAfterSendGroupMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}} - utils.CopyStructFields(req, msg.MsgData) + + //utils.CopyStructFields(req, msg.MsgData) req.Content = string(msg.MsgData.Content) defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp) if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackAfterSendGroupMsg.CallbackTimeOut); err != nil { @@ -97,10 +112,21 @@ func callBackWordFilter(msg *pbChat.SendMsgReq) (canSend bool, err error) { return true, nil } log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg) - req := cbApi.CallbackWordFilterReq{CommonCallbackReq: cbApi.CommonCallbackReq{CallbackCommand:constant.CallbackWordFilterCommand}} + //req := cbApi.CallbackWordFilterReq{ + // CommonCallbackReq: cbApi.CommonCallbackReq{ + // CallbackCommand: constant.CallbackWordFilterCommand, + // ServerMsgID: msg.MsgData.ServerMsgID, + // ClientMsgID: msg.MsgData.ClientMsgID, + // OperationID: msg.OperationID, + // }, + // Content: string(msg.MsgData.Content), + //} + req := cbApi.CallbackWordFilterReq{ + CommonCallbackReq: cbApi.CommonCallbackReq{}, + } + utils.CopyStructFields(req.CommonCallbackReq, msg.MsgData) resp := &cbApi.CallbackWordFilterResp{CommonCallbackResp: cbApi.CommonCallbackResp{}} - utils.CopyStructFields(&req, msg.MsgData) - req.Content = string(msg.MsgData.Content) + //utils.CopyStructFields(&req., msg.MsgData) defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp) if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackWordFilter.CallbackTimeOut); err != nil { if !config.Config.Callback.CallbackWordFilter.CallbackFailedContinue { diff --git a/pkg/call_back_struct/common.go b/pkg/call_back_struct/common.go index fa7e4d4d3..5266e0b26 100644 --- a/pkg/call_back_struct/common.go +++ b/pkg/call_back_struct/common.go @@ -1,10 +1,16 @@ package call_back_struct type CommonCallbackReq struct { - CallbackCommand string `json:"callbackCommand"` - ServerMsgID string `json:"serverID"` - ClientID string `json:"clientID"` - OperationID string `json:"operationID"` + CallbackCommand string `json:"callbackCommand"` + ServerMsgID string `json:"serverID"` + ClientMsgID string `json:"clientID"` + OperationID string `json:"operationID"` + SenderPlatformID int32 `json:"senderPlatformID"` + SenderNickname string `json:"senderNickname"` + SessionType int32 `json:"sessionType"` + MsgFrom int32 `json:"MsgFrom"` + ContentType int32 `json:"contentType"` + Status int32 `json:"status"` } type CommonCallbackResp struct { diff --git a/pkg/call_back_struct/message.go b/pkg/call_back_struct/message.go index 97d31a09f..13a67db4a 100644 --- a/pkg/call_back_struct/message.go +++ b/pkg/call_back_struct/message.go @@ -1,54 +1,52 @@ package call_back_struct -type msg struct { +type Msg struct { SendID string `json:"sendID"` - ClientMsgID string `json:"clientMsgID"` - ServerMsgID string `json:"serverMsgId"` CreateTime int64 `json:"createTime"` Content string `json:"content"` } -type singleMsg struct { - msg +type SingleMsg struct { + Msg RecvID string `json:"recvID"` } type CallbackBeforeSendSingleMsgReq struct { CommonCallbackReq - singleMsg + SingleMsg } type CallbackBeforeSendSingleMsgResp struct { CommonCallbackResp - singleMsg + SingleMsg } type CallbackAfterSendSingleMsgReq struct { CommonCallbackReq - singleMsg + SingleMsg } type CallbackAfterSendSingleMsgResp struct { CommonCallbackResp } -type groupMsg struct { - msg +type GroupMsg struct { + Msg GroupID string `json:"groupID"` } type CallbackBeforeSendGroupMsgReq struct { CommonCallbackReq - groupMsg + GroupMsg } type CallbackBeforeSendGroupMsgResp struct { CommonCallbackResp - groupMsg + GroupMsg } type CallbackAfterSendGroupMsgReq struct { - groupMsg + GroupMsg CommonCallbackReq } From 9f80e0a0e6634ab962dad96dce871e8db348e6f6 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Thu, 3 Mar 2022 17:54:31 +0800 Subject: [PATCH 41/67] alter callback fg --- internal/rpc/msg/callback.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/rpc/msg/callback.go b/internal/rpc/msg/callback.go index f50552ad8..c77400b95 100644 --- a/internal/rpc/msg/callback.go +++ b/internal/rpc/msg/callback.go @@ -88,12 +88,12 @@ func callbackAfterSendGroupMsg(msg *pbChat.SendMsgReq) error { OperationID: msg.OperationID, }, - GroupMsg: cbApi.GroupMsg{ - Msg: cbApi.Msg{ - SendID: msg.MsgData. - }, - GroupID: msg.MsgData.GroupID, - } + //GroupMsg: cbApi.GroupMsg{ + // Msg: cbApi.Msg{ + // SendID: msg.MsgData. + // }, + // GroupID: msg.MsgData.GroupID, + //} } resp := &cbApi.CallbackAfterSendGroupMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}} From 4d4520226deb489426a0c80439891b1142235ff4 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Thu, 3 Mar 2022 18:49:36 +0800 Subject: [PATCH 42/67] msg callback --- internal/rpc/msg/callback.go | 88 ++++++++++++++++++--------------- pkg/call_back_struct/common.go | 3 ++ pkg/call_back_struct/message.go | 26 ++-------- 3 files changed, 56 insertions(+), 61 deletions(-) diff --git a/internal/rpc/msg/callback.go b/internal/rpc/msg/callback.go index c77400b95..0fce99edc 100644 --- a/internal/rpc/msg/callback.go +++ b/internal/rpc/msg/callback.go @@ -10,18 +10,38 @@ import ( "Open_IM/pkg/utils" ) +func copyCallbackCommonReqStruct(msg *pbChat.SendMsgReq) cbApi.CommonCallbackReq { + return cbApi.CommonCallbackReq{ + SendID: msg.MsgData.SendID, + ServerMsgID: msg.MsgData.ServerMsgID, + ClientMsgID: msg.MsgData.ClientMsgID, + OperationID: msg.OperationID, + SenderPlatformID: msg.MsgData.SenderPlatformID, + SenderNickname: msg.MsgData.SenderNickname, + SessionType: msg.MsgData.SessionType, + MsgFrom: msg.MsgData.MsgFrom, + ContentType: msg.MsgData.ContentType, + Status: msg.MsgData.Status, + CreateTime: msg.MsgData.CreateTime, + Content: string(msg.MsgData.Content), + } +} + func callbackBeforeSendSingleMsg(msg *pbChat.SendMsgReq) (canSend bool, err error) { if !config.Config.Callback.CallbackbeforeSendSingleMsg.Enable { return true, nil } log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg) - req := cbApi.CallbackBeforeSendSingleMsgReq{CommonCallbackReq:cbApi.CommonCallbackReq{ - CallbackCommand: constant.CallbackBeforeSendSingleMsgCommand, - }} - resp := &cbApi.CallbackBeforeSendSingleMsgResp{CommonCallbackResp:cbApi.CommonCallbackResp{ - }} - utils.CopyStructFields(req, msg.MsgData) - req.Content = string(msg.MsgData.Content) + commonCallbackReq := copyCallbackCommonReqStruct(msg) + commonCallbackReq.CallbackCommand = constant.CallbackBeforeSendSingleMsgCommand + req := cbApi.CallbackBeforeSendSingleMsgReq{ + CommonCallbackReq: commonCallbackReq, + RecvID: msg.MsgData.RecvID, + } + resp := &cbApi.CallbackBeforeSendSingleMsgResp{ + CommonCallbackResp: cbApi.CommonCallbackResp{}, + } + //utils.CopyStructFields(req, msg.MsgData) defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp) if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackbeforeSendSingleMsg.CallbackTimeOut); err != nil{ if !config.Config.Callback.CallbackbeforeSendSingleMsg.CallbackFailedContinue { @@ -41,10 +61,14 @@ func callbackAfterSendSingleMsg(msg *pbChat.SendMsgReq) error { return nil } log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg) - req := cbApi.CallbackAfterSendSingleMsgReq{CommonCallbackReq: cbApi.CommonCallbackReq{CallbackCommand:constant.CallbackAfterSendSingleMsgCommand}} + commonCallbackReq := copyCallbackCommonReqStruct(msg) + commonCallbackReq.CallbackCommand = constant.CallbackAfterSendSingleMsgCommand + req := cbApi.CallbackAfterSendSingleMsgReq{ + CommonCallbackReq: commonCallbackReq, + RecvID: msg.MsgData.RecvID, + } resp := &cbApi.CallbackAfterSendSingleMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}} - utils.CopyStructFields(req, msg.MsgData) - req.Content = string(msg.MsgData.Content) + //utils.CopyStructFields(req, msg.MsgData) defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp) if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackAfterSendSingleMsg.CallbackTimeOut); err != nil{ return err @@ -58,10 +82,14 @@ func callbackBeforeSendGroupMsg(msg *pbChat.SendMsgReq) (canSend bool, err error return true, nil } log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg) - req := cbApi.CallbackBeforeSendSingleMsgReq{CommonCallbackReq: cbApi.CommonCallbackReq{CallbackCommand:constant.CallbackBeforeSendGroupMsgCommand}} + commonCallbackReq := copyCallbackCommonReqStruct(msg) + commonCallbackReq.CallbackCommand = constant.CallbackBeforeSendGroupMsgCommand + req := cbApi.CallbackBeforeSendSingleMsgReq{ + CommonCallbackReq: commonCallbackReq, + RecvID: msg.MsgData.RecvID, + } resp := &cbApi.CallbackBeforeSendGroupMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}} - utils.CopyStructFields(req, msg.MsgData) - req.Content = string(msg.MsgData.Content) + //utils.CopyStructFields(req, msg.MsgData) defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp) if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackBeforeSendGroupMsg.CallbackTimeOut); err != nil { if !config.Config.Callback.CallbackBeforeSendGroupMsg.CallbackFailedContinue { @@ -80,25 +108,15 @@ func callbackAfterSendGroupMsg(msg *pbChat.SendMsgReq) error { return nil } log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg) - req := cbApi.CallbackAfterSendGroupMsgReq{ - CommonCallbackReq: cbApi.CommonCallbackReq{ - CallbackCommand:constant.CallbackAfterSendGroupMsgCommand, - ServerMsgID: msg.MsgData.ServerMsgID, - ClientMsgID: msg.MsgData.ClientMsgID, - OperationID: msg.OperationID, - - }, - //GroupMsg: cbApi.GroupMsg{ - // Msg: cbApi.Msg{ - // SendID: msg.MsgData. - // }, - // GroupID: msg.MsgData.GroupID, - //} + commonCallbackReq := copyCallbackCommonReqStruct(msg) + commonCallbackReq.CallbackCommand = constant.CallbackBeforeSendGroupMsgCommand + req := cbApi.CallbackBeforeSendSingleMsgReq{ + CommonCallbackReq: commonCallbackReq, + RecvID: msg.MsgData.RecvID, } resp := &cbApi.CallbackAfterSendGroupMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}} //utils.CopyStructFields(req, msg.MsgData) - req.Content = string(msg.MsgData.Content) defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp) if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackAfterSendGroupMsg.CallbackTimeOut); err != nil { return err @@ -112,19 +130,11 @@ func callBackWordFilter(msg *pbChat.SendMsgReq) (canSend bool, err error) { return true, nil } log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg) - //req := cbApi.CallbackWordFilterReq{ - // CommonCallbackReq: cbApi.CommonCallbackReq{ - // CallbackCommand: constant.CallbackWordFilterCommand, - // ServerMsgID: msg.MsgData.ServerMsgID, - // ClientMsgID: msg.MsgData.ClientMsgID, - // OperationID: msg.OperationID, - // }, - // Content: string(msg.MsgData.Content), - //} + commonCallbackReq := copyCallbackCommonReqStruct(msg) + commonCallbackReq.CallbackCommand = constant.CallbackWordFilterCommand req := cbApi.CallbackWordFilterReq{ - CommonCallbackReq: cbApi.CommonCallbackReq{}, + CommonCallbackReq: commonCallbackReq, } - utils.CopyStructFields(req.CommonCallbackReq, msg.MsgData) resp := &cbApi.CallbackWordFilterResp{CommonCallbackResp: cbApi.CommonCallbackResp{}} //utils.CopyStructFields(&req., msg.MsgData) defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp) diff --git a/pkg/call_back_struct/common.go b/pkg/call_back_struct/common.go index 5266e0b26..5e33889fe 100644 --- a/pkg/call_back_struct/common.go +++ b/pkg/call_back_struct/common.go @@ -1,6 +1,7 @@ package call_back_struct type CommonCallbackReq struct { + SendID string `json:"sendID"` CallbackCommand string `json:"callbackCommand"` ServerMsgID string `json:"serverID"` ClientMsgID string `json:"clientID"` @@ -11,6 +12,8 @@ type CommonCallbackReq struct { MsgFrom int32 `json:"MsgFrom"` ContentType int32 `json:"contentType"` Status int32 `json:"status"` + CreateTime int64 `json:"createTime"` + Content string `json:"content"` } type CommonCallbackResp struct { diff --git a/pkg/call_back_struct/message.go b/pkg/call_back_struct/message.go index 13a67db4a..31c215ea2 100644 --- a/pkg/call_back_struct/message.go +++ b/pkg/call_back_struct/message.go @@ -1,53 +1,36 @@ package call_back_struct -type Msg struct { - SendID string `json:"sendID"` - CreateTime int64 `json:"createTime"` - Content string `json:"content"` -} - -type SingleMsg struct { - Msg - RecvID string `json:"recvID"` -} type CallbackBeforeSendSingleMsgReq struct { CommonCallbackReq - SingleMsg + RecvID string `json:"recvID"` } type CallbackBeforeSendSingleMsgResp struct { CommonCallbackResp - SingleMsg } type CallbackAfterSendSingleMsgReq struct { CommonCallbackReq - SingleMsg + RecvID string `json:"recvID"` } type CallbackAfterSendSingleMsgResp struct { CommonCallbackResp } -type GroupMsg struct { - Msg - GroupID string `json:"groupID"` -} - type CallbackBeforeSendGroupMsgReq struct { CommonCallbackReq - GroupMsg + GroupID string `json:"groupID"` } type CallbackBeforeSendGroupMsgResp struct { CommonCallbackResp - GroupMsg } type CallbackAfterSendGroupMsgReq struct { - GroupMsg CommonCallbackReq + GroupID string `json:"groupID"` } type CallbackAfterSendGroupMsgResp struct { @@ -56,7 +39,6 @@ type CallbackAfterSendGroupMsgResp struct { type CallbackWordFilterReq struct { CommonCallbackReq - Content string `json:"content"` } type CallbackWordFilterResp struct { From 7deffeffd8e00726af9614b16b814dc713c08d54 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Thu, 3 Mar 2022 19:06:00 +0800 Subject: [PATCH 43/67] msg callback --- config/config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config.yaml b/config/config.yaml index 578113f19..0259c23be 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -212,7 +212,7 @@ callback: callbackWordFilter: enable: true callbackTimeOut: 5 - CallbackFailedContinue: true + CallbackFailedContinue: false notification: From 02510528d125f93f0854d44abcd68cc99713d870 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Thu, 3 Mar 2022 19:09:59 +0800 Subject: [PATCH 44/67] msg callback --- config/config.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config/config.yaml b/config/config.yaml index 0259c23be..6e00a21f2 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -196,18 +196,18 @@ callback: callbackUrl : "http://127.0.0.1:8080/callback" # 开启关闭操作前后回调的配置 callbackbeforeSendSingleMsg: - enable: false # 回调是否启用 + enable: true # 回调是否启用 callbackTimeOut: 5 # 回调超时时间 CallbackFailedContinue: true # 回调超时是否继续执行代码 callbackAfterSendSingleMsg: - enable: false + enable: true callbackTimeOut: 5 callbackBeforeSendGroupMsg: - enable: false + enable: true callbackTimeOut: 5 CallbackFailedContinue: true callbackAfterSendGroupMsg: - enable: false + enable: true callbackTimeOut: 5 callbackWordFilter: enable: true From 88b8a5323acb33989817c0014b7e3ad47ff87013 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Thu, 3 Mar 2022 19:23:16 +0800 Subject: [PATCH 45/67] msg callback --- config/config.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/config/config.yaml b/config/config.yaml index 6e00a21f2..04d89d8fe 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -197,22 +197,22 @@ callback: # 开启关闭操作前后回调的配置 callbackbeforeSendSingleMsg: enable: true # 回调是否启用 - callbackTimeOut: 5 # 回调超时时间 + callbackTimeOut: 2 # 回调超时时间 CallbackFailedContinue: true # 回调超时是否继续执行代码 callbackAfterSendSingleMsg: enable: true - callbackTimeOut: 5 + callbackTimeOut: 2 callbackBeforeSendGroupMsg: enable: true - callbackTimeOut: 5 + callbackTimeOut: 2 CallbackFailedContinue: true callbackAfterSendGroupMsg: enable: true - callbackTimeOut: 5 + callbackTimeOut: 2 callbackWordFilter: enable: true - callbackTimeOut: 5 - CallbackFailedContinue: false + callbackTimeOut: 2 + CallbackFailedContinue: true notification: From 3805db1263caab0ee57695217310d6e1f934bc16 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Thu, 3 Mar 2022 19:39:49 +0800 Subject: [PATCH 46/67] msg callback --- internal/rpc/msg/callback.go | 13 +++++++++---- internal/rpc/msg/send_msg.go | 2 +- pkg/common/config/config.go | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/internal/rpc/msg/callback.go b/internal/rpc/msg/callback.go index 0fce99edc..54ff93786 100644 --- a/internal/rpc/msg/callback.go +++ b/internal/rpc/msg/callback.go @@ -28,7 +28,8 @@ func copyCallbackCommonReqStruct(msg *pbChat.SendMsgReq) cbApi.CommonCallbackReq } func callbackBeforeSendSingleMsg(msg *pbChat.SendMsgReq) (canSend bool, err error) { - if !config.Config.Callback.CallbackbeforeSendSingleMsg.Enable { + log.NewDebug(msg.OperationID, config.Config.Callback.CallbackBeforeSendSingleMsg.Enable) + if !config.Config.Callback.CallbackBeforeSendSingleMsg.Enable { return true, nil } log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg) @@ -43,8 +44,8 @@ func callbackBeforeSendSingleMsg(msg *pbChat.SendMsgReq) (canSend bool, err erro } //utils.CopyStructFields(req, msg.MsgData) defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp) - if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackbeforeSendSingleMsg.CallbackTimeOut); err != nil{ - if !config.Config.Callback.CallbackbeforeSendSingleMsg.CallbackFailedContinue { + if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackBeforeSendSingleMsg.CallbackTimeOut); err != nil{ + if !config.Config.Callback.CallbackBeforeSendSingleMsg.CallbackFailedContinue { return false, err } } else { @@ -57,6 +58,7 @@ func callbackBeforeSendSingleMsg(msg *pbChat.SendMsgReq) (canSend bool, err erro func callbackAfterSendSingleMsg(msg *pbChat.SendMsgReq) error { + log.NewDebug(msg.OperationID, config.Config.Callback.CallbackAfterSendSingleMsg.Enable) if !config.Config.Callback.CallbackAfterSendSingleMsg.Enable { return nil } @@ -78,6 +80,7 @@ func callbackAfterSendSingleMsg(msg *pbChat.SendMsgReq) error { func callbackBeforeSendGroupMsg(msg *pbChat.SendMsgReq) (canSend bool, err error) { + log.NewDebug(msg.OperationID, config.Config.Callback.CallbackBeforeSendGroupMsg.Enable) if !config.Config.Callback.CallbackBeforeSendGroupMsg.Enable { return true, nil } @@ -104,6 +107,7 @@ func callbackBeforeSendGroupMsg(msg *pbChat.SendMsgReq) (canSend bool, err error } func callbackAfterSendGroupMsg(msg *pbChat.SendMsgReq) error { + log.NewDebug(msg.OperationID, config.Config.Callback.CallbackAfterSendGroupMsg.Enable) if !config.Config.Callback.CallbackAfterSendGroupMsg.Enable { return nil } @@ -125,7 +129,8 @@ func callbackAfterSendGroupMsg(msg *pbChat.SendMsgReq) error { } -func callBackWordFilter(msg *pbChat.SendMsgReq) (canSend bool, err error) { +func callbackWordFilter(msg *pbChat.SendMsgReq) (canSend bool, err error) { + log.NewDebug(msg.OperationID, config.Config.Callback.CallbackWordFilter.Enable) if !config.Config.Callback.CallbackWordFilter.Enable || msg.MsgData.ContentType != constant.Text { return true, nil } diff --git a/internal/rpc/msg/send_msg.go b/internal/rpc/msg/send_msg.go index 86a28d480..16720575a 100644 --- a/internal/rpc/msg/send_msg.go +++ b/internal/rpc/msg/send_msg.go @@ -126,7 +126,7 @@ func (rpc *rpcChat) SendMsg(_ context.Context, pb *pbChat.SendMsgReq) (*pbChat.S } // callback - canSend, err := callBackWordFilter(pb) + canSend, err := callbackWordFilter(pb) if err != nil { log.NewError(pb.OperationID, utils.GetSelfFuncName(), "CallbackBeforeSendMsg failed", err.Error(), pb.MsgData) } diff --git a/pkg/common/config/config.go b/pkg/common/config/config.go index 4782276e7..c249b00ad 100644 --- a/pkg/common/config/config.go +++ b/pkg/common/config/config.go @@ -183,7 +183,7 @@ type config struct { Callback struct { CallbackUrl string `yaml:"callbackUrl"` - CallbackbeforeSendSingleMsg callBackConfig `yaml:"callbackSendGroupMsg"` + CallbackBeforeSendSingleMsg callBackConfig `yaml:"callbackSendGroupMsg"` CallbackAfterSendSingleMsg callBackConfig `yaml:"callbackSendSingleMsg"` CallbackBeforeSendGroupMsg callBackConfig `yaml:"CallbackBeforeSendGroupMsg"` CallbackAfterSendGroupMsg callBackConfig `yaml:"callbackAfterSendGroupMsg"` From a5712e1216bfbc42df25ec7f24efe1373613afb8 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Thu, 3 Mar 2022 19:44:34 +0800 Subject: [PATCH 47/67] msg callback --- pkg/common/config/config.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/common/config/config.go b/pkg/common/config/config.go index c249b00ad..282440672 100644 --- a/pkg/common/config/config.go +++ b/pkg/common/config/config.go @@ -183,9 +183,9 @@ type config struct { Callback struct { CallbackUrl string `yaml:"callbackUrl"` - CallbackBeforeSendSingleMsg callBackConfig `yaml:"callbackSendGroupMsg"` - CallbackAfterSendSingleMsg callBackConfig `yaml:"callbackSendSingleMsg"` - CallbackBeforeSendGroupMsg callBackConfig `yaml:"CallbackBeforeSendGroupMsg"` + CallbackBeforeSendSingleMsg callBackConfig `yaml:"callbackbeforeSendSingleMsg"` + CallbackAfterSendSingleMsg callBackConfig `yaml:"callbackAfterSendSingleMsg"` + CallbackBeforeSendGroupMsg callBackConfig `yaml:"callbackBeforeSendGroupMsg"` CallbackAfterSendGroupMsg callBackConfig `yaml:"callbackAfterSendGroupMsg"` CallbackWordFilter callBackConfig `yaml:"callbackWordFilter"` } `yaml:"callback"` From 399d0b94d5f2869fdf52681f18615523e5fb3e34 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Thu, 3 Mar 2022 19:47:30 +0800 Subject: [PATCH 48/67] msg callback --- config/config.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/config/config.yaml b/config/config.yaml index 04d89d8fe..4d3990194 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -196,21 +196,21 @@ callback: callbackUrl : "http://127.0.0.1:8080/callback" # 开启关闭操作前后回调的配置 callbackbeforeSendSingleMsg: - enable: true # 回调是否启用 + enable: false # 回调是否启用 callbackTimeOut: 2 # 回调超时时间 CallbackFailedContinue: true # 回调超时是否继续执行代码 callbackAfterSendSingleMsg: - enable: true + enable: false callbackTimeOut: 2 callbackBeforeSendGroupMsg: - enable: true + enable: false callbackTimeOut: 2 CallbackFailedContinue: true callbackAfterSendGroupMsg: - enable: true + enable: false callbackTimeOut: 2 callbackWordFilter: - enable: true + enable: false callbackTimeOut: 2 CallbackFailedContinue: true From bcae7720e104335e6c11ad8f4f4ab6c99bdf460a Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 4 Mar 2022 14:27:54 +0800 Subject: [PATCH 49/67] add callback --- cmd/open_im_api/main.go | 2 +- config/config.yaml | 14 +++++++------- internal/api/third/minio_init.go | 2 +- internal/rpc/msg/callback.go | 10 ++++++---- internal/rpc/msg/send_msg.go | 25 ++++++++++++++----------- pkg/call_back_struct/common.go | 6 +++--- pkg/common/constant/constant.go | 10 +++++----- 7 files changed, 37 insertions(+), 32 deletions(-) diff --git a/cmd/open_im_api/main.go b/cmd/open_im_api/main.go index d5c01986b..551a37a0e 100644 --- a/cmd/open_im_api/main.go +++ b/cmd/open_im_api/main.go @@ -102,7 +102,7 @@ func main() { conversationGroup.POST("/get_receive_message_opt", conversation.GetReceiveMessageOpt) //1 conversationGroup.POST("/get_all_conversation_message_opt", conversation.GetAllConversationMessageOpt) //1 } - + apiThird.MinioInit() log.NewPrivateLog("api") ginPort := flag.Int("port", 10000, "get ginServerPort from cmd,default 10000 as port") flag.Parse() diff --git a/config/config.yaml b/config/config.yaml index 4d3990194..7d326758d 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -91,8 +91,8 @@ credential: #腾讯cos,发送图片、视频、文件时需要,请自行申 bucket: openim location: us-east-1 endpoint: http://127.0.0.1:9000 - accessKeyID: minioadmin - secretAccessKey: minioadmin + accessKeyID: user12345 + secretAccessKey: key12345 rpcport: #rpc服务端口 默认即可 @@ -196,21 +196,21 @@ callback: callbackUrl : "http://127.0.0.1:8080/callback" # 开启关闭操作前后回调的配置 callbackbeforeSendSingleMsg: - enable: false # 回调是否启用 + enable: true # 回调是否启用 callbackTimeOut: 2 # 回调超时时间 CallbackFailedContinue: true # 回调超时是否继续执行代码 callbackAfterSendSingleMsg: - enable: false + enable: true callbackTimeOut: 2 callbackBeforeSendGroupMsg: - enable: false + enable: true callbackTimeOut: 2 CallbackFailedContinue: true callbackAfterSendGroupMsg: - enable: false + enable: true callbackTimeOut: 2 callbackWordFilter: - enable: false + enable: true callbackTimeOut: 2 CallbackFailedContinue: true diff --git a/internal/api/third/minio_init.go b/internal/api/third/minio_init.go index 8dae26d9f..29338ee77 100644 --- a/internal/api/third/minio_init.go +++ b/internal/api/third/minio_init.go @@ -10,7 +10,7 @@ import ( url2 "net/url" ) -func init() { +func MinioInit() { minioUrl, err := url2.Parse(config.Config.Credential.Minio.Endpoint) if err != nil { log.NewError("", utils.GetSelfFuncName(), "parse failed, please check config/config.yaml", err.Error()) diff --git a/internal/rpc/msg/callback.go b/internal/rpc/msg/callback.go index 54ff93786..c560fff95 100644 --- a/internal/rpc/msg/callback.go +++ b/internal/rpc/msg/callback.go @@ -113,10 +113,10 @@ func callbackAfterSendGroupMsg(msg *pbChat.SendMsgReq) error { } log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg) commonCallbackReq := copyCallbackCommonReqStruct(msg) - commonCallbackReq.CallbackCommand = constant.CallbackBeforeSendGroupMsgCommand - req := cbApi.CallbackBeforeSendSingleMsgReq{ + commonCallbackReq.CallbackCommand = constant.CallbackAfterSendGroupMsgCommand + req := cbApi.CallbackAfterSendGroupMsgReq{ CommonCallbackReq: commonCallbackReq, - RecvID: msg.MsgData.RecvID, + GroupID: msg.MsgData.GroupID, } resp := &cbApi.CallbackAfterSendGroupMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}} @@ -152,7 +152,9 @@ func callbackWordFilter(msg *pbChat.SendMsgReq) (canSend bool, err error) { if resp.ActionCode == constant.ActionForbidden && resp.ErrCode == constant.CallbackHandleSuccess { return false, nil } - msg.MsgData.Content = []byte(resp.Content) + if resp.ErrCode == constant.CallbackHandleSuccess { + msg.MsgData.Content = []byte(resp.Content) + } log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), string(msg.MsgData.Content)) } return true, nil diff --git a/internal/rpc/msg/send_msg.go b/internal/rpc/msg/send_msg.go index 16720575a..739a28171 100644 --- a/internal/rpc/msg/send_msg.go +++ b/internal/rpc/msg/send_msg.go @@ -128,21 +128,22 @@ func (rpc *rpcChat) SendMsg(_ context.Context, pb *pbChat.SendMsgReq) (*pbChat.S // callback canSend, err := callbackWordFilter(pb) if err != nil { - log.NewError(pb.OperationID, utils.GetSelfFuncName(), "CallbackBeforeSendMsg failed", err.Error(), pb.MsgData) + log.NewError(pb.OperationID, utils.GetSelfFuncName(), "callbackWordFilter failed", err.Error(), pb.MsgData) } if !canSend { - log.NewDebug(pb.OperationID, utils.GetSelfFuncName(), "callback result", canSend, "end rpc and return", pb.MsgData) - return returnMsg(&replay, pb, 201, "callback result stop rpc and return", "", 0) + log.NewDebug(pb.OperationID, utils.GetSelfFuncName(), "callbackWordFilter result", canSend, "end rpc and return", pb.MsgData) + return returnMsg(&replay, pb, 201, "callbackWordFilter result stop rpc and return", "", 0) } switch pb.MsgData.SessionType { case constant.SingleChatType: + // callback canSend, err := callbackBeforeSendSingleMsg(pb) if err != nil { - log.NewError(pb.OperationID, utils.GetSelfFuncName(), "CallBackAfterSendMsg failed", err.Error()) + log.NewError(pb.OperationID, utils.GetSelfFuncName(), "callbackBeforeSendSingleMsg failed", err.Error()) } if !canSend { - log.NewDebug(pb.OperationID, utils.GetSelfFuncName(), "callback result", canSend, "end rpc and return") - return returnMsg(&replay, pb, 201, "callback result stop rpc and return", "", 0) + log.NewDebug(pb.OperationID, utils.GetSelfFuncName(), "callbackBeforeSendSingleMsg result", canSend, "end rpc and return") + return returnMsg(&replay, pb, 201, "callbackBeforeSendSingleMsg result stop rpc and return", "", 0) } isSend := modifyMessageByUserMessageReceiveOpt(pb.MsgData.RecvID, pb.MsgData.SendID, constant.SingleChatType, pb) if isSend { @@ -161,18 +162,20 @@ func (rpc *rpcChat) SendMsg(_ context.Context, pb *pbChat.SendMsgReq) (*pbChat.S return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0) } } + // callback if err := callbackAfterSendSingleMsg(pb); err != nil { - log.NewError(pb.OperationID, utils.GetSelfFuncName(), "CallBackAfterSendMsg failed", err.Error()) + log.NewError(pb.OperationID, utils.GetSelfFuncName(), "callbackAfterSendSingleMsg failed", err.Error()) } return returnMsg(&replay, pb, 0, "", msgToMQ.MsgData.ServerMsgID, msgToMQ.MsgData.SendTime) case constant.GroupChatType: + // callback canSend, err := callbackBeforeSendGroupMsg(pb) if err != nil { - log.NewError(pb.OperationID, utils.GetSelfFuncName(), "CallBackAfterSendMsg failed", err.Error()) + log.NewError(pb.OperationID, utils.GetSelfFuncName(), "callbackBeforeSendGroupMsg failed", err.Error()) } if !canSend { - log.NewDebug(pb.OperationID, utils.GetSelfFuncName(), "callback result", canSend, "end rpc and return") - return returnMsg(&replay, pb, 201, "callback result stop rpc and return", "", 0) + log.NewDebug(pb.OperationID, utils.GetSelfFuncName(), "callbackBeforeSendGroupMsg result", canSend, "end rpc and return") + return returnMsg(&replay, pb, 201, "callbackBeforeSendGroupMsg result stop rpc and return", "", 0) } etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName) client := pbGroup.NewGroupClient(etcdConn) @@ -237,8 +240,8 @@ func (rpc *rpcChat) SendMsg(_ context.Context, pb *pbChat.SendMsgReq) (*pbChat.S return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0) } } - } + // callback if err := callbackAfterSendGroupMsg(pb); err != nil { log.NewError(pb.OperationID, utils.GetSelfFuncName(), "CallBackAfterSendMsg failed", err.Error()) } diff --git a/pkg/call_back_struct/common.go b/pkg/call_back_struct/common.go index 5e33889fe..e2bf510f4 100644 --- a/pkg/call_back_struct/common.go +++ b/pkg/call_back_struct/common.go @@ -3,13 +3,13 @@ package call_back_struct type CommonCallbackReq struct { SendID string `json:"sendID"` CallbackCommand string `json:"callbackCommand"` - ServerMsgID string `json:"serverID"` - ClientMsgID string `json:"clientID"` + ServerMsgID string `json:"serverMsgID"` + ClientMsgID string `json:"clientMsgID"` OperationID string `json:"operationID"` SenderPlatformID int32 `json:"senderPlatformID"` SenderNickname string `json:"senderNickname"` SessionType int32 `json:"sessionType"` - MsgFrom int32 `json:"MsgFrom"` + MsgFrom int32 `json:"msgFrom"` ContentType int32 `json:"contentType"` Status int32 `json:"status"` CreateTime int64 `json:"createTime"` diff --git a/pkg/common/constant/constant.go b/pkg/common/constant/constant.go index fa8646d5e..199a1917a 100644 --- a/pkg/common/constant/constant.go +++ b/pkg/common/constant/constant.go @@ -138,15 +138,15 @@ const ( VerificationCodeForResetSuffix = "_forReset" //callbackCommand - CallbackBeforeSendSingleMsgCommand = "callbackBeforeSendSingleMsg" - CallbackAfterSendSingleMsgCommand = "callbackAfterSendSingleMsg" - CallbackBeforeSendGroupMsgCommand = "callbackBeforeSendGroupMsg" + CallbackBeforeSendSingleMsgCommand = "callbackBeforeSendSingleMsgCommand" + CallbackAfterSendSingleMsgCommand = "callbackAfterSendSingleMsgCommand" + CallbackBeforeSendGroupMsgCommand = "callbackBeforeSendGroupMsgCommand" CallbackAfterSendGroupMsgCommand = "callbackAfterSendGroupMsgCommand" CallbackWordFilterCommand = "callbackWordFilterCommand" - //actionCode + //callback actionCode ActionAllow = 0 ActionForbidden = 1 - //callbackHandleCode + //callback callbackHandleCode CallbackHandleSuccess = 0 CallbackHandleFailed = 1 ) From c108115c830d90584271b4cd61930016e4766ea4 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 4 Mar 2022 15:20:59 +0800 Subject: [PATCH 50/67] add callback --- internal/rpc/msg/callback.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/internal/rpc/msg/callback.go b/internal/rpc/msg/callback.go index c560fff95..9dc90eb50 100644 --- a/internal/rpc/msg/callback.go +++ b/internal/rpc/msg/callback.go @@ -53,7 +53,7 @@ func callbackBeforeSendSingleMsg(msg *pbChat.SendMsgReq) (canSend bool, err erro return false, nil } } - return true, nil + return true, err } @@ -87,23 +87,23 @@ func callbackBeforeSendGroupMsg(msg *pbChat.SendMsgReq) (canSend bool, err error log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg) commonCallbackReq := copyCallbackCommonReqStruct(msg) commonCallbackReq.CallbackCommand = constant.CallbackBeforeSendGroupMsgCommand - req := cbApi.CallbackBeforeSendSingleMsgReq{ + req := cbApi.CallbackAfterSendGroupMsgReq{ CommonCallbackReq: commonCallbackReq, - RecvID: msg.MsgData.RecvID, + GroupID: msg.MsgData.GroupID, } resp := &cbApi.CallbackBeforeSendGroupMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}} //utils.CopyStructFields(req, msg.MsgData) defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp) if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackBeforeSendGroupMsg.CallbackTimeOut); err != nil { if !config.Config.Callback.CallbackBeforeSendGroupMsg.CallbackFailedContinue { - return false, nil + return false, err } } else { if resp.ActionCode == constant.ActionForbidden && resp.ErrCode == constant.CallbackHandleSuccess { return false, nil } } - return true, nil + return true, err } func callbackAfterSendGroupMsg(msg *pbChat.SendMsgReq) error { @@ -145,7 +145,7 @@ func callbackWordFilter(msg *pbChat.SendMsgReq) (canSend bool, err error) { defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp) if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackWordFilter.CallbackTimeOut); err != nil { if !config.Config.Callback.CallbackWordFilter.CallbackFailedContinue { - log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), "config disable, stop this operation") + log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), "callback failed and config disable, stop this operation") return false, err } } else { @@ -157,7 +157,7 @@ func callbackWordFilter(msg *pbChat.SendMsgReq) (canSend bool, err error) { } log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), string(msg.MsgData.Content)) } - return true, nil + return true, err } From 8dc04667b00e316459cf0c655b433f5831c2594e Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Fri, 4 Mar 2022 16:11:04 +0800 Subject: [PATCH 51/67] test recover --- internal/msg_gateway/gate/ws_server.go | 21 +++-- internal/msg_transfer/logic/init.go | 2 +- internal/push/logic/push_to_client.go | 126 +++++++++++++------------ pkg/statistics/statistics.go | 7 +- 4 files changed, 80 insertions(+), 76 deletions(-) diff --git a/internal/msg_gateway/gate/ws_server.go b/internal/msg_gateway/gate/ws_server.go index ff7e739c8..477d43420 100644 --- a/internal/msg_gateway/gate/ws_server.go +++ b/internal/msg_gateway/gate/ws_server.go @@ -5,6 +5,7 @@ import ( "Open_IM/pkg/common/constant" "Open_IM/pkg/common/db" "Open_IM/pkg/common/log" + "Open_IM/pkg/common/token_verify" "Open_IM/pkg/utils" "bytes" "encoding/gob" @@ -257,16 +258,16 @@ func (ws *WServer) headerCheck(w http.ResponseWriter, r *http.Request) bool { status := http.StatusUnauthorized query := r.URL.Query() if len(query["token"]) != 0 && len(query["sendID"]) != 0 && len(query["platformID"]) != 0 { - //if ok, err := token_verify.VerifyToken(query["token"][0], query["sendID"][0]); !ok { - // e := err.(*constant.ErrInfo) - // log.ErrorByKv("Token verify failed", "", "query", query) - // w.Header().Set("Sec-Websocket-Version", "13") - // http.Error(w, e.ErrMsg, int(e.ErrCode)) - // return false - //} else { - log.InfoByKv("Connection Authentication Success", "", "token", query["token"][0], "userID", query["sendID"][0]) - return true - //} + if ok, err := token_verify.VerifyToken(query["token"][0], query["sendID"][0]); !ok { + e := err.(*constant.ErrInfo) + log.ErrorByKv("Token verify failed", "", "query", query) + w.Header().Set("Sec-Websocket-Version", "13") + http.Error(w, e.ErrMsg, int(e.ErrCode)) + return false + } else { + log.InfoByKv("Connection Authentication Success", "", "token", query["token"][0], "userID", query["sendID"][0]) + return true + } } else { log.ErrorByKv("Args err", "", "query", query) w.Header().Set("Sec-Websocket-Version", "13") diff --git a/internal/msg_transfer/logic/init.go b/internal/msg_transfer/logic/init.go index 7d1cad671..cce434d99 100644 --- a/internal/msg_transfer/logic/init.go +++ b/internal/msg_transfer/logic/init.go @@ -20,6 +20,6 @@ func Init() { } func Run() { //register mysqlConsumerHandler to - //go persistentCH.persistentConsumerGroup.RegisterHandleAndConsumer(&persistentCH) + go persistentCH.persistentConsumerGroup.RegisterHandleAndConsumer(&persistentCH) go historyCH.historyConsumerGroup.RegisterHandleAndConsumer(&historyCH) } diff --git a/internal/push/logic/push_to_client.go b/internal/push/logic/push_to_client.go index 11d090ac5..a5a6397f2 100644 --- a/internal/push/logic/push_to_client.go +++ b/internal/push/logic/push_to_client.go @@ -7,12 +7,16 @@ package logic import ( + push "Open_IM/internal/push/jpush" "Open_IM/pkg/common/config" + "Open_IM/pkg/common/constant" "Open_IM/pkg/common/log" "Open_IM/pkg/grpc-etcdv3/getcdv3" pbPush "Open_IM/pkg/proto/push" pbRelay "Open_IM/pkg/proto/relay" + "Open_IM/pkg/utils" "context" + "encoding/json" "strings" ) @@ -30,7 +34,7 @@ type AtContent struct { func MsgToUser(pushMsg *pbPush.PushMsgReq) { var wsResult []*pbRelay.SingleMsgToUser - //isOfflinePush := utils.GetSwitchFromOptions(pushMsg.MsgData.Options, constant.IsOfflinePush) + isOfflinePush := utils.GetSwitchFromOptions(pushMsg.MsgData.Options, constant.IsOfflinePush) log.Debug("Get msg from msg_transfer And push msg", pushMsg.OperationID, "PushData", pushMsg.String()) grpcCons := getcdv3.GetConn4Unique(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOnlineMessageRelayName) //Online push message @@ -48,66 +52,66 @@ func MsgToUser(pushMsg *pbPush.PushMsgReq) { } log.InfoByKv("push_result", pushMsg.OperationID, "result", wsResult, "sendData", pushMsg.MsgData) count++ - //if isOfflinePush && pushMsg.PushToUserID != pushMsg.MsgData.SendID { - // for _, v := range wsResult { - // if v.ResultCode == 0 { - // continue - // } - // //supported terminal - // for _, t := range pushTerminal { - // if v.RecvPlatFormID == t { - // //Use offline push messaging - // var UIDList []string - // UIDList = append(UIDList, v.RecvID) - // customContent := OpenIMContent{ - // SessionType: int(pushMsg.MsgData.SessionType), - // From: pushMsg.MsgData.SendID, - // To: pushMsg.MsgData.RecvID, - // Seq: pushMsg.MsgData.Seq, - // } - // bCustomContent, _ := json.Marshal(customContent) - // jsonCustomContent := string(bCustomContent) - // var content string - // if pushMsg.MsgData.OfflinePushInfo != nil { - // content = pushMsg.MsgData.OfflinePushInfo.Title - // - // } else { - // switch pushMsg.MsgData.ContentType { - // case constant.Text: - // content = constant.ContentType2PushContent[constant.Text] - // case constant.Picture: - // content = constant.ContentType2PushContent[constant.Picture] - // case constant.Voice: - // content = constant.ContentType2PushContent[constant.Voice] - // case constant.Video: - // content = constant.ContentType2PushContent[constant.Video] - // case constant.File: - // content = constant.ContentType2PushContent[constant.File] - // case constant.AtText: - // a := AtContent{} - // _ = utils.JsonStringToStruct(string(pushMsg.MsgData.Content), &a) - // if utils.IsContain(v.RecvID, a.AtUserList) { - // content = constant.ContentType2PushContent[constant.AtText] + constant.ContentType2PushContent[constant.Common] - // } else { - // content = constant.ContentType2PushContent[constant.GroupMsg] - // } - // default: - // content = constant.ContentType2PushContent[constant.Common] - // } - // } - // - // pushResult, err := push.JGAccountListPush(UIDList, content, jsonCustomContent, constant.PlatformIDToName(t)) - // if err != nil { - // log.NewError(pushMsg.OperationID, "offline push error", pushMsg.String(), err.Error(), constant.PlatformIDToName(t)) - // } else { - // log.NewDebug(pushMsg.OperationID, "offline push return result is ", string(pushResult), pushMsg.MsgData, constant.PlatformIDToName(t)) - // } - // - // } - // } - // } - // - //} + if isOfflinePush && pushMsg.PushToUserID != pushMsg.MsgData.SendID { + for _, v := range wsResult { + if v.ResultCode == 0 { + continue + } + //supported terminal + for _, t := range pushTerminal { + if v.RecvPlatFormID == t { + //Use offline push messaging + var UIDList []string + UIDList = append(UIDList, v.RecvID) + customContent := OpenIMContent{ + SessionType: int(pushMsg.MsgData.SessionType), + From: pushMsg.MsgData.SendID, + To: pushMsg.MsgData.RecvID, + Seq: pushMsg.MsgData.Seq, + } + bCustomContent, _ := json.Marshal(customContent) + jsonCustomContent := string(bCustomContent) + var content string + if pushMsg.MsgData.OfflinePushInfo != nil { + content = pushMsg.MsgData.OfflinePushInfo.Title + + } else { + switch pushMsg.MsgData.ContentType { + case constant.Text: + content = constant.ContentType2PushContent[constant.Text] + case constant.Picture: + content = constant.ContentType2PushContent[constant.Picture] + case constant.Voice: + content = constant.ContentType2PushContent[constant.Voice] + case constant.Video: + content = constant.ContentType2PushContent[constant.Video] + case constant.File: + content = constant.ContentType2PushContent[constant.File] + case constant.AtText: + a := AtContent{} + _ = utils.JsonStringToStruct(string(pushMsg.MsgData.Content), &a) + if utils.IsContain(v.RecvID, a.AtUserList) { + content = constant.ContentType2PushContent[constant.AtText] + constant.ContentType2PushContent[constant.Common] + } else { + content = constant.ContentType2PushContent[constant.GroupMsg] + } + default: + content = constant.ContentType2PushContent[constant.Common] + } + } + + pushResult, err := push.JGAccountListPush(UIDList, content, jsonCustomContent, constant.PlatformIDToName(t)) + if err != nil { + log.NewError(pushMsg.OperationID, "offline push error", pushMsg.String(), err.Error(), constant.PlatformIDToName(t)) + } else { + log.NewDebug(pushMsg.OperationID, "offline push return result is ", string(pushResult), pushMsg.MsgData, constant.PlatformIDToName(t)) + } + + } + } + } + + } } //func SendMsgByWS(m *pbChat.WSToMsgSvrChatMsg) { diff --git a/pkg/statistics/statistics.go b/pkg/statistics/statistics.go index bea4479bd..2711c5d91 100644 --- a/pkg/statistics/statistics.go +++ b/pkg/statistics/statistics.go @@ -1,7 +1,6 @@ package statistics import ( - "Open_IM/pkg/common/log" "time" ) @@ -15,13 +14,13 @@ type Statistics struct { func (s *Statistics) output() { t := time.NewTicker(time.Duration(s.SleepTime) * time.Second) defer t.Stop() - var sum uint64 + //var sum uint64 for { - sum = *s.Count + //sum = *s.Count select { case <-t.C: } - log.NewWarn("", " system stat ", s.ModuleName, s.PrintArgs, *s.Count-sum, "total:", *s.Count) + //log.NewWarn("", " system stat ", s.ModuleName, s.PrintArgs, *s.Count-sum, "total:", *s.Count) } } From d6e7cfb04415aacda522242d032d0d9d45175184 Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Fri, 4 Mar 2022 16:24:28 +0800 Subject: [PATCH 52/67] shell update --- config/config.yaml | 5 +++-- script/sdk_svr_start.sh | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/config/config.yaml b/config/config.yaml index 7d326758d..72d45568e 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -131,8 +131,9 @@ rpcregistername: #rpc注册服务名,默认即可 log: storageLocation: ../logs/ rotationTime: 24 - remainRotationCount: 5 #日志数量 - remainLogLevel: 6 #日志级别 6表示全都打印,测试阶段建议设置为6 + remainRotationCount: 3 #日志数量 + #日志级别 6表示全都打印,测试阶段建议设置为6 + remainLogLevel: 6 elasticSearchSwitch: false elasticSearchAddr: [ 127.0.0.1:9201 ] elasticSearchUser: "" diff --git a/script/sdk_svr_start.sh b/script/sdk_svr_start.sh index e9604e5ea..5f47228dc 100644 --- a/script/sdk_svr_start.sh +++ b/script/sdk_svr_start.sh @@ -6,6 +6,7 @@ source ./function.sh list1=$(cat $config_path | grep openImApiPort | awk -F '[:]' '{print $NF}') list2=$(cat $config_path | grep openImWsPort | awk -F '[:]' '{print $NF}') list3=$(cat $config_path | grep openImSdkWsPort | awk -F '[:]' '{print $NF}') +logLevel=$(cat $config_path | grep remainLogLevel | awk -F '[:]' '{print $NF}') list_to_string $list1 api_ports=($ports_array) list_to_string $list2 @@ -26,7 +27,7 @@ fi #Waiting port recycling sleep 1 cd ${sdk_server_binary_root} - nohup ./${sdk_server_name} -openIM_api_port ${api_ports[0]} -openIM_ws_port ${ws_ports[0]} -sdk_ws_port ${sdk_ws_ports[0]} >>../logs/openIM.log 2>&1 & + nohup ./${sdk_server_name} -openIM_api_port ${api_ports[0]} -openIM_ws_port ${ws_ports[0]} -sdk_ws_port ${sdk_ws_ports[0]} -openIM_log_level ${logLevel} >>../logs/openIM.log 2>&1 & #Check launched service process sleep 3 From 95f6035aa855184cf52b4d1fcaf46c374d6087f1 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 4 Mar 2022 16:37:49 +0800 Subject: [PATCH 53/67] add cb --- config/config.yaml | 8 ++++---- internal/rpc/msg/callback.go | 7 ++----- internal/rpc/msg/send_msg.go | 2 +- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/config/config.yaml b/config/config.yaml index 7d326758d..3f4e853e6 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -196,18 +196,18 @@ callback: callbackUrl : "http://127.0.0.1:8080/callback" # 开启关闭操作前后回调的配置 callbackbeforeSendSingleMsg: - enable: true # 回调是否启用 + enable: false # 回调是否启用 callbackTimeOut: 2 # 回调超时时间 CallbackFailedContinue: true # 回调超时是否继续执行代码 callbackAfterSendSingleMsg: - enable: true + enable: false callbackTimeOut: 2 callbackBeforeSendGroupMsg: - enable: true + enable: false callbackTimeOut: 2 CallbackFailedContinue: true callbackAfterSendGroupMsg: - enable: true + enable: false callbackTimeOut: 2 callbackWordFilter: enable: true diff --git a/internal/rpc/msg/callback.go b/internal/rpc/msg/callback.go index 9dc90eb50..a09b1e87c 100644 --- a/internal/rpc/msg/callback.go +++ b/internal/rpc/msg/callback.go @@ -28,7 +28,6 @@ func copyCallbackCommonReqStruct(msg *pbChat.SendMsgReq) cbApi.CommonCallbackReq } func callbackBeforeSendSingleMsg(msg *pbChat.SendMsgReq) (canSend bool, err error) { - log.NewDebug(msg.OperationID, config.Config.Callback.CallbackBeforeSendSingleMsg.Enable) if !config.Config.Callback.CallbackBeforeSendSingleMsg.Enable { return true, nil } @@ -58,7 +57,6 @@ func callbackBeforeSendSingleMsg(msg *pbChat.SendMsgReq) (canSend bool, err erro func callbackAfterSendSingleMsg(msg *pbChat.SendMsgReq) error { - log.NewDebug(msg.OperationID, config.Config.Callback.CallbackAfterSendSingleMsg.Enable) if !config.Config.Callback.CallbackAfterSendSingleMsg.Enable { return nil } @@ -80,7 +78,6 @@ func callbackAfterSendSingleMsg(msg *pbChat.SendMsgReq) error { func callbackBeforeSendGroupMsg(msg *pbChat.SendMsgReq) (canSend bool, err error) { - log.NewDebug(msg.OperationID, config.Config.Callback.CallbackBeforeSendGroupMsg.Enable) if !config.Config.Callback.CallbackBeforeSendGroupMsg.Enable { return true, nil } @@ -103,11 +100,11 @@ func callbackBeforeSendGroupMsg(msg *pbChat.SendMsgReq) (canSend bool, err error return false, nil } } + log.NewInfo() return true, err } func callbackAfterSendGroupMsg(msg *pbChat.SendMsgReq) error { - log.NewDebug(msg.OperationID, config.Config.Callback.CallbackAfterSendGroupMsg.Enable) if !config.Config.Callback.CallbackAfterSendGroupMsg.Enable { return nil } @@ -130,7 +127,6 @@ func callbackAfterSendGroupMsg(msg *pbChat.SendMsgReq) error { func callbackWordFilter(msg *pbChat.SendMsgReq) (canSend bool, err error) { - log.NewDebug(msg.OperationID, config.Config.Callback.CallbackWordFilter.Enable) if !config.Config.Callback.CallbackWordFilter.Enable || msg.MsgData.ContentType != constant.Text { return true, nil } @@ -157,6 +153,7 @@ func callbackWordFilter(msg *pbChat.SendMsgReq) (canSend bool, err error) { } log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), string(msg.MsgData.Content)) } + log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), err.Error()) return true, err } diff --git a/internal/rpc/msg/send_msg.go b/internal/rpc/msg/send_msg.go index 739a28171..af8f40b4f 100644 --- a/internal/rpc/msg/send_msg.go +++ b/internal/rpc/msg/send_msg.go @@ -243,7 +243,7 @@ func (rpc *rpcChat) SendMsg(_ context.Context, pb *pbChat.SendMsgReq) (*pbChat.S } // callback if err := callbackAfterSendGroupMsg(pb); err != nil { - log.NewError(pb.OperationID, utils.GetSelfFuncName(), "CallBackAfterSendMsg failed", err.Error()) + log.NewError(pb.OperationID, utils.GetSelfFuncName(), "callbackAfterSendGroupMsg failed", err.Error()) } return returnMsg(&replay, pb, 0, "", msgToMQ.MsgData.ServerMsgID, msgToMQ.MsgData.SendTime) default: From af2917adb9d952c86002dc51c27eed1deb1916a1 Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Fri, 4 Mar 2022 16:38:53 +0800 Subject: [PATCH 54/67] log --- pkg/common/log/file_line_hk.go | 75 +++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 32 deletions(-) diff --git a/pkg/common/log/file_line_hk.go b/pkg/common/log/file_line_hk.go index 9ffa7806e..35dd34912 100644 --- a/pkg/common/log/file_line_hk.go +++ b/pkg/common/log/file_line_hk.go @@ -7,7 +7,7 @@ package log import ( - "fmt" + "Open_IM/pkg/utils" "github.com/sirupsen/logrus" "runtime" "strings" @@ -23,38 +23,49 @@ func (f *fileHook) Levels() []logrus.Level { return logrus.AllLevels } -func (f *fileHook) Fire(entry *logrus.Entry) error { - entry.Data["FilePath"] = findCaller(6) - return nil -} +//func (f *fileHook) Fire(entry *logrus.Entry) error { +// entry.Data["FilePath"] = findCaller(6) +// return nil +//} -func findCaller(skip int) string { - file := "" - line := 0 - for i := 0; i < 10; i++ { - file, line = getCaller(skip + i) - if !strings.HasPrefix(file, "log") { - break - } +func (f *fileHook) Fire(entry *logrus.Entry) error { + var s string + _, b, c, _ := runtime.Caller(8) + i := strings.LastIndex(b, "/") + if i != -1 { + s = b[i+1:len(b)] + ":" + utils.IntToString(c) } - return fmt.Sprintf("%s:%d", file, line) + entry.Data["FilePath"] = s + return nil } -func getCaller(skip int) (string, int) { - _, file, line, ok := runtime.Caller(skip) - if !ok { - return "", 0 - } - - n := 0 - for i := len(file) - 1; i > 0; i-- { - if file[i] == '/' { - n++ - if n >= 2 { - file = file[i+1:] - break - } - } - } - return file, line -} +//func findCaller(skip int) string { +// file := "" +// line := 0 +// for i := 0; i < 10; i++ { +// file, line = getCaller(skip + i) +// if !strings.HasPrefix(file, "log") { +// break +// } +// } +// return fmt.Sprintf("%s:%d", file, line) +//} +// +//func getCaller(skip int) (string, int) { +// _, file, line, ok := runtime.Caller(skip) +// if !ok { +// return "", 0 +// } +// +// n := 0 +// for i := len(file) - 1; i > 0; i-- { +// if file[i] == '/' { +// n++ +// if n >= 2 { +// file = file[i+1:] +// break +// } +// } +// } +// return file, line +//} From 7e9234e71262332b789c78a227681eb613983fce Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Fri, 4 Mar 2022 17:13:23 +0800 Subject: [PATCH 55/67] log --- pkg/common/log/file_line_hk.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/common/log/file_line_hk.go b/pkg/common/log/file_line_hk.go index 35dd34912..7e079b79f 100644 --- a/pkg/common/log/file_line_hk.go +++ b/pkg/common/log/file_line_hk.go @@ -31,9 +31,9 @@ func (f *fileHook) Levels() []logrus.Level { func (f *fileHook) Fire(entry *logrus.Entry) error { var s string _, b, c, _ := runtime.Caller(8) - i := strings.LastIndex(b, "/") - if i != -1 { - s = b[i+1:len(b)] + ":" + utils.IntToString(c) + i := strings.SplitAfter(b, "/") + if len(i) > 3 { + s = i[len(i)-3] + i[len(i)-2] + i[len(i)-1] + ":" + utils.IntToString(c) } entry.Data["FilePath"] = s return nil From 9bbcf0c5d7c7ff8adc7821f170335cea39b320e9 Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Fri, 4 Mar 2022 17:16:21 +0800 Subject: [PATCH 56/67] log --- internal/rpc/msg/callback.go | 44 +++++++++++++++--------------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/internal/rpc/msg/callback.go b/internal/rpc/msg/callback.go index a09b1e87c..d9875da1e 100644 --- a/internal/rpc/msg/callback.go +++ b/internal/rpc/msg/callback.go @@ -12,18 +12,18 @@ import ( func copyCallbackCommonReqStruct(msg *pbChat.SendMsgReq) cbApi.CommonCallbackReq { return cbApi.CommonCallbackReq{ - SendID: msg.MsgData.SendID, - ServerMsgID: msg.MsgData.ServerMsgID, - ClientMsgID: msg.MsgData.ClientMsgID, - OperationID: msg.OperationID, + SendID: msg.MsgData.SendID, + ServerMsgID: msg.MsgData.ServerMsgID, + ClientMsgID: msg.MsgData.ClientMsgID, + OperationID: msg.OperationID, SenderPlatformID: msg.MsgData.SenderPlatformID, - SenderNickname: msg.MsgData.SenderNickname, - SessionType: msg.MsgData.SessionType, - MsgFrom: msg.MsgData.MsgFrom, - ContentType: msg.MsgData.ContentType, - Status: msg.MsgData.Status, - CreateTime: msg.MsgData.CreateTime, - Content: string(msg.MsgData.Content), + SenderNickname: msg.MsgData.SenderNickname, + SessionType: msg.MsgData.SessionType, + MsgFrom: msg.MsgData.MsgFrom, + ContentType: msg.MsgData.ContentType, + Status: msg.MsgData.Status, + CreateTime: msg.MsgData.CreateTime, + Content: string(msg.MsgData.Content), } } @@ -36,14 +36,14 @@ func callbackBeforeSendSingleMsg(msg *pbChat.SendMsgReq) (canSend bool, err erro commonCallbackReq.CallbackCommand = constant.CallbackBeforeSendSingleMsgCommand req := cbApi.CallbackBeforeSendSingleMsgReq{ CommonCallbackReq: commonCallbackReq, - RecvID: msg.MsgData.RecvID, + RecvID: msg.MsgData.RecvID, } resp := &cbApi.CallbackBeforeSendSingleMsgResp{ CommonCallbackResp: cbApi.CommonCallbackResp{}, } //utils.CopyStructFields(req, msg.MsgData) defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp) - if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackBeforeSendSingleMsg.CallbackTimeOut); err != nil{ + if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackBeforeSendSingleMsg.CallbackTimeOut); err != nil { if !config.Config.Callback.CallbackBeforeSendSingleMsg.CallbackFailedContinue { return false, err } @@ -55,7 +55,6 @@ func callbackBeforeSendSingleMsg(msg *pbChat.SendMsgReq) (canSend bool, err erro return true, err } - func callbackAfterSendSingleMsg(msg *pbChat.SendMsgReq) error { if !config.Config.Callback.CallbackAfterSendSingleMsg.Enable { return nil @@ -65,18 +64,17 @@ func callbackAfterSendSingleMsg(msg *pbChat.SendMsgReq) error { commonCallbackReq.CallbackCommand = constant.CallbackAfterSendSingleMsgCommand req := cbApi.CallbackAfterSendSingleMsgReq{ CommonCallbackReq: commonCallbackReq, - RecvID: msg.MsgData.RecvID, + RecvID: msg.MsgData.RecvID, } resp := &cbApi.CallbackAfterSendSingleMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}} //utils.CopyStructFields(req, msg.MsgData) defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp) - if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackAfterSendSingleMsg.CallbackTimeOut); err != nil{ + if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackAfterSendSingleMsg.CallbackTimeOut); err != nil { return err } return nil } - func callbackBeforeSendGroupMsg(msg *pbChat.SendMsgReq) (canSend bool, err error) { if !config.Config.Callback.CallbackBeforeSendGroupMsg.Enable { return true, nil @@ -86,7 +84,7 @@ func callbackBeforeSendGroupMsg(msg *pbChat.SendMsgReq) (canSend bool, err error commonCallbackReq.CallbackCommand = constant.CallbackBeforeSendGroupMsgCommand req := cbApi.CallbackAfterSendGroupMsgReq{ CommonCallbackReq: commonCallbackReq, - GroupID: msg.MsgData.GroupID, + GroupID: msg.MsgData.GroupID, } resp := &cbApi.CallbackBeforeSendGroupMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}} //utils.CopyStructFields(req, msg.MsgData) @@ -100,7 +98,7 @@ func callbackBeforeSendGroupMsg(msg *pbChat.SendMsgReq) (canSend bool, err error return false, nil } } - log.NewInfo() + //log.NewInfo() return true, err } @@ -113,7 +111,7 @@ func callbackAfterSendGroupMsg(msg *pbChat.SendMsgReq) error { commonCallbackReq.CallbackCommand = constant.CallbackAfterSendGroupMsgCommand req := cbApi.CallbackAfterSendGroupMsgReq{ CommonCallbackReq: commonCallbackReq, - GroupID: msg.MsgData.GroupID, + GroupID: msg.MsgData.GroupID, } resp := &cbApi.CallbackAfterSendGroupMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}} @@ -125,7 +123,6 @@ func callbackAfterSendGroupMsg(msg *pbChat.SendMsgReq) error { return nil } - func callbackWordFilter(msg *pbChat.SendMsgReq) (canSend bool, err error) { if !config.Config.Callback.CallbackWordFilter.Enable || msg.MsgData.ContentType != constant.Text { return true, nil @@ -156,8 +153,3 @@ func callbackWordFilter(msg *pbChat.SendMsgReq) (canSend bool, err error) { log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), err.Error()) return true, err } - - - - - From eb1e596cdeb0bc328bf8642a62834efeb59cf120 Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Fri, 4 Mar 2022 17:26:08 +0800 Subject: [PATCH 57/67] log --- internal/rpc/msg/callback.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/rpc/msg/callback.go b/internal/rpc/msg/callback.go index d9875da1e..41421ec2c 100644 --- a/internal/rpc/msg/callback.go +++ b/internal/rpc/msg/callback.go @@ -150,6 +150,6 @@ func callbackWordFilter(msg *pbChat.SendMsgReq) (canSend bool, err error) { } log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), string(msg.MsgData.Content)) } - log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), err.Error()) + log.NewDebug(msg.OperationID, utils.GetSelfFuncName()) return true, err } From 1bcd2d453128181e4b1db30210c76975d4bd0e64 Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Fri, 4 Mar 2022 17:26:50 +0800 Subject: [PATCH 58/67] log --- pkg/common/log/file_line_hk.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/common/log/file_line_hk.go b/pkg/common/log/file_line_hk.go index 7e079b79f..babc4791f 100644 --- a/pkg/common/log/file_line_hk.go +++ b/pkg/common/log/file_line_hk.go @@ -30,7 +30,7 @@ func (f *fileHook) Levels() []logrus.Level { func (f *fileHook) Fire(entry *logrus.Entry) error { var s string - _, b, c, _ := runtime.Caller(8) + _, b, c, _ := runtime.Caller(10) i := strings.SplitAfter(b, "/") if len(i) > 3 { s = i[len(i)-3] + i[len(i)-2] + i[len(i)-1] + ":" + utils.IntToString(c) From a7c8eda2902be18a40ab6b05dac3b51cc2be6772 Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Fri, 4 Mar 2022 17:29:15 +0800 Subject: [PATCH 59/67] log --- pkg/common/log/file_line_hk.go | 80 +++++++++++++++++----------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/pkg/common/log/file_line_hk.go b/pkg/common/log/file_line_hk.go index babc4791f..bc908ee03 100644 --- a/pkg/common/log/file_line_hk.go +++ b/pkg/common/log/file_line_hk.go @@ -7,7 +7,7 @@ package log import ( - "Open_IM/pkg/utils" + "fmt" "github.com/sirupsen/logrus" "runtime" "strings" @@ -23,49 +23,49 @@ func (f *fileHook) Levels() []logrus.Level { return logrus.AllLevels } +func (f *fileHook) Fire(entry *logrus.Entry) error { + entry.Data["FilePath"] = findCaller(6) + return nil +} + //func (f *fileHook) Fire(entry *logrus.Entry) error { -// entry.Data["FilePath"] = findCaller(6) +// var s string +// _, b, c, _ := runtime.Caller(10) +// i := strings.SplitAfter(b, "/") +// if len(i) > 3 { +// s = i[len(i)-3] + i[len(i)-2] + i[len(i)-1] + ":" + utils.IntToString(c) +// } +// entry.Data["FilePath"] = s // return nil //} -func (f *fileHook) Fire(entry *logrus.Entry) error { - var s string - _, b, c, _ := runtime.Caller(10) - i := strings.SplitAfter(b, "/") - if len(i) > 3 { - s = i[len(i)-3] + i[len(i)-2] + i[len(i)-1] + ":" + utils.IntToString(c) +func findCaller(skip int) string { + file := "" + line := 0 + for i := 0; i < 10; i++ { + file, line = getCaller(skip + i) + if !strings.HasPrefix(file, "log") { + break + } } - entry.Data["FilePath"] = s - return nil + return fmt.Sprintf("%s:%d", file, line) } -//func findCaller(skip int) string { -// file := "" -// line := 0 -// for i := 0; i < 10; i++ { -// file, line = getCaller(skip + i) -// if !strings.HasPrefix(file, "log") { -// break -// } -// } -// return fmt.Sprintf("%s:%d", file, line) -//} -// -//func getCaller(skip int) (string, int) { -// _, file, line, ok := runtime.Caller(skip) -// if !ok { -// return "", 0 -// } -// -// n := 0 -// for i := len(file) - 1; i > 0; i-- { -// if file[i] == '/' { -// n++ -// if n >= 2 { -// file = file[i+1:] -// break -// } -// } -// } -// return file, line -//} +func getCaller(skip int) (string, int) { + _, file, line, ok := runtime.Caller(skip) + if !ok { + return "", 0 + } + + n := 0 + for i := len(file) - 1; i > 0; i-- { + if file[i] == '/' { + n++ + if n >= 2 { + file = file[i+1:] + break + } + } + } + return file, line +} From 4c297164a54fc9104be5467a72f153d9bf422b35 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 4 Mar 2022 18:03:22 +0800 Subject: [PATCH 60/67] cb --- config/config.yaml | 11 ++++++----- internal/rpc/msg/callback.go | 5 +++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/config/config.yaml b/config/config.yaml index c76d69ef6..c71011247 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -194,26 +194,27 @@ iospush: badgeCount: true callback: + # callback url 需要自行更换callback url callbackUrl : "http://127.0.0.1:8080/callback" # 开启关闭操作前后回调的配置 callbackbeforeSendSingleMsg: - enable: false # 回调是否启用 + enable: true # 回调是否启用 callbackTimeOut: 2 # 回调超时时间 CallbackFailedContinue: true # 回调超时是否继续执行代码 callbackAfterSendSingleMsg: - enable: false + enable: true callbackTimeOut: 2 callbackBeforeSendGroupMsg: - enable: false + enable: true callbackTimeOut: 2 CallbackFailedContinue: true callbackAfterSendGroupMsg: - enable: false + enable: true callbackTimeOut: 2 callbackWordFilter: enable: true callbackTimeOut: 2 - CallbackFailedContinue: true + CallbackFailedContinue: false notification: diff --git a/internal/rpc/msg/callback.go b/internal/rpc/msg/callback.go index 41421ec2c..a56038de8 100644 --- a/internal/rpc/msg/callback.go +++ b/internal/rpc/msg/callback.go @@ -52,6 +52,7 @@ func callbackBeforeSendSingleMsg(msg *pbChat.SendMsgReq) (canSend bool, err erro return false, nil } } + log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), err.Error()) return true, err } @@ -98,7 +99,7 @@ func callbackBeforeSendGroupMsg(msg *pbChat.SendMsgReq) (canSend bool, err error return false, nil } } - //log.NewInfo() + log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), err.Error()) return true, err } @@ -150,6 +151,6 @@ func callbackWordFilter(msg *pbChat.SendMsgReq) (canSend bool, err error) { } log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), string(msg.MsgData.Content)) } - log.NewDebug(msg.OperationID, utils.GetSelfFuncName()) + log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), err.Error()) return true, err } From 1572d9df89591e022b26c197c0d3fd94106dc51a Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 4 Mar 2022 18:17:44 +0800 Subject: [PATCH 61/67] cb --- internal/rpc/msg/callback.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/rpc/msg/callback.go b/internal/rpc/msg/callback.go index a56038de8..f04c2a1fc 100644 --- a/internal/rpc/msg/callback.go +++ b/internal/rpc/msg/callback.go @@ -52,7 +52,7 @@ func callbackBeforeSendSingleMsg(msg *pbChat.SendMsgReq) (canSend bool, err erro return false, nil } } - log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), err.Error()) + log.NewDebug(msg.OperationID, utils.GetSelfFuncName()) return true, err } From 29f849c184e3149dd7a39188e54f257d495b2991 Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Fri, 4 Mar 2022 18:20:57 +0800 Subject: [PATCH 62/67] log --- internal/rpc/msg/callback.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/rpc/msg/callback.go b/internal/rpc/msg/callback.go index f04c2a1fc..3cff165aa 100644 --- a/internal/rpc/msg/callback.go +++ b/internal/rpc/msg/callback.go @@ -151,6 +151,6 @@ func callbackWordFilter(msg *pbChat.SendMsgReq) (canSend bool, err error) { } log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), string(msg.MsgData.Content)) } - log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), err.Error()) + log.NewDebug(msg.OperationID, utils.GetSelfFuncName()) return true, err } From 08022497e608d778ee91d24539af663307f849f4 Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Fri, 4 Mar 2022 18:21:14 +0800 Subject: [PATCH 63/67] log --- internal/rpc/msg/callback.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/rpc/msg/callback.go b/internal/rpc/msg/callback.go index 3cff165aa..d3413cd7e 100644 --- a/internal/rpc/msg/callback.go +++ b/internal/rpc/msg/callback.go @@ -99,7 +99,7 @@ func callbackBeforeSendGroupMsg(msg *pbChat.SendMsgReq) (canSend bool, err error return false, nil } } - log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), err.Error()) + log.NewDebug(msg.OperationID, utils.GetSelfFuncName()) return true, err } From fafad9217d2660802dd14f39badae187c5a84f8e Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 4 Mar 2022 18:23:58 +0800 Subject: [PATCH 64/67] cb --- internal/rpc/msg/callback.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/rpc/msg/callback.go b/internal/rpc/msg/callback.go index f04c2a1fc..bb8ccd700 100644 --- a/internal/rpc/msg/callback.go +++ b/internal/rpc/msg/callback.go @@ -46,13 +46,14 @@ func callbackBeforeSendSingleMsg(msg *pbChat.SendMsgReq) (canSend bool, err erro if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackBeforeSendSingleMsg.CallbackTimeOut); err != nil { if !config.Config.Callback.CallbackBeforeSendSingleMsg.CallbackFailedContinue { return false, err + } else { + return true, err } } else { if resp.ActionCode == constant.ActionForbidden && resp.ErrCode == constant.CallbackHandleSuccess { return false, nil } } - log.NewDebug(msg.OperationID, utils.GetSelfFuncName()) return true, err } @@ -93,13 +94,14 @@ func callbackBeforeSendGroupMsg(msg *pbChat.SendMsgReq) (canSend bool, err error if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackBeforeSendGroupMsg.CallbackTimeOut); err != nil { if !config.Config.Callback.CallbackBeforeSendGroupMsg.CallbackFailedContinue { return false, err + } else { + return true, err } } else { if resp.ActionCode == constant.ActionForbidden && resp.ErrCode == constant.CallbackHandleSuccess { return false, nil } } - log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), err.Error()) return true, err } @@ -141,6 +143,8 @@ func callbackWordFilter(msg *pbChat.SendMsgReq) (canSend bool, err error) { if !config.Config.Callback.CallbackWordFilter.CallbackFailedContinue { log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), "callback failed and config disable, stop this operation") return false, err + } else { + return true, err } } else { if resp.ActionCode == constant.ActionForbidden && resp.ErrCode == constant.CallbackHandleSuccess { @@ -151,6 +155,5 @@ func callbackWordFilter(msg *pbChat.SendMsgReq) (canSend bool, err error) { } log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), string(msg.MsgData.Content)) } - log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), err.Error()) return true, err } From 319f46406c241fc2f0a79e54c324d4cd984ebd14 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 4 Mar 2022 18:37:55 +0800 Subject: [PATCH 65/67] cfg --- config/config.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/config/config.yaml b/config/config.yaml index c71011247..5316eaf46 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -198,21 +198,21 @@ callback: callbackUrl : "http://127.0.0.1:8080/callback" # 开启关闭操作前后回调的配置 callbackbeforeSendSingleMsg: - enable: true # 回调是否启用 + enable: false # 回调是否启用 callbackTimeOut: 2 # 回调超时时间 CallbackFailedContinue: true # 回调超时是否继续执行代码 callbackAfterSendSingleMsg: - enable: true + enable: false callbackTimeOut: 2 callbackBeforeSendGroupMsg: - enable: true + enable: false callbackTimeOut: 2 CallbackFailedContinue: true callbackAfterSendGroupMsg: - enable: true + enable: false callbackTimeOut: 2 callbackWordFilter: - enable: true + enable: false callbackTimeOut: 2 CallbackFailedContinue: false From 127e5af6f3daec56cb422a902e21244ce0971205 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 4 Mar 2022 18:44:38 +0800 Subject: [PATCH 66/67] cfg --- config/config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config.yaml b/config/config.yaml index 5316eaf46..9a9e1ec6c 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -214,7 +214,7 @@ callback: callbackWordFilter: enable: false callbackTimeOut: 2 - CallbackFailedContinue: false + CallbackFailedContinue: true notification: From e734b000dea2e93032e73cb6147df7080ecb8f50 Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Fri, 4 Mar 2022 19:01:32 +0800 Subject: [PATCH 67/67] log --- pkg/common/db/mysql_model/im_mysql_msg_model/chat_log_model.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/common/db/mysql_model/im_mysql_msg_model/chat_log_model.go b/pkg/common/db/mysql_model/im_mysql_msg_model/chat_log_model.go index fef4c1fb2..99c099ac4 100644 --- a/pkg/common/db/mysql_model/im_mysql_msg_model/chat_log_model.go +++ b/pkg/common/db/mysql_model/im_mysql_msg_model/chat_log_model.go @@ -9,6 +9,7 @@ package im_mysql_msg_model import ( "Open_IM/pkg/common/constant" "Open_IM/pkg/common/db" + "Open_IM/pkg/common/log" pbMsg "Open_IM/pkg/proto/chat" "Open_IM/pkg/proto/sdk_ws" "Open_IM/pkg/utils" @@ -45,5 +46,6 @@ func InsertMessageToChatLog(msg pbMsg.MsgDataToMQ) error { } chatLog.CreateTime = utils.UnixMillSecondToTime(msg.MsgData.CreateTime) chatLog.SendTime = utils.UnixMillSecondToTime(msg.MsgData.SendTime) + log.NewDebug("test", "this is ", chatLog) return dbConn.Table("chat_logs").Create(chatLog).Error }