test-errcode
wangchuxiao 2 years ago
parent 745c96349d
commit 549a0aceb0

@ -7,6 +7,7 @@ import (
"OpenIM/pkg/common/config"
"OpenIM/pkg/common/constant"
"OpenIM/pkg/common/log"
"OpenIM/pkg/common/tracelog"
"OpenIM/pkg/discoveryregistry"
"OpenIM/pkg/errs"
"OpenIM/pkg/proto/msg"
@ -31,14 +32,14 @@ type Msg struct {
validate *validator.Validate
}
func SetOptions(options map[string]bool, value bool) {
func (Msg) SetOptions(options map[string]bool, value bool) {
utils.SetSwitchFromOptions(options, constant.IsHistory, value)
utils.SetSwitchFromOptions(options, constant.IsPersistent, value)
utils.SetSwitchFromOptions(options, constant.IsSenderSync, value)
utils.SetSwitchFromOptions(options, constant.IsConversationUpdate, value)
}
func newUserSendMsgReq(params *apistruct.ManagementSendMsgReq) *msg.SendMsgReq {
func (m Msg) newUserSendMsgReq(c *gin.Context, params *apistruct.ManagementSendMsgReq) *msg.SendMsgReq {
var newContent string
var err error
switch params.ContentType {
@ -66,17 +67,16 @@ func newUserSendMsgReq(params *apistruct.ManagementSendMsgReq) *msg.SendMsgReq {
}
options := make(map[string]bool, 5)
if params.IsOnlineOnly {
SetOptions(options, false)
m.SetOptions(options, false)
}
if params.NotOfflinePush {
utils.SetSwitchFromOptions(options, constant.IsOfflinePush, false)
}
if params.ContentType == constant.CustomOnlineOnly {
SetOptions(options, false)
m.SetOptions(options, false)
} else if params.ContentType == constant.CustomNotTriggerConversation {
utils.SetSwitchFromOptions(options, constant.IsConversationUpdate, false)
}
pbData := msg.SendMsgReq{
MsgData: &sdkws.MsgData{
SendID: params.SendID,
@ -100,91 +100,87 @@ func newUserSendMsgReq(params *apistruct.ManagementSendMsgReq) *msg.SendMsgReq {
tips.JsonDetail = utils.StructToJsonString(params.Content)
pbData.MsgData.Content, err = proto.Marshal(&tips)
if err != nil {
log.Error(params.OperationID, "Marshal failed ", err.Error(), tips.String())
log.Error(tracelog.GetOperationID(c), "Marshal failed ", err.Error(), tips.String())
}
}
return &pbData
}
func (o *Msg) client() (msg.MsgClient, error) {
conn, err := o.c.GetConn(config.Config.RpcRegisterName.OpenImMsgName)
func (m *Msg) client() (msg.MsgClient, error) {
conn, err := m.c.GetConn(config.Config.RpcRegisterName.OpenImMsgName)
if err != nil {
return nil, err
}
return msg.NewMsgClient(conn), nil
}
func (o *Msg) GetSeq(c *gin.Context) {
a2r.Call(msg.MsgClient.GetMaxAndMinSeq, o.client, c)
}
func (o *Msg) SendMsg(c *gin.Context) {
a2r.Call(msg.MsgClient.SendMsg, o.client, c)
func (m *Msg) GetSeq(c *gin.Context) {
a2r.Call(msg.MsgClient.GetMaxAndMinSeq, m.client, c)
}
func (o *Msg) PullMsgBySeqs(c *gin.Context) {
a2r.Call(msg.MsgClient.PullMessageBySeqs, o.client, c)
func (m *Msg) PullMsgBySeqs(c *gin.Context) {
a2r.Call(msg.MsgClient.PullMessageBySeqs, m.client, c)
}
func (o *Msg) DelMsg(c *gin.Context) {
a2r.Call(msg.MsgClient.DelMsgs, o.client, c)
func (m *Msg) DelMsg(c *gin.Context) {
a2r.Call(msg.MsgClient.DelMsgs, m.client, c)
}
func (o *Msg) DelSuperGroupMsg(c *gin.Context) {
a2r.Call(msg.MsgClient.DelSuperGroupMsg, o.client, c)
func (m *Msg) DelSuperGroupMsg(c *gin.Context) {
a2r.Call(msg.MsgClient.DelSuperGroupMsg, m.client, c)
}
func (o *Msg) ClearMsg(c *gin.Context) {
a2r.Call(msg.MsgClient.ClearMsg, o.client, c)
func (m *Msg) ClearMsg(c *gin.Context) {
a2r.Call(msg.MsgClient.ClearMsg, m.client, c)
}
func (o *Msg) SetMessageReactionExtensions(c *gin.Context) {
a2r.Call(msg.MsgClient.SetMessageReactionExtensions, o.client, c)
func (m *Msg) SetMessageReactionExtensions(c *gin.Context) {
a2r.Call(msg.MsgClient.SetMessageReactionExtensions, m.client, c)
}
func (o *Msg) GetMessageListReactionExtensions(c *gin.Context) {
a2r.Call(msg.MsgClient.GetMessagesReactionExtensions, o.client, c)
func (m *Msg) GetMessageListReactionExtensions(c *gin.Context) {
a2r.Call(msg.MsgClient.GetMessagesReactionExtensions, m.client, c)
}
func (o *Msg) AddMessageReactionExtensions(c *gin.Context) {
a2r.Call(msg.MsgClient.AddMessageReactionExtensions, o.client, c)
func (m *Msg) AddMessageReactionExtensions(c *gin.Context) {
a2r.Call(msg.MsgClient.AddMessageReactionExtensions, m.client, c)
}
func (o *Msg) DeleteMessageReactionExtensions(c *gin.Context) {
a2r.Call(msg.MsgClient.DeleteMessageReactionExtensions, o.client, c)
func (m *Msg) DeleteMessageReactionExtensions(c *gin.Context) {
a2r.Call(msg.MsgClient.DeleteMessageReactionExtensions, m.client, c)
}
func (o *Msg) ManagementSendMsg(c *gin.Context) {
var data interface{}
func (m *Msg) SendMsg(c *gin.Context) {
params := apistruct.ManagementSendMsgReq{}
if err := c.BindJSON(&params); err != nil {
apiresp.GinError(c, err)
return
}
var data interface{}
switch params.ContentType {
case constant.Text:
data = TextElem{}
data = apistruct.TextElem{}
case constant.Picture:
data = PictureElem{}
data = apistruct.PictureElem{}
case constant.Voice:
data = SoundElem{}
data = apistruct.SoundElem{}
case constant.Video:
data = VideoElem{}
data = apistruct.VideoElem{}
case constant.File:
data = FileElem{}
data = apistruct.FileElem{}
case constant.Custom:
data = CustomElem{}
data = apistruct.CustomElem{}
case constant.Revoke:
data = RevokeElem{}
data = apistruct.RevokeElem{}
case constant.AdvancedRevoke:
data = MessageRevoked{}
data = apistruct.MessageRevoked{}
case constant.OANotification:
data = OANotificationElem{}
data = apistruct.OANotificationElem{}
params.SessionType = constant.NotificationChatType
case constant.CustomNotTriggerConversation:
data = CustomElem{}
data = apistruct.CustomElem{}
case constant.CustomOnlineOnly:
data = CustomElem{}
data = apistruct.CustomElem{}
//case constant.HasReadReceipt:
//case constant.Typing:
//case constant.Quote:
@ -195,11 +191,10 @@ func (o *Msg) ManagementSendMsg(c *gin.Context) {
if err := mapstructure.WeakDecode(params.Content, &data); err != nil {
apiresp.GinError(c, errs.ErrData)
return
} else if err := o.validate.Struct(data); err != nil {
} else if err := m.validate.Struct(data); err != nil {
apiresp.GinError(c, errs.ErrData)
return
}
log.NewInfo(params.OperationID, data, params)
switch params.SessionType {
case constant.SingleChatType:
if len(params.RecvID) == 0 {
@ -212,132 +207,43 @@ func (o *Msg) ManagementSendMsg(c *gin.Context) {
return
}
}
log.NewInfo(params.OperationID, "Ws call success to ManagementSendMsgReq", params)
pbData := newUserSendMsgReq(&params)
conn, err := o.c.GetConn(config.Config.RpcRegisterName.OpenImMsgName)
pbReq := m.newUserSendMsgReq(c, &params)
conn, err := m.c.GetConn(config.Config.RpcRegisterName.OpenImMsgName)
if err != nil {
apiresp.GinError(c, errs.ErrInternalServer)
return
}
client := msg.NewMsgClient(conn)
log.Info(params.OperationID, "", "api ManagementSendMsg call, api call rpc...")
//var status int32
RpcResp, err := client.SendMsg(context.Background(), pbData)
var status int
respPb, err := client.SendMsg(c, pbReq)
if err != nil {
//status = constant.MsgSendFailed
status = constant.MsgSendFailed
apiresp.GinError(c, err)
return
}
//status = constant.MsgSendSuccessed
//_, err2 := client.SetSendMsgStatus(context.Background(), &msg.SetSendMsgStatusReq{OperationID: params.OperationID, Status: status})
//if err2 != nil {
// log.NewError(params.OperationID, utils.GetSelfFuncName(), err2.Error())
//}
log.Info(params.OperationID, "", "api ManagementSendMsg call end..., [data: %s] [reply: %s]", pbData.String(), RpcResp.String())
resp := apistruct.ManagementSendMsgResp{ResultList: sdkws.UserSendMsgResp{ServerMsgID: RpcResp.ServerMsgID, ClientMsgID: RpcResp.ClientMsgID, SendTime: RpcResp.SendTime}}
log.Info(params.OperationID, "ManagementSendMsg return", resp)
status = constant.MsgSendSuccessed
_, err = client.SetSendMsgStatus(c, &msg.SetSendMsgStatusReq{
Status: int32(status),
})
if err != nil {
log.NewError(tracelog.GetOperationID(c), "SetSendMsgStatus failed")
}
resp := apistruct.ManagementSendMsgResp{ResultList: sdkws.UserSendMsgResp{ServerMsgID: respPb.ServerMsgID, ClientMsgID: respPb.ClientMsgID, SendTime: respPb.SendTime}}
apiresp.GinSuccess(c, resp)
}
func (o *Msg) ManagementBatchSendMsg(c *gin.Context) {
a2r.Call(msg.MsgClient.SendMsg, o.client, c)
}
func (o *Msg) CheckMsgIsSendSuccess(c *gin.Context) {
a2r.Call(msg.MsgClient.GetSendMsgStatus, o.client, c)
}
func (o *Msg) GetUsersOnlineStatus(c *gin.Context) {
a2r.Call(msg.MsgClient.GetSendMsgStatus, o.client, c)
func (m *Msg) ManagementBatchSendMsg(c *gin.Context) {
a2r.Call(msg.MsgClient.SendMsg, m.client, c)
}
func (o *Msg) AccountCheck(c *gin.Context) {
a2r.Call(msg.MsgClient.GetSendMsgStatus, o.client, c)
func (m *Msg) CheckMsgIsSendSuccess(c *gin.Context) {
a2r.Call(msg.MsgClient.GetSendMsgStatus, m.client, c)
}
type PictureBaseInfo struct {
UUID string `mapstructure:"uuid"`
Type string `mapstructure:"type" `
Size int64 `mapstructure:"size" `
Width int32 `mapstructure:"width" `
Height int32 `mapstructure:"height"`
Url string `mapstructure:"url" `
func (m *Msg) GetUsersOnlineStatus(c *gin.Context) {
a2r.Call(msg.MsgClient.GetSendMsgStatus, m.client, c)
}
type PictureElem struct {
SourcePath string `mapstructure:"sourcePath"`
SourcePicture PictureBaseInfo `mapstructure:"sourcePicture"`
BigPicture PictureBaseInfo `mapstructure:"bigPicture" `
SnapshotPicture PictureBaseInfo `mapstructure:"snapshotPicture"`
}
type SoundElem struct {
UUID string `mapstructure:"uuid"`
SoundPath string `mapstructure:"soundPath"`
SourceURL string `mapstructure:"sourceUrl"`
DataSize int64 `mapstructure:"dataSize"`
Duration int64 `mapstructure:"duration"`
}
type VideoElem struct {
VideoPath string `mapstructure:"videoPath"`
VideoUUID string `mapstructure:"videoUUID"`
VideoURL string `mapstructure:"videoUrl"`
VideoType string `mapstructure:"videoType"`
VideoSize int64 `mapstructure:"videoSize"`
Duration int64 `mapstructure:"duration"`
SnapshotPath string `mapstructure:"snapshotPath"`
SnapshotUUID string `mapstructure:"snapshotUUID"`
SnapshotSize int64 `mapstructure:"snapshotSize"`
SnapshotURL string `mapstructure:"snapshotUrl"`
SnapshotWidth int32 `mapstructure:"snapshotWidth"`
SnapshotHeight int32 `mapstructure:"snapshotHeight"`
}
type FileElem struct {
FilePath string `mapstructure:"filePath"`
UUID string `mapstructure:"uuid"`
SourceURL string `mapstructure:"sourceUrl"`
FileName string `mapstructure:"fileName"`
FileSize int64 `mapstructure:"fileSize"`
}
type AtElem struct {
Text string `mapstructure:"text"`
AtUserList []string `mapstructure:"atUserList"`
IsAtSelf bool `mapstructure:"isAtSelf"`
}
type LocationElem struct {
Description string `mapstructure:"description"`
Longitude float64 `mapstructure:"longitude"`
Latitude float64 `mapstructure:"latitude"`
}
type CustomElem struct {
Data string `mapstructure:"data" validate:"required"`
Description string `mapstructure:"description"`
Extension string `mapstructure:"extension"`
}
type TextElem struct {
Text string `mapstructure:"text" validate:"required"`
}
type RevokeElem struct {
RevokeMsgClientID string `mapstructure:"revokeMsgClientID" validate:"required"`
}
type OANotificationElem struct {
NotificationName string `mapstructure:"notificationName" json:"notificationName" validate:"required"`
NotificationFaceURL string `mapstructure:"notificationFaceURL" json:"notificationFaceURL"`
NotificationType int32 `mapstructure:"notificationType" json:"notificationType" validate:"required"`
Text string `mapstructure:"text" json:"text" validate:"required"`
Url string `mapstructure:"url" json:"url"`
MixType int32 `mapstructure:"mixType" json:"mixType"`
PictureElem PictureElem `mapstructure:"pictureElem" json:"pictureElem"`
SoundElem SoundElem `mapstructure:"soundElem" json:"soundElem"`
VideoElem VideoElem `mapstructure:"videoElem" json:"videoElem"`
FileElem FileElem `mapstructure:"fileElem" json:"fileElem"`
Ex string `mapstructure:"ex" json:"ex"`
}
type MessageRevoked struct {
RevokerID string `mapstructure:"revokerID" json:"revokerID" validate:"required"`
RevokerRole int32 `mapstructure:"revokerRole" json:"revokerRole" validate:"required"`
ClientMsgID string `mapstructure:"clientMsgID" json:"clientMsgID" validate:"required"`
RevokerNickname string `mapstructure:"revokerNickname" json:"revokerNickname"`
SessionType int32 `mapstructure:"sessionType" json:"sessionType" validate:"required"`
Seq uint32 `mapstructure:"seq" json:"seq" validate:"required"`
func (m *Msg) AccountCheck(c *gin.Context) {
a2r.Call(msg.MsgClient.GetSendMsgStatus, m.client, c)
}

@ -121,7 +121,7 @@ func NewGinRouter(zk discoveryregistry.SvcDiscoveryRegistry) *gin.Engine {
chatGroup.POST("/del_super_group_msg", m.DelSuperGroupMsg)
chatGroup.POST("/clear_msg", m.ClearMsg)
chatGroup.POST("/manage_send_msg", m.ManagementSendMsg)
chatGroup.POST("/send_msg", m.ManagementSendMsg)
chatGroup.POST("/batch_send_msg", m.ManagementBatchSendMsg)
chatGroup.POST("/check_msg_is_send_success", m.CheckMsgIsSendSuccess)
chatGroup.POST("/get_users_online_status", m.GetUsersOnlineStatus)

@ -30,25 +30,20 @@ type AccountCheckReq struct {
CheckUserIDList []string `json:"checkUserIDList" binding:"required,lte=100"`
}
type AccountCheckResp struct {
//ResultList []*pbUser.AccountCheckResp_SingleUserStatus `json:"data"`
}
type ManagementSendMsg struct {
OperationID string `json:"operationID" binding:"required"`
BusinessOperationID string `json:"businessOperationID"`
SendID string `json:"sendID" binding:"required"`
GroupID string `json:"groupID" `
SenderNickname string `json:"senderNickname" `
SenderFaceURL string `json:"senderFaceURL" `
SenderPlatformID int32 `json:"senderPlatformID"`
//ForceList []string `json:"forceList" `
Content map[string]interface{} `json:"content" binding:"required" swaggerignore:"true"`
ContentType int32 `json:"contentType" binding:"required"`
SessionType int32 `json:"sessionType" binding:"required"`
IsOnlineOnly bool `json:"isOnlineOnly"`
NotOfflinePush bool `json:"notOfflinePush"`
OfflinePushInfo *sdkws.OfflinePushInfo `json:"offlinePushInfo"`
SendID string `json:"sendID" binding:"required"`
GroupID string `json:"groupID" `
SenderNickname string `json:"senderNickname" `
SenderFaceURL string `json:"senderFaceURL" `
SenderPlatformID int32 `json:"senderPlatformID"`
Content map[string]interface{} `json:"content" binding:"required" swaggerignore:"true"`
ContentType int32 `json:"contentType" binding:"required"`
SessionType int32 `json:"sessionType" binding:"required"`
IsOnlineOnly bool `json:"isOnlineOnly"`
NotOfflinePush bool `json:"notOfflinePush"`
OfflinePushInfo *sdkws.OfflinePushInfo `json:"offlinePushInfo"`
}
type ManagementSendMsgReq struct {
@ -86,39 +81,3 @@ type CheckMsgIsSendSuccessReq struct {
type CheckMsgIsSendSuccessResp struct {
Status int32 `json:"status"`
}
type GetUsersReq struct {
OperationID string `json:"operationID" binding:"required"`
UserName string `json:"userName"`
UserID string `json:"userID"`
Content string `json:"content"`
PageNumber int32 `json:"pageNumber" binding:"required"`
ShowNumber int32 `json:"showNumber" binding:"required"`
}
type CMSUser struct {
UserID string `json:"userID"`
Nickname string `json:"nickname"`
FaceURL string `json:"faceURL"`
Gender int32 `json:"gender"`
PhoneNumber string `json:"phoneNumber"`
Birth uint32 `json:"birth"`
Email string `json:"email"`
Ex string `json:"ex"`
CreateIp string `json:"createIp"`
CreateTime uint32 `json:"createTime"`
LastLoginIp string `json:"LastLoginIp"`
LastLoginTime uint32 `json:"LastLoginTime"`
AppMangerLevel int32 `json:"appMangerLevel"`
GlobalRecvMsgOpt int32 `json:"globalRecvMsgOpt"`
IsBlock bool `json:"isBlock"`
}
type GetUsersResp struct {
Data struct {
UserList []*CMSUser `json:"userList"`
TotalNum int32 `json:"totalNum"`
CurrentPage int32 `json:"currentPage"`
ShowNumber int32 `json:"showNumber"`
} `json:"data"`
}

@ -131,3 +131,90 @@ type ReactionMessageDeleteNotification struct {
ClientMsgID string `json:"clientMsgID" binding:"required"`
MsgFirstModifyTime int64 `json:"msgFirstModifyTime"`
}
type PictureBaseInfo struct {
UUID string `mapstructure:"uuid"`
Type string `mapstructure:"type" `
Size int64 `mapstructure:"size" `
Width int32 `mapstructure:"width" `
Height int32 `mapstructure:"height"`
Url string `mapstructure:"url" `
}
type PictureElem struct {
SourcePath string `mapstructure:"sourcePath"`
SourcePicture PictureBaseInfo `mapstructure:"sourcePicture"`
BigPicture PictureBaseInfo `mapstructure:"bigPicture" `
SnapshotPicture PictureBaseInfo `mapstructure:"snapshotPicture"`
}
type SoundElem struct {
UUID string `mapstructure:"uuid"`
SoundPath string `mapstructure:"soundPath"`
SourceURL string `mapstructure:"sourceUrl"`
DataSize int64 `mapstructure:"dataSize"`
Duration int64 `mapstructure:"duration"`
}
type VideoElem struct {
VideoPath string `mapstructure:"videoPath"`
VideoUUID string `mapstructure:"videoUUID"`
VideoURL string `mapstructure:"videoUrl"`
VideoType string `mapstructure:"videoType"`
VideoSize int64 `mapstructure:"videoSize"`
Duration int64 `mapstructure:"duration"`
SnapshotPath string `mapstructure:"snapshotPath"`
SnapshotUUID string `mapstructure:"snapshotUUID"`
SnapshotSize int64 `mapstructure:"snapshotSize"`
SnapshotURL string `mapstructure:"snapshotUrl"`
SnapshotWidth int32 `mapstructure:"snapshotWidth"`
SnapshotHeight int32 `mapstructure:"snapshotHeight"`
}
type FileElem struct {
FilePath string `mapstructure:"filePath"`
UUID string `mapstructure:"uuid"`
SourceURL string `mapstructure:"sourceUrl"`
FileName string `mapstructure:"fileName"`
FileSize int64 `mapstructure:"fileSize"`
}
type AtElem struct {
Text string `mapstructure:"text"`
AtUserList []string `mapstructure:"atUserList"`
IsAtSelf bool `mapstructure:"isAtSelf"`
}
type LocationElem struct {
Description string `mapstructure:"description"`
Longitude float64 `mapstructure:"longitude"`
Latitude float64 `mapstructure:"latitude"`
}
type CustomElem struct {
Data string `mapstructure:"data" validate:"required"`
Description string `mapstructure:"description"`
Extension string `mapstructure:"extension"`
}
type TextElem struct {
Text string `mapstructure:"text" validate:"required"`
}
type RevokeElem struct {
RevokeMsgClientID string `mapstructure:"revokeMsgClientID" validate:"required"`
}
type OANotificationElem struct {
NotificationName string `mapstructure:"notificationName" json:"notificationName" validate:"required"`
NotificationFaceURL string `mapstructure:"notificationFaceURL" json:"notificationFaceURL"`
NotificationType int32 `mapstructure:"notificationType" json:"notificationType" validate:"required"`
Text string `mapstructure:"text" json:"text" validate:"required"`
Url string `mapstructure:"url" json:"url"`
MixType int32 `mapstructure:"mixType" json:"mixType"`
PictureElem PictureElem `mapstructure:"pictureElem" json:"pictureElem"`
SoundElem SoundElem `mapstructure:"soundElem" json:"soundElem"`
VideoElem VideoElem `mapstructure:"videoElem" json:"videoElem"`
FileElem FileElem `mapstructure:"fileElem" json:"fileElem"`
Ex string `mapstructure:"ex" json:"ex"`
}
type MessageRevoked struct {
RevokerID string `mapstructure:"revokerID" json:"revokerID" validate:"required"`
RevokerRole int32 `mapstructure:"revokerRole" json:"revokerRole" validate:"required"`
ClientMsgID string `mapstructure:"clientMsgID" json:"clientMsgID" validate:"required"`
RevokerNickname string `mapstructure:"revokerNickname" json:"revokerNickname"`
SessionType int32 `mapstructure:"sessionType" json:"sessionType" validate:"required"`
Seq uint32 `mapstructure:"seq" json:"seq" validate:"required"`
}

Loading…
Cancel
Save