增加配置项从数据库取

pull/30/head
taoshihan1991 4 years ago
parent 830d617be3
commit 23288d6021

@ -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(){
//配置文件

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

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

@ -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")

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

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

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

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

Loading…
Cancel
Save