mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
merge code
This commit is contained in:
parent
7d8d314962
commit
0bed7ee669
@ -8,7 +8,7 @@ etcd:
|
|||||||
etcdAddr: [ 127.0.0.1:2379 ] #单机部署时,默认即可
|
etcdAddr: [ 127.0.0.1:2379 ] #单机部署时,默认即可
|
||||||
|
|
||||||
mysql:
|
mysql:
|
||||||
dbMysqlAddress: [ 127.0.0.1:13306 ] #mysql地址 目前仅支持单机,默认即可
|
dbMysqlAddress: [ 43.128.5.63:13306 ] #mysql地址 目前仅支持单机,默认即可
|
||||||
dbMysqlUserName: root #mysql用户名,建议修改
|
dbMysqlUserName: root #mysql用户名,建议修改
|
||||||
dbMysqlPassword: openIM # mysql密码,建议修改
|
dbMysqlPassword: openIM # mysql密码,建议修改
|
||||||
dbMysqlDatabaseName: openIM_v2 #默认即可
|
dbMysqlDatabaseName: openIM_v2 #默认即可
|
||||||
@ -19,7 +19,7 @@ mysql:
|
|||||||
dbMaxLifeTime: 120
|
dbMaxLifeTime: 120
|
||||||
|
|
||||||
mongo:
|
mongo:
|
||||||
dbAddress: [ 127.0.0.1:37017 ] #redis地址 目前仅支持单机,默认即可
|
dbAddress: [ 43.128.5.63:37017 ] #redis地址 目前仅支持单机,默认即可
|
||||||
dbDirect: false
|
dbDirect: false
|
||||||
dbTimeout: 10
|
dbTimeout: 10
|
||||||
dbDatabase: openIM #mongo db 默认即可
|
dbDatabase: openIM #mongo db 默认即可
|
||||||
@ -30,7 +30,7 @@ mongo:
|
|||||||
dbRetainChatRecords: 3650 #mongo保存离线消息时间(天),根据需求修改
|
dbRetainChatRecords: 3650 #mongo保存离线消息时间(天),根据需求修改
|
||||||
|
|
||||||
redis:
|
redis:
|
||||||
dbAddress: 127.0.0.1:16379 #redis地址 目前仅支持单机,默认即可
|
dbAddress: 43.128.5.63:16379 #redis地址 目前仅支持单机,默认即可
|
||||||
dbMaxIdle: 128
|
dbMaxIdle: 128
|
||||||
dbMaxActive: 0
|
dbMaxActive: 0
|
||||||
dbIdleTimeout: 120
|
dbIdleTimeout: 120
|
||||||
@ -178,13 +178,6 @@ tokenpolicy:
|
|||||||
# Token effective time day as a unit
|
# Token effective time day as a unit
|
||||||
accessExpire: 3650 #token过期时间(天) 默认即可
|
accessExpire: 3650 #token过期时间(天) 默认即可
|
||||||
|
|
||||||
messagecallback:
|
|
||||||
callbackSwitch: false
|
|
||||||
callbackUrl: "http://www.xxx.com/msg/judge"
|
|
||||||
#TimeOut use second as unit
|
|
||||||
callbackTimeOut: 10
|
|
||||||
messagejudge:
|
|
||||||
isJudgeFriend: true
|
|
||||||
# c2c:
|
# c2c:
|
||||||
# callbackBeforeSendMsg:
|
# callbackBeforeSendMsg:
|
||||||
# switch: false
|
# switch: false
|
||||||
@ -199,6 +192,31 @@ iospush:
|
|||||||
pushSound: "xxx"
|
pushSound: "xxx"
|
||||||
badgeCount: true
|
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:
|
notification:
|
||||||
groupCreated:
|
groupCreated:
|
||||||
conversation:
|
conversation:
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"Open_IM/pkg/common/config"
|
"Open_IM/pkg/common/config"
|
||||||
"Open_IM/pkg/common/constant"
|
"Open_IM/pkg/common/constant"
|
||||||
"Open_IM/pkg/common/log"
|
"Open_IM/pkg/common/log"
|
||||||
|
"Open_IM/pkg/common/token_verify"
|
||||||
_ "Open_IM/pkg/common/token_verify"
|
_ "Open_IM/pkg/common/token_verify"
|
||||||
"Open_IM/pkg/utils"
|
"Open_IM/pkg/utils"
|
||||||
"github.com/gin-gonic/gin"
|
"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()})
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//ok, _ := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
ok, _ := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||||
//if !ok {
|
if !ok {
|
||||||
// log.NewError("", utils.GetSelfFuncName(), "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
log.NewError("", utils.GetSelfFuncName(), "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||||
// c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||||
// return
|
return
|
||||||
//}
|
}
|
||||||
var stsOpts cr.STSAssumeRoleOptions
|
var stsOpts cr.STSAssumeRoleOptions
|
||||||
stsOpts.AccessKey = config.Config.Credential.Minio.AccessKeyID
|
stsOpts.AccessKey = config.Config.Credential.Minio.AccessKeyID
|
||||||
stsOpts.SecretKey = config.Config.Credential.Minio.SecretAccessKey
|
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()})
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||||
return
|
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.SessionToken = v.SessionToken
|
||||||
resp.SecretAccessKey = v.SecretAccessKey
|
resp.SecretAccessKey = v.SecretAccessKey
|
||||||
resp.AccessKeyID = v.AccessKeyID
|
resp.AccessKeyID = v.AccessKeyID
|
||||||
|
@ -12,10 +12,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type resetPasswordRequest struct {
|
type resetPasswordRequest struct {
|
||||||
VerificationCode string `json:"verificationCode"`
|
VerificationCode string `json:"verificationCode" binding:"required"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
PhoneNumber string `json:"phoneNumber"`
|
PhoneNumber string `json:"phoneNumber"`
|
||||||
NewPassword string `json:"newPassword"`
|
NewPassword string `json:"newPassword" binding:"required"`
|
||||||
OperationID string `json:"operationID"`
|
OperationID string `json:"operationID"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1
internal/rpc/auth/callback.go
Normal file
1
internal/rpc/auth/callback.go
Normal file
@ -0,0 +1 @@
|
|||||||
|
package auth
|
1
internal/rpc/friend/callback.go
Normal file
1
internal/rpc/friend/callback.go
Normal file
@ -0,0 +1 @@
|
|||||||
|
package friend
|
9
internal/rpc/group/callback.go
Normal file
9
internal/rpc/group/callback.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package group
|
||||||
|
|
||||||
|
import (
|
||||||
|
pbGroup "Open_IM/pkg/proto/group"
|
||||||
|
)
|
||||||
|
|
||||||
|
func callbackBeforeCreateGroup(req *pbGroup.CreateGroupReq) (bool, error) {
|
||||||
|
return true, nil
|
||||||
|
}
|
@ -76,7 +76,12 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
|
|||||||
log.NewError(req.OperationID, "CheckAccess false ", req.OpUserID, req.OwnerUserID)
|
log.NewError(req.OperationID, "CheckAccess false ", req.OpUserID, req.OwnerUserID)
|
||||||
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
|
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
|
//Time stamp + MD5 to generate group chat id
|
||||||
groupId := utils.Md5(strconv.FormatInt(time.Now().UnixNano(), 10))
|
groupId := utils.Md5(strconv.FormatInt(time.Now().UnixNano(), 10))
|
||||||
//to group
|
//to group
|
||||||
@ -84,7 +89,7 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
|
|||||||
utils.CopyStructFields(&groupInfo, req.GroupInfo)
|
utils.CopyStructFields(&groupInfo, req.GroupInfo)
|
||||||
groupInfo.CreatorUserID = req.OpUserID
|
groupInfo.CreatorUserID = req.OpUserID
|
||||||
groupInfo.GroupID = groupId
|
groupInfo.GroupID = groupId
|
||||||
err := imdb.InsertIntoGroup(groupInfo)
|
err = imdb.InsertIntoGroup(groupInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, "InsertIntoGroup failed, ", err.Error(), groupInfo)
|
log.NewError(req.OperationID, "InsertIntoGroup failed, ", err.Error(), groupInfo)
|
||||||
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, http.WrapError(constant.ErrDB)
|
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, http.WrapError(constant.ErrDB)
|
||||||
|
94
internal/rpc/msg/callback.go
Normal file
94
internal/rpc/msg/callback.go
Normal file
@ -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
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -4,7 +4,6 @@ import (
|
|||||||
"Open_IM/pkg/common/config"
|
"Open_IM/pkg/common/config"
|
||||||
"Open_IM/pkg/common/constant"
|
"Open_IM/pkg/common/constant"
|
||||||
"Open_IM/pkg/common/db"
|
"Open_IM/pkg/common/db"
|
||||||
http2 "Open_IM/pkg/common/http"
|
|
||||||
"Open_IM/pkg/common/log"
|
"Open_IM/pkg/common/log"
|
||||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||||
pbChat "Open_IM/pkg/proto/chat"
|
pbChat "Open_IM/pkg/proto/chat"
|
||||||
@ -12,11 +11,9 @@ import (
|
|||||||
sdk_ws "Open_IM/pkg/proto/sdk_ws"
|
sdk_ws "Open_IM/pkg/proto/sdk_ws"
|
||||||
"Open_IM/pkg/utils"
|
"Open_IM/pkg/utils"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"github.com/garyburd/redigo/redis"
|
"github.com/garyburd/redigo/redis"
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -127,25 +124,26 @@ func (rpc *rpcChat) SendMsg(_ context.Context, pb *pbChat.SendMsgReq) (*pbChat.S
|
|||||||
if !isHistory {
|
if !isHistory {
|
||||||
mReq.IsOnlineOnly = true
|
mReq.IsOnlineOnly = true
|
||||||
}
|
}
|
||||||
mResp := MsgCallBackResp{}
|
|
||||||
if config.Config.MessageCallBack.CallbackSwitch {
|
// callback
|
||||||
bMsg, err := http2.Post(config.Config.MessageCallBack.CallbackUrl, mReq, config.Config.MessageCallBack.CallBackTimeOut)
|
canSend, err := callBackWordFilter(pb)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ErrorByKv("callback to Business server err", pb.OperationID, "args", pb.String(), "err", err.Error())
|
log.NewError(pb.OperationID, utils.GetSelfFuncName(), "CallbackBeforeSendMsg failed", err.Error(), pb.MsgData)
|
||||||
return returnMsg(&replay, pb, http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError), "", 0)
|
}
|
||||||
} else if err = json.Unmarshal(bMsg, &mResp); err != nil {
|
if !canSend {
|
||||||
log.ErrorByKv("ws json Unmarshal err", pb.OperationID, "args", pb.String(), "err", err.Error())
|
log.NewDebug(pb.OperationID, utils.GetSelfFuncName(), "callback result", canSend, "end rpc and return")
|
||||||
return returnMsg(&replay, pb, 200, err.Error(), "", 0)
|
return returnMsg(&replay, pb, 201, "callback result stop rpc and return", "", 0)
|
||||||
} else {
|
|
||||||
if mResp.ErrCode != 0 {
|
|
||||||
return returnMsg(&replay, pb, mResp.ResponseErrCode, mResp.ErrMsg, "", 0)
|
|
||||||
} else {
|
|
||||||
pb.MsgData.Content = []byte(mResp.ResponseResult.ModifiedMsg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
switch pb.MsgData.SessionType {
|
switch pb.MsgData.SessionType {
|
||||||
case constant.SingleChatType:
|
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)
|
isSend := modifyMessageByUserMessageReceiveOpt(pb.MsgData.RecvID, pb.MsgData.SendID, constant.SingleChatType, pb)
|
||||||
if isSend {
|
if isSend {
|
||||||
msgToMQ.MsgData = pb.MsgData
|
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)
|
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)
|
return returnMsg(&replay, pb, 0, "", msgToMQ.MsgData.ServerMsgID, msgToMQ.MsgData.SendTime)
|
||||||
case constant.GroupChatType:
|
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)
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||||
client := pbGroup.NewGroupClient(etcdConn)
|
client := pbGroup.NewGroupClient(etcdConn)
|
||||||
req := &pbGroup.GetGroupAllMemberReq{
|
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)
|
return returnMsg(&replay, pb, 0, "", msgToMQ.MsgData.ServerMsgID, msgToMQ.MsgData.SendTime)
|
||||||
default:
|
default:
|
||||||
return returnMsg(&replay, pb, 203, "unkonwn sessionType", "", 0)
|
return returnMsg(&replay, pb, 203, "unkonwn sessionType", "", 0)
|
||||||
|
1
internal/rpc/user/callback.go
Normal file
1
internal/rpc/user/callback.go
Normal file
@ -0,0 +1 @@
|
|||||||
|
package user
|
1
internal/utils/callback.go
Normal file
1
internal/utils/callback.go
Normal file
@ -0,0 +1 @@
|
|||||||
|
package utils
|
@ -1 +1,17 @@
|
|||||||
package call_back_struct
|
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"`
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
9
pkg/call_back_struct/group.go
Normal file
9
pkg/call_back_struct/group.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package call_back_struct
|
||||||
|
|
||||||
|
type CallbackBeforeCreateGroupReq struct {
|
||||||
|
CommonCallbackReq
|
||||||
|
}
|
||||||
|
|
||||||
|
type CallbackAfterCreateGroupResp struct {
|
||||||
|
CommonCallbackResp
|
||||||
|
}
|
@ -1 +1,61 @@
|
|||||||
package call_back_struct
|
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"`
|
||||||
|
}
|
||||||
|
@ -19,6 +19,12 @@ var (
|
|||||||
|
|
||||||
var Config config
|
var Config config
|
||||||
|
|
||||||
|
type callBackConfig struct {
|
||||||
|
Enable bool `yaml:"enable"`
|
||||||
|
CallbackTimeOut int `yaml:"callbackTimeOut"`
|
||||||
|
CallbackFailedContinue bool `CallbackFailedContinue`
|
||||||
|
}
|
||||||
|
|
||||||
type config struct {
|
type config struct {
|
||||||
ServerIP string `yaml:"serverip"`
|
ServerIP string `yaml:"serverip"`
|
||||||
ServerVersion string `yaml:"serverversion"`
|
ServerVersion string `yaml:"serverversion"`
|
||||||
@ -167,11 +173,6 @@ type config struct {
|
|||||||
AccessSecret string `yaml:"accessSecret"`
|
AccessSecret string `yaml:"accessSecret"`
|
||||||
AccessExpire int64 `yaml:"accessExpire"`
|
AccessExpire int64 `yaml:"accessExpire"`
|
||||||
}
|
}
|
||||||
MessageCallBack struct {
|
|
||||||
CallbackSwitch bool `yaml:"callbackSwitch"`
|
|
||||||
CallbackUrl string `yaml:"callbackUrl"`
|
|
||||||
CallBackTimeOut int `yaml:"callbackTimeOut"`
|
|
||||||
}
|
|
||||||
MessageJudge struct {
|
MessageJudge struct {
|
||||||
IsJudgeFriend bool `yaml:"isJudgeFriend"`
|
IsJudgeFriend bool `yaml:"isJudgeFriend"`
|
||||||
}
|
}
|
||||||
@ -179,6 +180,15 @@ type config struct {
|
|||||||
PushSound string `yaml:"pushSound"`
|
PushSound string `yaml:"pushSound"`
|
||||||
BadgeCount bool `yaml:"badgeCount"`
|
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 {
|
Notification struct {
|
||||||
///////////////////////group/////////////////////////////
|
///////////////////////group/////////////////////////////
|
||||||
GroupCreated struct {
|
GroupCreated struct {
|
||||||
|
@ -136,6 +136,16 @@ const (
|
|||||||
VerificationCodeForReset = 2
|
VerificationCodeForReset = 2
|
||||||
VerificationCodeForRegisterSuffix = "_forRegister"
|
VerificationCodeForRegisterSuffix = "_forRegister"
|
||||||
VerificationCodeForResetSuffix = "_forReset"
|
VerificationCodeForResetSuffix = "_forReset"
|
||||||
|
|
||||||
|
//callbackCommand
|
||||||
|
CallbackBeforeSendSingleMsgCommand = "callbackBeforeSendSingleMsg"
|
||||||
|
CallbackAfterSendSingleMsgCommand = "callbackAfterSendSingleMsg"
|
||||||
|
CallbackBeforeSendGroupMsgCommand = "callbackBeforeSendGroupMsg"
|
||||||
|
CallbackAfterSendGroupMsgCommand = "callbackAfterSendGroupMsgCommand"
|
||||||
|
CallbackWordFilterCommand = "callbackWordFilterCommand"
|
||||||
|
//actionCode
|
||||||
|
ActionAllow = 0
|
||||||
|
ActionForbidden = 1
|
||||||
)
|
)
|
||||||
|
|
||||||
var ContentType2PushContent = map[int64]string{
|
var ContentType2PushContent = map[int64]string{
|
||||||
|
@ -51,6 +51,7 @@ var (
|
|||||||
ErrAccess = ErrInfo{ErrCode: 801, ErrMsg: AccessMsg.Error()}
|
ErrAccess = ErrInfo{ErrCode: 801, ErrMsg: AccessMsg.Error()}
|
||||||
ErrDB = ErrInfo{ErrCode: 802, ErrMsg: DBMsg.Error()}
|
ErrDB = ErrInfo{ErrCode: 802, ErrMsg: DBMsg.Error()}
|
||||||
ErrArgs = ErrInfo{ErrCode: 8003, ErrMsg: ArgsMsg.Error()}
|
ErrArgs = ErrInfo{ErrCode: 8003, ErrMsg: ArgsMsg.Error()}
|
||||||
|
ErrCallback = ErrInfo{ErrCode: 809, ErrMsg: CallBackMsg.Error()}
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -64,6 +65,7 @@ var (
|
|||||||
AccessMsg = errors.New("no permission")
|
AccessMsg = errors.New("no permission")
|
||||||
DBMsg = errors.New("db failed")
|
DBMsg = errors.New("db failed")
|
||||||
ArgsMsg = errors.New("args failed")
|
ArgsMsg = errors.New("args failed")
|
||||||
|
CallBackMsg = errors.New("callback failed")
|
||||||
|
|
||||||
ThirdPartyMsg = errors.New("third party error")
|
ThirdPartyMsg = errors.New("third party error")
|
||||||
)
|
)
|
||||||
|
@ -53,3 +53,13 @@ func Post(url string, data interface{}, timeOutSecond int) (content []byte, err
|
|||||||
}
|
}
|
||||||
return result, nil
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -2,7 +2,6 @@ package log
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"Open_IM/pkg/common/config"
|
"Open_IM/pkg/common/config"
|
||||||
"bufio"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
@ -33,13 +32,13 @@ func loggerInit(moduleName string) *Logger {
|
|||||||
//All logs will be printed
|
//All logs will be printed
|
||||||
logger.SetLevel(logrus.Level(config.Config.Log.RemainLogLevel))
|
logger.SetLevel(logrus.Level(config.Config.Log.RemainLogLevel))
|
||||||
//Close std console output
|
//Close std console output
|
||||||
src, err := os.OpenFile(os.DevNull, os.O_APPEND|os.O_WRONLY, os.ModeAppend)
|
//src, err := os.OpenFile(os.DevNull, os.O_APPEND|os.O_WRONLY, os.ModeAppend)
|
||||||
if err != nil {
|
//if err != nil {
|
||||||
panic(err.Error())
|
// panic(err.Error())
|
||||||
}
|
//}
|
||||||
writer := bufio.NewWriter(src)
|
//writer := bufio.NewWriter(src)
|
||||||
logger.SetOutput(writer)
|
//logger.SetOutput(writer)
|
||||||
//logger.SetOutput(os.Stdout)
|
logger.SetOutput(os.Stdout)
|
||||||
//Log Console Print Style Setting
|
//Log Console Print Style Setting
|
||||||
logger.SetFormatter(&nested.Formatter{
|
logger.SetFormatter(&nested.Formatter{
|
||||||
TimestampFormat: "2006-01-02 15:04:05.000",
|
TimestampFormat: "2006-01-02 15:04:05.000",
|
||||||
|
@ -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
|
///cms
|
||||||
|
Loading…
x
Reference in New Issue
Block a user