|
|
@ -248,24 +248,44 @@ func (m *MessageApi) SendMessage(c *gin.Context) {
|
|
|
|
|
|
|
|
|
|
|
|
func (m *MessageApi) SendBusinessNotification(c *gin.Context) {
|
|
|
|
func (m *MessageApi) SendBusinessNotification(c *gin.Context) {
|
|
|
|
req := struct {
|
|
|
|
req := struct {
|
|
|
|
Key string `json:"key"`
|
|
|
|
Key string `json:"key"`
|
|
|
|
Data string `json:"data"`
|
|
|
|
Data string `json:"data"`
|
|
|
|
SendUserID string `json:"sendUserID" binding:"required"`
|
|
|
|
SendUserID string `json:"sendUserID" binding:"required"`
|
|
|
|
RecvUserID string `json:"recvUserID" binding:"required"`
|
|
|
|
RecvUserID string `json:"recvUserID"`
|
|
|
|
|
|
|
|
RecvGroupID string `json:"recvGroupID"`
|
|
|
|
|
|
|
|
SendMsg bool `json:"sendMsg"`
|
|
|
|
|
|
|
|
ReliabilityLevel *int `json:"reliabilityLevel"`
|
|
|
|
}{}
|
|
|
|
}{}
|
|
|
|
if err := c.BindJSON(&req); err != nil {
|
|
|
|
if err := c.BindJSON(&req); err != nil {
|
|
|
|
apiresp.GinError(c, errs.ErrArgs.WithDetail(err.Error()).Wrap())
|
|
|
|
apiresp.GinError(c, errs.ErrArgs.WithDetail(err.Error()).Wrap())
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if req.RecvUserID == "" && req.RecvGroupID == "" {
|
|
|
|
|
|
|
|
apiresp.GinError(c, errs.ErrArgs.WrapMsg("recvUserID and recvGroupID cannot be empty at the same time"))
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if req.RecvUserID != "" && req.RecvGroupID != "" {
|
|
|
|
|
|
|
|
apiresp.GinError(c, errs.ErrArgs.WrapMsg("recvUserID and recvGroupID cannot be set at the same time"))
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var sessionType int32
|
|
|
|
|
|
|
|
if req.RecvUserID != "" {
|
|
|
|
|
|
|
|
sessionType = constant.SingleChatType
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
sessionType = constant.ReadGroupChatType
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if req.ReliabilityLevel == nil {
|
|
|
|
|
|
|
|
req.ReliabilityLevel = datautil.ToPtr(1)
|
|
|
|
|
|
|
|
}
|
|
|
|
if !authverify.IsAppManagerUid(c, m.imAdminUserID) {
|
|
|
|
if !authverify.IsAppManagerUid(c, m.imAdminUserID) {
|
|
|
|
apiresp.GinError(c, errs.ErrNoPermission.WrapMsg("only app manager can send message"))
|
|
|
|
apiresp.GinError(c, errs.ErrNoPermission.WrapMsg("only app manager can send message"))
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sendMsgReq := msg.SendMsgReq{
|
|
|
|
sendMsgReq := msg.SendMsgReq{
|
|
|
|
MsgData: &sdkws.MsgData{
|
|
|
|
MsgData: &sdkws.MsgData{
|
|
|
|
SendID: req.SendUserID,
|
|
|
|
SendID: req.SendUserID,
|
|
|
|
RecvID: req.RecvUserID,
|
|
|
|
RecvID: req.RecvUserID,
|
|
|
|
|
|
|
|
GroupID: req.RecvGroupID,
|
|
|
|
Content: []byte(jsonutil.StructToJsonString(&sdkws.NotificationElem{
|
|
|
|
Content: []byte(jsonutil.StructToJsonString(&sdkws.NotificationElem{
|
|
|
|
Detail: jsonutil.StructToJsonString(&struct {
|
|
|
|
Detail: jsonutil.StructToJsonString(&struct {
|
|
|
|
Key string `json:"key"`
|
|
|
|
Key string `json:"key"`
|
|
|
@ -274,12 +294,12 @@ func (m *MessageApi) SendBusinessNotification(c *gin.Context) {
|
|
|
|
})),
|
|
|
|
})),
|
|
|
|
MsgFrom: constant.SysMsgType,
|
|
|
|
MsgFrom: constant.SysMsgType,
|
|
|
|
ContentType: constant.BusinessNotification,
|
|
|
|
ContentType: constant.BusinessNotification,
|
|
|
|
SessionType: constant.SingleChatType,
|
|
|
|
SessionType: sessionType,
|
|
|
|
CreateTime: timeutil.GetCurrentTimestampByMill(),
|
|
|
|
CreateTime: timeutil.GetCurrentTimestampByMill(),
|
|
|
|
ClientMsgID: idutil.GetMsgIDByMD5(mcontext.GetOpUserID(c)),
|
|
|
|
ClientMsgID: idutil.GetMsgIDByMD5(mcontext.GetOpUserID(c)),
|
|
|
|
Options: config.GetOptionsByNotification(config.NotificationConfig{
|
|
|
|
Options: config.GetOptionsByNotification(config.NotificationConfig{
|
|
|
|
IsSendMsg: false,
|
|
|
|
IsSendMsg: req.SendMsg,
|
|
|
|
ReliabilityLevel: 1,
|
|
|
|
ReliabilityLevel: *req.ReliabilityLevel,
|
|
|
|
UnreadCount: false,
|
|
|
|
UnreadCount: false,
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|