From b0abaecf087e4651414fe9f48cf3d167892e7ac1 Mon Sep 17 00:00:00 2001 From: taoshihan1991 <630892807@qq.com> Date: Tue, 15 Sep 2020 13:51:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0server=E9=85=B1=E7=9A=84?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/server.go | 2 +- config/config.go | 9 ++++++++- config/config.json | 3 ++- controller/chat.go | 2 ++ controller/shout.go | 20 ++++++++++++++++++++ static/html/chat_kf_page.html | 1 - tools/http.go | 19 +++++++++++++++++++ 7 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 controller/shout.go create mode 100644 tools/http.go diff --git a/cmd/server.go b/cmd/server.go index 555b8a0..30505c2 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -19,7 +19,7 @@ var( port string tcpport string daemon bool - GoflyConfig config.Config + GoflyConfig *config.Config ) var serverCmd = &cobra.Command{ Use: "server", diff --git a/config/config.go b/config/config.go index a3bd66c..143a920 100644 --- a/config/config.go +++ b/config/config.go @@ -11,6 +11,7 @@ var( PageSize uint=10 VisitorPageSize uint=8 Version = "0.1.2" + GoflyConfig *Config ) const Dir = "config/" const AccountConf = Dir + "account.json" @@ -19,7 +20,11 @@ const MailConf = Dir + "mail.json" const LangConf=Dir+"language.json" const MainConf = Dir + "config.json" const WeixinToken="taoshihan1" - +const ServerJiang="" +func init(){ + //配置文件 + GoflyConfig=CreateConfig() +} type Mysql struct{ Server string Port string @@ -32,11 +37,13 @@ type MailServer struct { } type Config struct { Upload string + NoticeServerJiang bool } func CreateConfig()*Config{ var configObj Config c:=&Config{ Upload: "static/upload/", + NoticeServerJiang:false, } isExist, _ := tools.IsFileExist(MainConf) if !isExist { diff --git a/config/config.json b/config/config.json index 2d26ad1..151dbc2 100644 --- a/config/config.json +++ b/config/config.json @@ -1,3 +1,4 @@ { - "Upload":"static/upload/" + "Upload":"static/upload/", + "NoticeServerJiang": true } diff --git a/controller/chat.go b/controller/chat.go index d8e4c4f..40c61c6 100644 --- a/controller/chat.go +++ b/controller/chat.go @@ -257,6 +257,8 @@ func singleBroadcaster(){ kefuConn.WriteMessage(websocket.TextMessage,str) } } + //客户上线发微信通知 + go SendServerJiang(userInfo["username"]) sendPingOnlineUsers() //客服上线 case "kfOnline": diff --git a/controller/shout.go b/controller/shout.go new file mode 100644 index 0000000..aebd359 --- /dev/null +++ b/controller/shout.go @@ -0,0 +1,20 @@ +package controller + +import ( + "fmt" + "github.com/taoshihan1991/imaptool/config" + "github.com/taoshihan1991/imaptool/tools" + "log" +) + +func SendServerJiang(content string)string{ + conf:=config.CreateConfig() + if config.ServerJiang=="" || !conf.NoticeServerJiang{ + log.Println("do not notice serverjiang:",config.ServerJiang,conf.NoticeServerJiang) + return "" + } + sendStr:=fmt.Sprintf("%s,访客来了",content) + desp:="[登录](https://gofly.sopans.com/main)"; + res:=tools.Get(config.ServerJiang+"?text="+sendStr+"&desp="+desp) + return res +} diff --git a/static/html/chat_kf_page.html b/static/html/chat_kf_page.html index debec84..45121ca 100644 --- a/static/html/chat_kf_page.html +++ b/static/html/chat_kf_page.html @@ -148,7 +148,6 @@ chatTitle:"正在连接...", visitor:{}, face:[], - showKfonline:false, kfConfig:{ id : "", name : "", diff --git a/tools/http.go b/tools/http.go new file mode 100644 index 0000000..88aaa3c --- /dev/null +++ b/tools/http.go @@ -0,0 +1,19 @@ +package tools + +import ( + "io/ioutil" + "net/http" +) + +func Get(url string)string{ + res, err :=http.Get(url) + if err != nil { + return "" + } + robots, err := ioutil.ReadAll(res.Body) + res.Body.Close() + if err != nil { + return "" + } + return string(robots) +}