增加server酱的微信通知

pull/30/head
taoshihan1991 4 years ago
parent b8ce5a0474
commit b0abaecf08

@ -19,7 +19,7 @@ var(
port string port string
tcpport string tcpport string
daemon bool daemon bool
GoflyConfig config.Config GoflyConfig *config.Config
) )
var serverCmd = &cobra.Command{ var serverCmd = &cobra.Command{
Use: "server", Use: "server",

@ -11,6 +11,7 @@ var(
PageSize uint=10 PageSize uint=10
VisitorPageSize uint=8 VisitorPageSize uint=8
Version = "0.1.2" Version = "0.1.2"
GoflyConfig *Config
) )
const Dir = "config/" const Dir = "config/"
const AccountConf = Dir + "account.json" const AccountConf = Dir + "account.json"
@ -19,7 +20,11 @@ const MailConf = Dir + "mail.json"
const LangConf=Dir+"language.json" const LangConf=Dir+"language.json"
const MainConf = Dir + "config.json" const MainConf = Dir + "config.json"
const WeixinToken="taoshihan1" const WeixinToken="taoshihan1"
const ServerJiang=""
func init(){
//配置文件
GoflyConfig=CreateConfig()
}
type Mysql struct{ type Mysql struct{
Server string Server string
Port string Port string
@ -32,11 +37,13 @@ type MailServer struct {
} }
type Config struct { type Config struct {
Upload string Upload string
NoticeServerJiang bool
} }
func CreateConfig()*Config{ func CreateConfig()*Config{
var configObj Config var configObj Config
c:=&Config{ c:=&Config{
Upload: "static/upload/", Upload: "static/upload/",
NoticeServerJiang:false,
} }
isExist, _ := tools.IsFileExist(MainConf) isExist, _ := tools.IsFileExist(MainConf)
if !isExist { if !isExist {

@ -1,3 +1,4 @@
{ {
"Upload":"static/upload/" "Upload":"static/upload/",
"NoticeServerJiang": true
} }

@ -257,6 +257,8 @@ func singleBroadcaster(){
kefuConn.WriteMessage(websocket.TextMessage,str) kefuConn.WriteMessage(websocket.TextMessage,str)
} }
} }
//客户上线发微信通知
go SendServerJiang(userInfo["username"])
sendPingOnlineUsers() sendPingOnlineUsers()
//客服上线 //客服上线
case "kfOnline": case "kfOnline":

@ -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
}

@ -148,7 +148,6 @@
chatTitle:"正在连接...", chatTitle:"正在连接...",
visitor:{}, visitor:{},
face:[], face:[],
showKfonline:false,
kfConfig:{ kfConfig:{
id : "", id : "",
name : "", name : "",

@ -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)
}
Loading…
Cancel
Save