|
|
|
/*
|
|
|
|
** description("").
|
|
|
|
** copyright('Open_IM,www.Open_IM.io').
|
|
|
|
** author("fg,Gordon@tuoyun.net").
|
|
|
|
** time(2021/5/21 15:29).
|
|
|
|
*/
|
|
|
|
package msggateway
|
|
|
|
|
|
|
|
import (
|
|
|
|
"Open_IM/pkg/common/constant"
|
|
|
|
"Open_IM/pkg/common/log"
|
|
|
|
pbRtc "Open_IM/pkg/proto/rtc"
|
|
|
|
sdkws "Open_IM/pkg/proto/sdkws"
|
|
|
|
"github.com/golang/protobuf/proto"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Req struct {
|
|
|
|
ReqIdentifier int32 `json:"reqIdentifier" validate:"required"`
|
|
|
|
Token string `json:"token" `
|
|
|
|
SendID string `json:"sendID" validate:"required"`
|
|
|
|
OperationID string `json:"operationID" validate:"required"`
|
|
|
|
MsgIncr string `json:"msgIncr" validate:"required"`
|
|
|
|
Data []byte `json:"data"`
|
|
|
|
}
|
|
|
|
type Resp struct {
|
|
|
|
ReqIdentifier int32 `json:"reqIdentifier"`
|
|
|
|
MsgIncr string `json:"msgIncr"`
|
|
|
|
OperationID string `json:"operationID"`
|
|
|
|
ErrCode int32 `json:"errCode"`
|
|
|
|
ErrMsg string `json:"errMsg"`
|
|
|
|
Data []byte `json:"data"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type SeqData struct {
|
|
|
|
SeqBegin int64 `mapstructure:"seqBegin" validate:"required"`
|
|
|
|
SeqEnd int64 `mapstructure:"seqEnd" validate:"required"`
|
|
|
|
}
|
|
|
|
type MsgData struct {
|
|
|
|
PlatformID int32 `mapstructure:"platformID" validate:"required"`
|
|
|
|
SessionType int32 `mapstructure:"sessionType" validate:"required"`
|
|
|
|
MsgFrom int32 `mapstructure:"msgFrom" validate:"required"`
|
|
|
|
ContentType int32 `mapstructure:"contentType" validate:"required"`
|
|
|
|
RecvID string `mapstructure:"recvID" validate:"required"`
|
|
|
|
ForceList []string `mapstructure:"forceList"`
|
|
|
|
Content string `mapstructure:"content" validate:"required"`
|
|
|
|
Options map[string]interface{} `mapstructure:"options" validate:"required"`
|
|
|
|
ClientMsgID string `mapstructure:"clientMsgID" validate:"required"`
|
|
|
|
OfflineInfo map[string]interface{} `mapstructure:"offlineInfo" validate:"required"`
|
|
|
|
Ext map[string]interface{} `mapstructure:"ext"`
|
|
|
|
}
|
|
|
|
type MaxSeqResp struct {
|
|
|
|
MaxSeq int64 `json:"maxSeq"`
|
|
|
|
}
|
|
|
|
type PullMessageResp struct {
|
|
|
|
}
|
|
|
|
type SeqListData struct {
|
|
|
|
SeqList []int64 `mapstructure:"seqList" validate:"required"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ws *WServer) argsValidate(m *Req, r int32, operationID string) (isPass bool, errCode int32, errMsg string, returnData interface{}) {
|
|
|
|
switch r {
|
|
|
|
case constant.WSGetNewestSeq:
|
|
|
|
data := sdkws.GetMaxAndMinSeqReq{}
|
|
|
|
if err := proto.Unmarshal(m.Data, &data); err != nil {
|
|
|
|
log.Error(operationID, "Decode Map struct err", err.Error(), r)
|
|
|
|
return false, 203, err.Error(), nil
|
|
|
|
}
|
|
|
|
if err := validate.Struct(data); err != nil {
|
|
|
|
log.Error(operationID, "data args validate err", err.Error(), r)
|
|
|
|
return false, 204, err.Error(), nil
|
|
|
|
|
|
|
|
}
|
|
|
|
return true, 0, "", data
|
|
|
|
case constant.WSSendMsg:
|
|
|
|
data := sdkws.MsgData{}
|
|
|
|
if err := proto.Unmarshal(m.Data, &data); err != nil {
|
|
|
|
log.Error(operationID, "Decode Map struct err", err.Error(), r)
|
|
|
|
return false, 203, err.Error(), nil
|
|
|
|
}
|
|
|
|
if err := validate.Struct(data); err != nil {
|
|
|
|
log.Error(operationID, "data args validate err", err.Error(), r)
|
|
|
|
return false, 204, err.Error(), nil
|
|
|
|
|
|
|
|
}
|
|
|
|
return true, 0, "", data
|
|
|
|
case constant.WSSendSignalMsg:
|
|
|
|
data := pbRtc.SignalReq{}
|
|
|
|
if err := proto.Unmarshal(m.Data, &data); err != nil {
|
|
|
|
log.Error(operationID, "Decode Map struct err", err.Error(), r)
|
|
|
|
return false, 203, err.Error(), nil
|
|
|
|
}
|
|
|
|
if err := validate.Struct(data); err != nil {
|
|
|
|
log.Error(operationID, "data args validate err", err.Error(), r)
|
|
|
|
return false, 204, err.Error(), nil
|
|
|
|
|
|
|
|
}
|
|
|
|
return true, 0, "", &data
|
|
|
|
case constant.WSPullMsgBySeqList:
|
|
|
|
data := sdkws.PullMessageBySeqListReq{}
|
|
|
|
if err := proto.Unmarshal(m.Data, &data); err != nil {
|
|
|
|
log.Error(operationID, "Decode Map struct err", err.Error(), r)
|
|
|
|
return false, 203, err.Error(), nil
|
|
|
|
}
|
|
|
|
if err := validate.Struct(data); err != nil {
|
|
|
|
log.Error(operationID, "data args validate err", err.Error(), r)
|
|
|
|
return false, 204, err.Error(), nil
|
|
|
|
|
|
|
|
}
|
|
|
|
return true, 0, "", data
|
|
|
|
case constant.WsSetBackgroundStatus:
|
|
|
|
data := sdkws.SetAppBackgroundStatusReq{}
|
|
|
|
if err := proto.Unmarshal(m.Data, &data); err != nil {
|
|
|
|
log.Error(operationID, "Decode Map struct err", err.Error(), r)
|
|
|
|
return false, 203, err.Error(), nil
|
|
|
|
}
|
|
|
|
if err := validate.Struct(data); err != nil {
|
|
|
|
log.Error(operationID, "data args validate err", err.Error(), r)
|
|
|
|
return false, 204, err.Error(), nil
|
|
|
|
|
|
|
|
}
|
|
|
|
return true, 0, "", &data
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
return false, 204, "args err", nil
|
|
|
|
}
|