From 23288d6021a24a5f196e426acf59d0f822431a10 Mon Sep 17 00:00:00 2001 From: taoshihan1991 <630892807@qq.com> Date: Wed, 16 Sep 2020 15:09:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE=E9=A1=B9?= =?UTF-8?q?=E4=BB=8E=E6=95=B0=E6=8D=AE=E5=BA=93=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/config.go | 2 +- config/config.json | 2 +- controller/shout.go | 14 +++++++++----- controller/weixin.go | 4 ++-- models/configs.go | 26 ++++++++++++++++++++++++++ models/models.go | 2 ++ tmpl/chat.go | 34 ++++++++++++++++++++++++++++++++++ tmpl/login.go | 28 +--------------------------- 8 files changed, 76 insertions(+), 36 deletions(-) create mode 100644 models/configs.go create mode 100644 tmpl/chat.go diff --git a/config/config.go b/config/config.go index 143a920..bf2d774 100644 --- a/config/config.go +++ b/config/config.go @@ -19,7 +19,7 @@ const MysqlConf = Dir + "mysql.json" const MailConf = Dir + "mail.json" const LangConf=Dir+"language.json" const MainConf = Dir + "config.json" -const WeixinToken="taoshihan1" +const WeixinToken="" const ServerJiang="" func init(){ //配置文件 diff --git a/config/config.json b/config/config.json index 151dbc2..1e7afdb 100644 --- a/config/config.json +++ b/config/config.json @@ -1,4 +1,4 @@ { "Upload":"static/upload/", - "NoticeServerJiang": true + "NoticeServerJiang": false } diff --git a/controller/shout.go b/controller/shout.go index aebd359..4ab5cbd 100644 --- a/controller/shout.go +++ b/controller/shout.go @@ -2,19 +2,23 @@ package controller import ( "fmt" - "github.com/taoshihan1991/imaptool/config" + "github.com/taoshihan1991/imaptool/models" "github.com/taoshihan1991/imaptool/tools" "log" + "strconv" ) func SendServerJiang(content string)string{ - conf:=config.CreateConfig() - if config.ServerJiang=="" || !conf.NoticeServerJiang{ - log.Println("do not notice serverjiang:",config.ServerJiang,conf.NoticeServerJiang) + 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)"; - res:=tools.Get(config.ServerJiang+"?text="+sendStr+"&desp="+desp) + url:=serverJiangAPI+"?text="+sendStr+"&desp="+desp + //log.Println(url) + res:=tools.Get(url) return res } diff --git a/controller/weixin.go b/controller/weixin.go index b21e2f3..7ea89a2 100644 --- a/controller/weixin.go +++ b/controller/weixin.go @@ -4,13 +4,13 @@ import ( "crypto/sha1" "encoding/hex" "github.com/gin-gonic/gin" - "github.com/taoshihan1991/imaptool/config" + "github.com/taoshihan1991/imaptool/models" "log" "sort" ) func GetCheckWeixinSign(c *gin.Context){ - token:=config.WeixinToken + token:=models.FindConfig("WeixinToken") signature:=c.Query("signature") timestamp:=c.Query("timestamp") nonce:=c.Query("nonce") diff --git a/models/configs.go b/models/configs.go new file mode 100644 index 0000000..a197154 --- /dev/null +++ b/models/configs.go @@ -0,0 +1,26 @@ +package models + +var CustomConfigs []Config +type Config struct{ + ID uint `gorm:"primary_key" json:"id"` + ConfName string `json:"conf_name"` + ConfKey string `json:"conf_key"` + ConfValue string `json:"conf_value"` +} + +func FindConfigs()[]Config{ + var config []Config + DB.Find(&config) + return config +} +func InitConfig(){ + CustomConfigs=FindConfigs() +} +func FindConfig(key string)string{ + for _,config:=range CustomConfigs{ + if key==config.ConfKey{ + return config.ConfValue + } + } + return "" +} \ No newline at end of file diff --git a/models/models.go b/models/models.go index faa0f0a..3a46c76 100644 --- a/models/models.go +++ b/models/models.go @@ -21,6 +21,8 @@ func init(){ DB.LogMode(true) DB.DB().SetMaxIdleConns(10) DB.DB().SetMaxOpenConns(100) + + InitConfig() } func Execute(sql string){ DB.Exec(sql) diff --git a/tmpl/chat.go b/tmpl/chat.go new file mode 100644 index 0000000..bd1312c --- /dev/null +++ b/tmpl/chat.go @@ -0,0 +1,34 @@ +package tmpl + +import ( + "github.com/gin-gonic/gin" + "github.com/taoshihan1991/imaptool/config" + "net/http" +) + +//咨询界面 +func PageChat(c *gin.Context) { + kefuId := c.Query("kefu_id") + lang,_ := c.Get("lang") + language:=config.CreateLanguage(lang.(string)) + refer := c.Query("refer") + if refer==""{ + refer=c.Request.Referer() + } + c.HTML(http.StatusOK, "chat_page.html", gin.H{ + "KEFU_ID":kefuId, + "SendBtn":language.Send, + "Lang":lang.(string), + "Refer":refer, + }) +} +func PageKfChat(c *gin.Context) { + kefuId := c.Query("kefu_id") + visitorId:=c.Query("visitor_id") + token:=c.Query("token") + c.HTML(http.StatusOK, "chat_kf_page.html", gin.H{ + "KefuId":kefuId, + "VisitorId":visitorId, + "Token":token, + }) +} diff --git a/tmpl/login.go b/tmpl/login.go index de9564c..c980905 100644 --- a/tmpl/login.go +++ b/tmpl/login.go @@ -2,7 +2,6 @@ package tmpl import ( "github.com/gin-gonic/gin" - "github.com/taoshihan1991/imaptool/config" "net/http" ) @@ -11,30 +10,5 @@ func PageLogin(c *gin.Context) { c.HTML(http.StatusOK, "login.html", nil) } -//咨询界面 -func PageChat(c *gin.Context) { - kefuId := c.Query("kefu_id") - lang,_ := c.Get("lang") - language:=config.CreateLanguage(lang.(string)) - refer := c.Query("refer") - if refer==""{ - refer=c.Request.Referer() - } - c.HTML(http.StatusOK, "chat_page.html", gin.H{ - "KEFU_ID":kefuId, - "SendBtn":language.Send, - "Lang":lang.(string), - "Refer":refer, - }) -} -func PageKfChat(c *gin.Context) { - kefuId := c.Query("kefu_id") - visitorId:=c.Query("visitor_id") - token:=c.Query("token") - c.HTML(http.StatusOK, "chat_kf_page.html", gin.H{ - "KefuId":kefuId, - "VisitorId":visitorId, - "Token":token, - }) -} +