You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
126 lines
4.4 KiB
126 lines
4.4 KiB
/*
|
|
** description("").
|
|
** copyright('Open_IM,www.Open_IM.io').
|
|
** author("fg,Gordon@tuoyun.net").
|
|
** time(2021/5/21 15:29).
|
|
*/
|
|
package gate
|
|
|
|
import (
|
|
"Open_IM/pkg/common/constant"
|
|
"Open_IM/pkg/common/log"
|
|
pbRtc "Open_IM/pkg/proto/rtc"
|
|
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
|
"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 := open_im_sdk.GetMaxAndMinSeqReq{}
|
|
if err := proto.Unmarshal(m.Data, &data); err != nil {
|
|
log.Error(operationID, "Decode Data 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 := open_im_sdk.MsgData{}
|
|
if err := proto.Unmarshal(m.Data, &data); err != nil {
|
|
log.Error(operationID, "Decode Data 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 Data 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 := open_im_sdk.PullMessageBySeqListReq{}
|
|
if err := proto.Unmarshal(m.Data, &data); err != nil {
|
|
log.Error(operationID, "Decode Data 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 := open_im_sdk.SetAppBackgroundStatusReq{}
|
|
if err := proto.Unmarshal(m.Data, &data); err != nil {
|
|
log.Error(operationID, "Decode Data 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
|
|
}
|