|
|
|
@ -2,6 +2,7 @@ package ImRelateController
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"dsSzxy/Business/ImRelate/ImRelateDao"
|
|
|
|
|
"dsSzxy/Utils/CommonUtil"
|
|
|
|
|
"dsSzxy/Utils/ConfigUtil"
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
@ -14,7 +15,7 @@ func Routers(r *gin.RouterGroup) {
|
|
|
|
|
rr.POST("/sendTxtMsg", sendTxtMsg)
|
|
|
|
|
rr.POST("/sendImgMsg", sendImgMsg)
|
|
|
|
|
rr.POST("/sendFileMsg", sendFileMsg)
|
|
|
|
|
rr.POST("/sendVideoMsg", sendVideoMsg)
|
|
|
|
|
rr.POST("/sendSightMsg", sendSightMsg)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -42,7 +43,29 @@ func sendTxtMsg(c *gin.Context) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cm := map[string]string{"name": "中华人民共和国1234", "country": "China", "age": "21", "date": "2021-08-17"}
|
|
|
|
|
fromName := ImRelateDao.GetPersonNameByUserId(fromId)
|
|
|
|
|
fromAvatar := ImRelateDao.GetPersonAvatarByUserId(fromId)
|
|
|
|
|
var toName, toAvatar string
|
|
|
|
|
if sendType == "p" {
|
|
|
|
|
toName = ImRelateDao.GetPersonNameByUserId(toId)
|
|
|
|
|
toAvatar = ImRelateDao.GetPersonAvatarByUserId(toId)
|
|
|
|
|
} else
|
|
|
|
|
{
|
|
|
|
|
toName, toAvatar = ImRelateDao.GetGroupNameAvatarByGroupId(toId)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cm := map[string]string{
|
|
|
|
|
"sender_user_id": fromId,
|
|
|
|
|
"sender_user_name": fromName,
|
|
|
|
|
"sender_user_avatar": fromAvatar,
|
|
|
|
|
"receiver_user_id": toId,
|
|
|
|
|
"receiver_user_name": toName,
|
|
|
|
|
"receiver_user_avatar": toAvatar,
|
|
|
|
|
"send_time": CommonUtil.GetCurrentTime(),
|
|
|
|
|
"content": content,
|
|
|
|
|
"message_type": "TxtMsg",
|
|
|
|
|
"chat_type": sendType,
|
|
|
|
|
}
|
|
|
|
|
bodyJsonObj, _ := json.Marshal(cm)
|
|
|
|
|
bodyString := string(bodyJsonObj)
|
|
|
|
|
|
|
|
|
@ -72,7 +95,7 @@ func sendImgMsg(c *gin.Context) {
|
|
|
|
|
//imgUrl
|
|
|
|
|
imgUrl := c.PostForm("imgUrl")
|
|
|
|
|
//文件名
|
|
|
|
|
//fileName := c.PostForm("fileName")
|
|
|
|
|
fileName := c.PostForm("fileName")
|
|
|
|
|
|
|
|
|
|
m := map[string]string{"content": imgBase64, "imageUri": imgUrl}
|
|
|
|
|
contentJsonObj, _ := json.Marshal(m)
|
|
|
|
@ -84,6 +107,40 @@ func sendImgMsg(c *gin.Context) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fromName := ImRelateDao.GetPersonNameByUserId(fromId)
|
|
|
|
|
fromAvatar := ImRelateDao.GetPersonAvatarByUserId(fromId)
|
|
|
|
|
var toName, toAvatar string
|
|
|
|
|
if sendType == "p" {
|
|
|
|
|
toName = ImRelateDao.GetPersonNameByUserId(toId)
|
|
|
|
|
toAvatar = ImRelateDao.GetPersonAvatarByUserId(toId)
|
|
|
|
|
} else
|
|
|
|
|
{
|
|
|
|
|
toName, toAvatar = ImRelateDao.GetGroupNameAvatarByGroupId(toId)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cm := map[string]string{
|
|
|
|
|
"sender_user_id": fromId,
|
|
|
|
|
"sender_user_name": fromName,
|
|
|
|
|
"sender_user_avatar": fromAvatar,
|
|
|
|
|
"receiver_user_id": toId,
|
|
|
|
|
"receiver_user_name": toName,
|
|
|
|
|
"receiver_user_avatar": toAvatar,
|
|
|
|
|
"send_time": CommonUtil.GetCurrentTime(),
|
|
|
|
|
"content": fileName,
|
|
|
|
|
"base64": imgBase64,
|
|
|
|
|
"url": imgUrl,
|
|
|
|
|
"message_type": "ImgMsg",
|
|
|
|
|
"chat_type": sendType,
|
|
|
|
|
}
|
|
|
|
|
bodyJsonObj, _ := json.Marshal(cm)
|
|
|
|
|
bodyString := string(bodyJsonObj)
|
|
|
|
|
|
|
|
|
|
saveErr := ImRelateDao.SaveChatRecord("chat_record", bodyString)
|
|
|
|
|
if saveErr != nil {
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{"success": false, "info": "聊天记录保存失败!"})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{"success": true, "info": "发送消息成功!"})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -118,6 +175,41 @@ func sendFileMsg(c *gin.Context) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fromName := ImRelateDao.GetPersonNameByUserId(fromId)
|
|
|
|
|
fromAvatar := ImRelateDao.GetPersonAvatarByUserId(fromId)
|
|
|
|
|
var toName, toAvatar string
|
|
|
|
|
if sendType == "p" {
|
|
|
|
|
toName = ImRelateDao.GetPersonNameByUserId(toId)
|
|
|
|
|
toAvatar = ImRelateDao.GetPersonAvatarByUserId(toId)
|
|
|
|
|
} else
|
|
|
|
|
{
|
|
|
|
|
toName, toAvatar = ImRelateDao.GetGroupNameAvatarByGroupId(toId)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cm := map[string]string{
|
|
|
|
|
"sender_user_id": fromId,
|
|
|
|
|
"sender_user_name": fromName,
|
|
|
|
|
"sender_user_avatar": fromAvatar,
|
|
|
|
|
"receiver_user_id": toId,
|
|
|
|
|
"receiver_user_name": toName,
|
|
|
|
|
"receiver_user_avatar": toAvatar,
|
|
|
|
|
"send_time": CommonUtil.GetCurrentTime(),
|
|
|
|
|
"content": fileName,
|
|
|
|
|
"size": fileSize,
|
|
|
|
|
"file_type": fileType,
|
|
|
|
|
"url": fileUrl,
|
|
|
|
|
"message_type": "FileMsg",
|
|
|
|
|
"chat_type": sendType,
|
|
|
|
|
}
|
|
|
|
|
bodyJsonObj, _ := json.Marshal(cm)
|
|
|
|
|
bodyString := string(bodyJsonObj)
|
|
|
|
|
|
|
|
|
|
saveErr := ImRelateDao.SaveChatRecord("chat_record", bodyString)
|
|
|
|
|
if saveErr != nil {
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{"success": false, "info": "聊天记录保存失败!"})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{"success": true, "info": "发送消息成功!"})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -126,7 +218,7 @@ func sendFileMsg(c *gin.Context) {
|
|
|
|
|
作者:吴缤
|
|
|
|
|
日期:2021-08-16
|
|
|
|
|
*/
|
|
|
|
|
func sendVideoMsg(c *gin.Context) {
|
|
|
|
|
func sendSightMsg(c *gin.Context) {
|
|
|
|
|
//发送方Id。
|
|
|
|
|
fromId := c.PostForm("fromId")
|
|
|
|
|
//接收方Id。
|
|
|
|
@ -140,17 +232,52 @@ func sendVideoMsg(c *gin.Context) {
|
|
|
|
|
//视频大小
|
|
|
|
|
videoSize := c.PostForm("videoSize")
|
|
|
|
|
//视频名称
|
|
|
|
|
fileName := c.PostForm("fileName")
|
|
|
|
|
videoName := c.PostForm("fileName")
|
|
|
|
|
|
|
|
|
|
m := map[string]string{"sightUrl": videoUrl, "content": thumbBase64, "duration": "60", "size": videoSize, "name": fileName}
|
|
|
|
|
m := map[string]string{"sightUrl": videoUrl, "content": thumbBase64, "duration": "60", "size": videoSize, "name": videoName}
|
|
|
|
|
contentJsonObj, _ := json.Marshal(m)
|
|
|
|
|
contentJsonStr := string(contentJsonObj)
|
|
|
|
|
|
|
|
|
|
err := ImRelateDao.SendRongYunMsg(sendType, fromId, toId, "RC:FileMsg", contentJsonStr)
|
|
|
|
|
err := ImRelateDao.SendRongYunMsg(sendType, fromId, toId, "RC:SightMsg", contentJsonStr)
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{"success": false, "info": "发送消息失败!"})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fromName := ImRelateDao.GetPersonNameByUserId(fromId)
|
|
|
|
|
fromAvatar := ImRelateDao.GetPersonAvatarByUserId(fromId)
|
|
|
|
|
var toName, toAvatar string
|
|
|
|
|
if sendType == "p" {
|
|
|
|
|
toName = ImRelateDao.GetPersonNameByUserId(toId)
|
|
|
|
|
toAvatar = ImRelateDao.GetPersonAvatarByUserId(toId)
|
|
|
|
|
} else
|
|
|
|
|
{
|
|
|
|
|
toName, toAvatar = ImRelateDao.GetGroupNameAvatarByGroupId(toId)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cm := map[string]string{
|
|
|
|
|
"sender_user_id": fromId,
|
|
|
|
|
"sender_user_name": fromName,
|
|
|
|
|
"sender_user_avatar": fromAvatar,
|
|
|
|
|
"receiver_user_id": toId,
|
|
|
|
|
"receiver_user_name": toName,
|
|
|
|
|
"receiver_user_avatar": toAvatar,
|
|
|
|
|
"send_time": CommonUtil.GetCurrentTime(),
|
|
|
|
|
"content": videoName,
|
|
|
|
|
"size": videoSize,
|
|
|
|
|
"base64": thumbBase64,
|
|
|
|
|
"url": videoUrl,
|
|
|
|
|
"message_type": "SightMsg",
|
|
|
|
|
"chat_type": sendType,
|
|
|
|
|
}
|
|
|
|
|
bodyJsonObj, _ := json.Marshal(cm)
|
|
|
|
|
bodyString := string(bodyJsonObj)
|
|
|
|
|
|
|
|
|
|
saveErr := ImRelateDao.SaveChatRecord("chat_record", bodyString)
|
|
|
|
|
if saveErr != nil {
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{"success": false, "info": "聊天记录保存失败!"})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{"success": true, "info": "发送消息成功!"})
|
|
|
|
|
}
|
|
|
|
|