From 1a3ec1ab902756be25383769309b92d5f64455a3 Mon Sep 17 00:00:00 2001 From: taoshihan1991 <630892807@qq.com> Date: Fri, 19 Feb 2021 15:54:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=AE=BF=E5=AE=A2=E9=80=9A?= =?UTF-8?q?=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/shout.go | 19 ++++++++++++++++--- controller/visitor.go | 2 ++ static/js/chat-main.js | 17 ++++++++--------- ws/visitor.go | 2 +- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/controller/shout.go b/controller/shout.go index 06b2153..a47a8cd 100644 --- a/controller/shout.go +++ b/controller/shout.go @@ -5,25 +5,38 @@ import ( "fmt" "github.com/taoshihan1991/imaptool/models" "github.com/taoshihan1991/imaptool/tools" + "github.com/taoshihan1991/imaptool/ws" "log" "strconv" "time" ) -func SendServerJiang(content string) string { +func SendServerJiang(title string, content string, domain string) string { noticeServerJiang, err := strconv.ParseBool(models.FindConfig("NoticeServerJiang")) serverJiangAPI := models.FindConfig("ServerJiangAPI") if err != nil || !noticeServerJiang || serverJiangAPI == "" { log.Println("do not notice serverjiang:", serverJiangAPI, noticeServerJiang) return "" } - sendStr := fmt.Sprintf("%s,访客来了", content) - desp := "[登录](https://gofly.sopans.com/main)" + sendStr := fmt.Sprintf("%s%s", title, content) + desp := title + ":" + content + "[登录](http://" + domain + "/main)" url := serverJiangAPI + "?text=" + sendStr + "&desp=" + desp //log.Println(url) res := tools.Get(url) return res } +func SendVisitorLoginNotice(kefuName, visitorName, avator, content string) { + userInfo := make(map[string]string) + userInfo["username"] = visitorName + userInfo["avator"] = avator + userInfo["content"] = content + msg := TypeMessage{ + Type: "notice", + Data: userInfo, + } + str, _ := json.Marshal(msg) + ws.OneKefuMessage(kefuName, str) +} func SendNoticeEmail(username, msg string) { smtp := models.FindConfig("NoticeEmailSmtp") email := models.FindConfig("NoticeEmailAddress") diff --git a/controller/visitor.go b/controller/visitor.go index 893a52f..98cc9ce 100644 --- a/controller/visitor.go +++ b/controller/visitor.go @@ -101,6 +101,8 @@ func PostVisitorLogin(c *gin.Context) { //各种通知 go SendNoticeEmail(visitor.Name, "来了") go SendAppGetuiPush(kefuInfo.Name, visitor.Name, visitor.Name+"来了") + go SendVisitorLoginNotice(kefuInfo.Name, visitor.Name, visitor.Avator, visitor.Name+"来了") + go SendServerJiang(visitor.Name, "来了", c.Request.Host) c.JSON(200, gin.H{ "code": 200, diff --git a/static/js/chat-main.js b/static/js/chat-main.js index 265b0f5..0776f1c 100644 --- a/static/js/chat-main.js +++ b/static/js/chat-main.js @@ -97,14 +97,6 @@ var app=new Vue({ break; case "userOnline": this.addOnlineUser(redata.data); - //发送通知 - let _this=this; - window.parent.postMessage({ - name:redata.data.username, - body: "来了", - icon: redata.data.avator - }); - _this.alertSound(); break; case "userOffline": @@ -112,7 +104,14 @@ var app=new Vue({ //this.sendKefuOnline(); break; case "notice": - this.sendKefuOnline(); + //发送通知 + var _this=this; + window.parent.postMessage({ + name:redata.data.username, + body: redata.data.content, + icon: redata.data.avator + }); + _this.alertSound(); break; } diff --git a/ws/visitor.go b/ws/visitor.go index a272d6b..4a700d7 100644 --- a/ws/visitor.go +++ b/ws/visitor.go @@ -32,7 +32,7 @@ func NewVisitorServer(c *gin.Context) { To_id: vistorInfo.ToId, } go models.UpdateVisitorStatus(vistorInfo.VisitorId, 1) - go SendServerJiang(vistorInfo.Name, "来了", c.Request.Host) + //go SendServerJiang(vistorInfo.Name, "来了", c.Request.Host) AddVisitorToList(user)