diff --git a/internal/msg_gateway/gate/callback.go b/internal/msg_gateway/gate/callback.go index e0498f615..b65bfa9ae 100644 --- a/internal/msg_gateway/gate/callback.go +++ b/internal/msg_gateway/gate/callback.go @@ -28,7 +28,7 @@ func callbackUserOnline(operationID, userID string, platformID int, token string Seq: int(time.Now().UnixNano() / 1e6), } callbackUserOnlineResp := &cbApi.CallbackUserOnlineResp{CommonCallbackResp: callbackResp} - if err := http.PostReturn(config.Config.Callback.CallbackUrl, callbackUserOnlineReq, callbackUserOnlineResp, config.Config.Callback.CallbackUserOnline.CallbackTimeOut); err != nil { + if err := http.PostReturn(config.Config.Callback.CallbackUrl, constant.CallbackUserOnlineCommand, callbackUserOnlineReq, callbackUserOnlineResp, config.Config.Callback.CallbackUserOnline.CallbackTimeOut); err != nil { callbackResp.ErrCode = http2.StatusInternalServerError callbackResp.ErrMsg = err.Error() } @@ -53,7 +53,7 @@ func callbackUserOffline(operationID, userID string, platformID int) cbApi.Commo Seq: int(time.Now().UnixNano() / 1e6), } callbackUserOfflineResp := &cbApi.CallbackUserOfflineResp{CommonCallbackResp: callbackResp} - if err := http.PostReturn(config.Config.Callback.CallbackUrl, callbackOfflineReq, callbackUserOfflineResp, config.Config.Callback.CallbackUserOffline.CallbackTimeOut); err != nil { + if err := http.PostReturn(config.Config.Callback.CallbackUrl, constant.CallbackUserOfflineCommand, callbackOfflineReq, callbackUserOfflineResp, config.Config.Callback.CallbackUserOffline.CallbackTimeOut); err != nil { callbackResp.ErrCode = http2.StatusInternalServerError callbackResp.ErrMsg = err.Error() } @@ -78,7 +78,7 @@ func callbackUserKickOff(operationID string, userID string, platformID int) cbAp Seq: int(time.Now().UnixNano() / 1e6), } callbackUserKickOffResp := &cbApi.CallbackUserKickOffResp{CommonCallbackResp: callbackResp} - if err := http.PostReturn(config.Config.Callback.CallbackUrl, callbackUserKickOffReq, callbackUserKickOffResp, config.Config.Callback.CallbackUserOffline.CallbackTimeOut); err != nil { + if err := http.PostReturn(config.Config.Callback.CallbackUrl, constant.CallbackUserKickOffCommand, callbackUserKickOffReq, callbackUserKickOffResp, config.Config.Callback.CallbackUserOffline.CallbackTimeOut); err != nil { callbackResp.ErrCode = http2.StatusInternalServerError callbackResp.ErrMsg = err.Error() } diff --git a/internal/push/logic/callback.go b/internal/push/logic/callback.go index 788a6e6e6..fc82cb120 100644 --- a/internal/push/logic/callback.go +++ b/internal/push/logic/callback.go @@ -37,7 +37,7 @@ func callbackOfflinePush(operationID string, userIDList []string, msg *commonPb. Content: callback.GetContent(msg), } resp := &cbApi.CallbackBeforePushResp{CommonCallbackResp: &callbackResp} - if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackOfflinePush.CallbackTimeOut); err != nil { + if err := http.PostReturn(config.Config.Callback.CallbackUrl, constant.CallbackOfflinePushCommand, req, resp, config.Config.Callback.CallbackOfflinePush.CallbackTimeOut); err != nil { callbackResp.ErrCode = http2.StatusInternalServerError callbackResp.ErrMsg = err.Error() if !config.Config.Callback.CallbackOfflinePush.CallbackFailedContinue { @@ -85,7 +85,7 @@ func callbackOnlinePush(operationID string, userIDList []string, msg *commonPb.M Content: callback.GetContent(msg), } resp := &cbApi.CallbackBeforePushResp{CommonCallbackResp: &callbackResp} - if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackOnlinePush.CallbackTimeOut); err != nil { + if err := http.PostReturn(config.Config.Callback.CallbackUrl, constant.CallbackOnlinePushCommand, req, resp, config.Config.Callback.CallbackOnlinePush.CallbackTimeOut); err != nil { callbackResp.ErrCode = http2.StatusInternalServerError callbackResp.ErrMsg = err.Error() if !config.Config.Callback.CallbackOnlinePush.CallbackFailedContinue { @@ -127,7 +127,7 @@ func callbackBeforeSuperGroupOnlinePush(operationID string, groupID string, msg Content: callback.GetContent(msg), } resp := &cbApi.CallbackBeforeSuperGroupOnlinePushResp{CommonCallbackResp: &callbackResp} - if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackBeforeSuperGroupOnlinePush.CallbackTimeOut); err != nil { + if err := http.PostReturn(config.Config.Callback.CallbackUrl, constant.CallbackSuperGroupOnlinePushCommand, req, resp, config.Config.Callback.CallbackBeforeSuperGroupOnlinePush.CallbackTimeOut); err != nil { callbackResp.ErrCode = http2.StatusInternalServerError callbackResp.ErrMsg = err.Error() if !config.Config.Callback.CallbackBeforeSuperGroupOnlinePush.CallbackFailedContinue { diff --git a/internal/rpc/friend/callback.go b/internal/rpc/friend/callback.go index 2ccec870e..88a9ac11a 100644 --- a/internal/rpc/friend/callback.go +++ b/internal/rpc/friend/callback.go @@ -30,7 +30,7 @@ func callbackBeforeAddFriend(req *pbFriend.AddFriendReq) cbApi.CommonCallbackRes } //utils.CopyStructFields(req, msg.MsgData) defer log.NewDebug(req.CommID.OperationID, utils.GetSelfFuncName(), commonCallbackReq, *resp) - if err := http.PostReturn(config.Config.Callback.CallbackUrl, commonCallbackReq, resp, config.Config.Callback.CallbackBeforeAddFriend.CallbackTimeOut); err != nil { + if err := http.PostReturn(config.Config.Callback.CallbackUrl, constant.CallbackBeforeAddFriendCommand, commonCallbackReq, resp, config.Config.Callback.CallbackBeforeAddFriend.CallbackTimeOut); err != nil { callbackResp.ErrCode = http2.StatusInternalServerError callbackResp.ErrMsg = err.Error() if !config.Config.Callback.CallbackBeforeAddFriend.CallbackFailedContinue { diff --git a/internal/rpc/msg/callback.go b/internal/rpc/msg/callback.go index e60a1ff3c..a3fb41e39 100644 --- a/internal/rpc/msg/callback.go +++ b/internal/rpc/msg/callback.go @@ -51,7 +51,7 @@ func callbackBeforeSendSingleMsg(msg *pbChat.SendMsgReq) cbApi.CommonCallbackRes } //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, constant.CallbackBeforeSendSingleMsgCommand, req, resp, config.Config.Callback.CallbackBeforeSendSingleMsg.CallbackTimeOut); err != nil { callbackResp.ErrCode = http2.StatusInternalServerError callbackResp.ErrMsg = err.Error() if !config.Config.Callback.CallbackBeforeSendSingleMsg.CallbackFailedContinue { @@ -79,7 +79,7 @@ func callbackAfterSendSingleMsg(msg *pbChat.SendMsgReq) cbApi.CommonCallbackResp } resp := &cbApi.CallbackAfterSendSingleMsgResp{CommonCallbackResp: &callbackResp} 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, constant.CallbackAfterSendSingleMsgCommand, req, resp, config.Config.Callback.CallbackAfterSendSingleMsg.CallbackTimeOut); err != nil { callbackResp.ErrCode = http2.StatusInternalServerError callbackResp.ErrMsg = err.Error() return callbackResp @@ -101,7 +101,7 @@ func callbackBeforeSendGroupMsg(msg *pbChat.SendMsgReq) cbApi.CommonCallbackResp } resp := &cbApi.CallbackBeforeSendGroupMsgResp{CommonCallbackResp: &callbackResp} 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 err := http.PostReturn(config.Config.Callback.CallbackUrl, constant.CallbackBeforeSendGroupMsgCommand, req, resp, config.Config.Callback.CallbackBeforeSendGroupMsg.CallbackTimeOut); err != nil { callbackResp.ErrCode = http2.StatusInternalServerError callbackResp.ErrMsg = err.Error() if !config.Config.Callback.CallbackBeforeSendGroupMsg.CallbackFailedContinue { @@ -129,7 +129,7 @@ func callbackAfterSendGroupMsg(msg *pbChat.SendMsgReq) cbApi.CommonCallbackResp } resp := &cbApi.CallbackAfterSendGroupMsgResp{CommonCallbackResp: &callbackResp} 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 { + if err := http.PostReturn(config.Config.Callback.CallbackUrl, constant.CallbackAfterSendGroupMsgCommand, req, resp, config.Config.Callback.CallbackAfterSendGroupMsg.CallbackTimeOut); err != nil { callbackResp.ErrCode = http2.StatusInternalServerError callbackResp.ErrMsg = err.Error() return callbackResp @@ -150,7 +150,7 @@ func callbackWordFilter(msg *pbChat.SendMsgReq) cbApi.CommonCallbackResp { } resp := &cbApi.CallbackWordFilterResp{CommonCallbackResp: &callbackResp} 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 err := http.PostReturn(config.Config.Callback.CallbackUrl, constant.CallbackWordFilterCommand, req, resp, config.Config.Callback.CallbackWordFilter.CallbackTimeOut); err != nil { callbackResp.ErrCode = http2.StatusInternalServerError callbackResp.ErrMsg = err.Error() if !config.Config.Callback.CallbackWordFilter.CallbackFailedContinue { diff --git a/pkg/common/http/http_client.go b/pkg/common/http/http_client.go index e227da91e..46ddb2ba8 100644 --- a/pkg/common/http/http_client.go +++ b/pkg/common/http/http_client.go @@ -11,6 +11,7 @@ import ( "encoding/json" "io/ioutil" "net/http" + urlLib "net/url" "time" ) @@ -34,6 +35,7 @@ func Post(url string, data interface{}, timeOutSecond int) (content []byte, err if err != nil { return nil, err } + req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr)) if err != nil { return nil, err @@ -54,7 +56,10 @@ func Post(url string, data interface{}, timeOutSecond int) (content []byte, err return result, nil } -func PostReturn(url string, input, output interface{}, timeOut int) error { +func PostReturn(url, callbackCommand string, input, output interface{}, timeOut int) error { + v := urlLib.Values{} + v.Set("callbackCommand", callbackCommand) + url = url + "?" + v.Encode() b, err := Post(url, input, timeOut) if err != nil { return err