callback add

pull/168/head
wangchuxiao 3 years ago
parent 0bed7ee669
commit dcfd802757

@ -8,7 +8,7 @@ etcd:
etcdAddr: [ 127.0.0.1:2379 ] #单机部署时,默认即可 etcdAddr: [ 127.0.0.1:2379 ] #单机部署时,默认即可
mysql: mysql:
dbMysqlAddress: [ 43.128.5.63:13306 ] #mysql地址 目前仅支持单机,默认即可 dbMysqlAddress: [ 127.0.0.1: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: [ 43.128.5.63:37017 ] #redis地址 目前仅支持单机,默认即可 dbAddress: [ 127.0.0.1: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: 43.128.5.63:16379 #redis地址 目前仅支持单机,默认即可 dbAddress: 127.0.0.1:16379 #redis地址 目前仅支持单机,默认即可
dbMaxIdle: 128 dbMaxIdle: 128
dbMaxActive: 0 dbMaxActive: 0
dbIdleTimeout: 120 dbIdleTimeout: 120

@ -42,6 +42,7 @@ func init() {
return return
} }
} }
// 自动化桶public的代码
//err = minioClient.SetBucketPolicy(context.Background(), config.Config.Credential.Minio.Bucket, policy.BucketPolicyReadWrite) //err = minioClient.SetBucketPolicy(context.Background(), config.Config.Credential.Minio.Bucket, policy.BucketPolicyReadWrite)
//if err != nil { //if err != nil {
// log.NewError("", utils.GetSelfFuncName(), "SetBucketPolicy failed please set in ", err.Error()) // log.NewError("", utils.GetSelfFuncName(), "SetBucketPolicy failed please set in ", err.Error())

@ -12,16 +12,19 @@ import (
func callbackBeforeSendSingleMsg(msg *pbChat.SendMsgReq) (canSend bool, err error) { func callbackBeforeSendSingleMsg(msg *pbChat.SendMsgReq) (canSend bool, err error) {
log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg) 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 return true, nil
} }
req := cbApi.CallbackBeforeSendSingleMsgReq{CommonCallbackReq:cbApi.CommonCallbackReq{ req := cbApi.CallbackBeforeSendSingleMsgReq{CommonCallbackReq:cbApi.CommonCallbackReq{
}} }}
resp := &cbApi.CallbackBeforeSendSingleMsgResp{CommonCallbackResp:cbApi.CommonCallbackResp{ resp := &cbApi.CallbackBeforeSendSingleMsgResp{CommonCallbackResp:cbApi.CommonCallbackResp{
}} }}
defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, resp)
utils.CopyStructFields(req, msg.MsgData) 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{ if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackbeforeSendSingleMsg.CallbackTimeOut); err != nil{
return false, err if !config.Config.Callback.CallbackbeforeSendSingleMsg.CallbackFailedContinue {
return false, err
}
} }
if resp.ActionCode == constant.ActionForbidden { if resp.ActionCode == constant.ActionForbidden {
return false, nil return false, nil
@ -32,13 +35,14 @@ func callbackBeforeSendSingleMsg(msg *pbChat.SendMsgReq) (canSend bool, err erro
func callbackAfterSendSingleMsg(msg *pbChat.SendMsgReq) error { func callbackAfterSendSingleMsg(msg *pbChat.SendMsgReq) error {
log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg) 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 return nil
} }
req := cbApi.CallbackAfterSendSingleMsgReq{CommonCallbackReq: cbApi.CommonCallbackReq{}} req := cbApi.CallbackAfterSendSingleMsgReq{CommonCallbackReq: cbApi.CommonCallbackReq{}}
resp := &cbApi.CallbackAfterSendSingleMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}} resp := &cbApi.CallbackAfterSendSingleMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}}
defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, resp)
utils.CopyStructFields(req, msg.MsgData) 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 err
} }
return nil return nil
@ -47,14 +51,17 @@ func callbackAfterSendSingleMsg(msg *pbChat.SendMsgReq) error {
func callbackBeforeSendGroupMsg(msg *pbChat.SendMsgReq) (canSend bool, err error) { func callbackBeforeSendGroupMsg(msg *pbChat.SendMsgReq) (canSend bool, err error) {
log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg) 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 return true, nil
} }
req := cbApi.CallbackBeforeSendSingleMsgReq{CommonCallbackReq: cbApi.CommonCallbackReq{}} req := cbApi.CallbackBeforeSendSingleMsgReq{CommonCallbackReq: cbApi.CommonCallbackReq{}}
resp := &cbApi.CallbackBeforeSendGroupMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}} resp := &cbApi.CallbackBeforeSendGroupMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}}
defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, resp)
utils.CopyStructFields(req, msg.MsgData) 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{ if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackBeforeSendGroupMsg.CallbackTimeOut); err != nil {
return false, nil if !config.Config.Callback.CallbackBeforeSendGroupMsg.CallbackFailedContinue {
return false, nil
}
} }
if resp.ActionCode == constant.ActionForbidden { if resp.ActionCode == constant.ActionForbidden {
return false, nil return false, nil
@ -64,9 +71,16 @@ func callbackBeforeSendGroupMsg(msg *pbChat.SendMsgReq) (canSend bool, err error
func callbackAfterSendGroupMsg(msg *pbChat.SendMsgReq) error { func callbackAfterSendGroupMsg(msg *pbChat.SendMsgReq) error {
log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg) 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 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 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 { if !config.Config.Callback.CallbackWordFilter.Enable || msg.MsgData.ContentType != constant.Text {
return true, nil return true, nil
} }
req := cbApi.CallBackWordFilterReq{ req := cbApi.CallbackWordFilterReq{CommonCallbackReq: cbApi.CommonCallbackReq{}}
CommonCallbackReq: cbApi.CommonCallbackReq{}, resp := &cbApi.CallbackWordFilterResp{CommonCallbackResp: cbApi.CommonCallbackResp{}}
} defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, resp)
resp := cbApi.CallBackWordFilterResp{CommonCallbackResp: cbApi.CommonCallbackResp{}}
utils.CopyStructFields(&req, msg.MsgData) utils.CopyStructFields(&req, msg.MsgData)
if err := http.PostReturn(msg.OperationID, req, &resp, config.Config.Callback.CallbackWordFilter.CallbackTimeOut); err != nil { if err := http.PostReturn(msg.OperationID, req, resp, config.Config.Callback.CallbackWordFilter.CallbackTimeOut); err != nil {
return false, err if !config.Config.Callback.CallbackWordFilter.CallbackFailedContinue {
return false, err
}
}
if resp.ActionCode == constant.ActionForbidden {
return false, nil
} }
msg.MsgData.Content = resp.Content msg.MsgData.Content = resp.Content
return true, nil return true, nil

@ -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) log.NewError(pb.OperationID, utils.GetSelfFuncName(), "CallbackBeforeSendMsg failed", err.Error(), pb.MsgData)
} }
if !canSend { 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) return returnMsg(&replay, pb, 201, "callback result stop rpc and return", "", 0)
} }
switch pb.MsgData.SessionType { switch pb.MsgData.SessionType {

@ -164,28 +164,41 @@ func GetRangeDate(from, to time.Time) [][2]time.Time {
} }
// month // month
case !isInOneMonth(from, to): case !isInOneMonth(from, to):
for i := 0; ; i++ { if to.Sub(from) < time.Hour * 24 * 30 {
if i == 0 { for i := 0; ; i++ {
fromTime := from fromTime := from.Add(time.Hour * 24 * time.Duration(i))
toTime := getFirstDateOfNextNMonth(fromTime, 1) 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{ times = append(times, [2]time.Time{
fromTime, toTime, fromTime, toTime,
}) })
} else { }
fromTime := getFirstDateOfNextNMonth(from, i) } else {
toTime := getFirstDateOfNextNMonth(fromTime, 1) for i := 0; ; i++ {
if toTime.After(to) { if i == 0 {
toTime = to 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{ times = append(times, [2]time.Time{
fromTime, toTime, fromTime, toTime,
}) })
break
} }
times = append(times, [2]time.Time{
fromTime, toTime,
})
}
}
} }
} }
return times return times

@ -1,12 +1,16 @@
package call_back_struct package call_back_struct
type singleMsg struct { type msg struct {
SendID string `json:"sendID"` SendID string `json:"sendID"`
RecvID string `json:"recvID"`
ClientMsgID string `json:"clientMsgID"` ClientMsgID string `json:"clientMsgID"`
ServerMsgID string `json:"serverMsgId"` ServerMsgID string `json:"serverMsgId"`
SendTime int64 `json:"sendTime"`
CreateTime int64 `json:"createTime"` CreateTime int64 `json:"createTime"`
Content []byte `json:"content"`
}
type singleMsg struct {
msg
RecvID string `json:"recvID"`
} }
type CallbackBeforeSendSingleMsgReq struct { type CallbackBeforeSendSingleMsgReq struct {
@ -16,6 +20,7 @@ type CallbackBeforeSendSingleMsgReq struct {
type CallbackBeforeSendSingleMsgResp struct { type CallbackBeforeSendSingleMsgResp struct {
CommonCallbackResp CommonCallbackResp
singleMsg
} }
type CallbackAfterSendSingleMsgReq struct { type CallbackAfterSendSingleMsgReq struct {
@ -28,18 +33,22 @@ type CallbackAfterSendSingleMsgResp struct {
} }
type groupMsg struct { type groupMsg struct {
msg
GroupID string `json:"groupID"`
} }
type CallbackBeforeSendGroupMsgReq struct { type CallbackBeforeSendGroupMsgReq struct {
CommonCallbackReq CommonCallbackReq
groupMsg
} }
type CallbackBeforeSendGroupMsgResp struct { type CallbackBeforeSendGroupMsgResp struct {
CommonCallbackResp CommonCallbackResp
groupMsg
} }
type CallbackAfterSendGroupMsgReq struct { type CallbackAfterSendGroupMsgReq struct {
groupMsg
CommonCallbackReq CommonCallbackReq
} }
@ -47,15 +56,12 @@ type CallbackAfterSendGroupMsgResp struct {
CommonCallbackResp CommonCallbackResp
} }
type CallBackWordFilterReq struct { type CallbackWordFilterReq struct {
CommonCallbackReq CommonCallbackReq
Content []byte `json:"content"` Content []byte `json:"content"`
SendID string `json:"SendID"`
RecvID string `json:"RecvID"`
GroupID string `json:"GroupID"`
} }
type CallBackWordFilterResp struct { type CallbackWordFilterResp struct {
CommonCallbackResp CommonCallbackResp
Content []byte `json:"content"` Content []byte `json:"content"`
} }

Loading…
Cancel
Save