关闭访客连接

pull/23/head
taoshihan1991 4 years ago
parent 73381185d8
commit 6af8350add

@ -249,6 +249,33 @@ func SendCloseMessage(c *gin.Context) {
"msg": "ok",
})
}
func SendCloseMessageV2(c *gin.Context) {
visitorId := c.Query("visitor_id")
if visitorId == "" {
c.JSON(200, gin.H{
"code": 400,
"msg": "visitor_id不能为空",
})
return
}
msg := TypeMessage{
Type: "close",
Data: visitorId,
}
str, _ := json.Marshal(msg)
for _, visitor := range ws.ClientList {
if visitorId == visitor.Id {
if err := visitor.Conn.WriteMessage(websocket.TextMessage, str); err != nil {
visitor.Conn.Close()
delete(ws.ClientList, visitorId)
}
}
}
c.JSON(200, gin.H{
"code": 200,
"msg": "ok",
})
}
func UploadImg(c *gin.Context) {
config := config.CreateConfig()
f, err := c.FormFile("imgfile")

@ -14,9 +14,11 @@ func InitApiRouter(engine *gin.Engine) {
v2 := engine.Group("/2")
{
//获取消息
v2.GET("/2/messages", controller.GetMessagesV2)
v2.GET("/messages", controller.GetMessagesV2)
//发送单条信息
v2.POST("/2/message", middleware.Ipblack, controller.SendMessageV2)
v2.POST("/message", middleware.Ipblack, controller.SendMessageV2)
//关闭连接
v2.GET("/message_close", controller.SendCloseMessageV2)
}
engine.POST("/check", controller.LoginCheckPass)
engine.POST("/check_auth", middleware.JwtApiMiddleware, controller.MainCheckAuth)
@ -31,7 +33,6 @@ func InitApiRouter(engine *gin.Engine) {
engine.GET("/message_notice", controller.SendVisitorNotice)
//发送单条消息
engine.POST("/message", middleware.Ipblack, controller.SendMessage)
engine.POST("/2/message", middleware.Ipblack, controller.SendMessageV2)
//发送关闭消息
engine.GET("/message_close", controller.SendCloseMessage)
//上传文件

@ -378,7 +378,7 @@ var app=new Vue({
let _this=this;
$.ajax({
type:"get",
url:"/message_close",
url:"/2/message_close",
data:{visitor_id:visitorId},
headers:{
"token":localStorage.getItem("token")

@ -31,7 +31,9 @@ func NewVisitorServer(c *gin.Context) {
Id: vistorInfo.VisitorId,
To_id: vistorInfo.ToId,
}
go models.UpdateVisitorStatus(vistorInfo.VisitorId, 1)
go SendServerJiang(vistorInfo.Name)
AddVisitorToList(user)
for {

Loading…
Cancel
Save