From b786521ce67d4c33bb282d40bc5a18ee3ed511e7 Mon Sep 17 00:00:00 2001
From: taoshihan1991 <630892807@qq.com>
Date: Wed, 30 Sep 2020 13:49:47 +0800
Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E9=80=81=E5=85=B3=E9=97=AD=E8=BF=9E?=
=?UTF-8?q?=E6=8E=A5=E6=8C=87=E4=BB=A4=E6=8E=A5=E5=8F=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
controller/message.go | 24 ++++++++++++++++++++++++
router/api.go | 2 ++
static/html/chat_page.html | 2 +-
static/js/chat-page.js | 10 +++++++++-
4 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/controller/message.go b/controller/message.go
index 2482a7c..23a29eb 100644
--- a/controller/message.go
+++ b/controller/message.go
@@ -135,6 +135,30 @@ func SendVisitorNotice(c *gin.Context) {
"msg": "ok",
})
}
+func SendCloseMessage(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 clientList {
+ if visitorId == visitor.id {
+ visitor.conn.WriteMessage(websocket.TextMessage, str)
+ }
+ }
+ c.JSON(200, gin.H{
+ "code": 200,
+ "msg": "ok",
+ })
+}
func UploadImg(c *gin.Context) {
config := config.CreateConfig()
f, err := c.FormFile("imgfile")
diff --git a/router/api.go b/router/api.go
index 6f34777..0708c93 100644
--- a/router/api.go
+++ b/router/api.go
@@ -18,6 +18,8 @@ func InitApiRouter(engine *gin.Engine) {
engine.GET("/message_notice", controller.SendVisitorNotice)
//发送单条消息
engine.POST("/message", middleware.Ipblack, controller.SendMessage)
+ //发送关闭消息
+ engine.GET("/message_close", controller.SendCloseMessage)
//上传文件
engine.POST("/uploadimg", middleware.Ipblack, controller.UploadImg)
//获取未读消息数
diff --git a/static/html/chat_page.html b/static/html/chat_page.html
index dc95ce8..865b304 100644
--- a/static/html/chat_page.html
+++ b/static/html/chat_page.html
@@ -79,5 +79,5 @@
var KEFU_ID='{{.KEFU_ID}}';
var REFER='{{.Refer}}';
-
+