From 84f9a83f5585e38e3c66ce29c0c7927c74d88706 Mon Sep 17 00:00:00 2001 From: RockYang Date: Mon, 24 Jul 2023 18:18:09 +0800 Subject: [PATCH] =?UTF-8?q?opt:=20=E5=8F=96=E6=B6=88=E5=BC=BA=E5=88=B6?= =?UTF-8?q?=E6=89=8B=E6=9C=BA=E5=8F=B7=E9=AA=8C=E8=AF=81=EF=BC=8C=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/config.sample.toml | 29 ++++++++++++++++++++++++----- api/core/config.go | 2 +- api/core/types/config.go | 9 +++++---- api/handler/chat_handler.go | 4 ++++ api/handler/verify_handler.go | 2 +- api/main.go | 6 +++--- docker/conf/config.toml | 21 ++++++++++++++++----- web/src/views/ChatPlus.vue | 3 --- web/src/views/mobile/ChatList.vue | 3 --- 9 files changed, 54 insertions(+), 25 deletions(-) diff --git a/api/config.sample.toml b/api/config.sample.toml index b5c425ec..b1337cb1 100644 --- a/api/config.sample.toml +++ b/api/config.sample.toml @@ -1,12 +1,18 @@ Listen = "0.0.0.0:5678" -ProxyURL = "YOUR_PROXY_URL" -MysqlDns = "mysql_user:mysql_pass@tcp(localhost:3306)/chatgpt_plus?charset=utf8&parseTime=True&loc=Local" +ProxyURL = "http://172.22.11.200:7777" +MysqlDns = "root:mysql_pass@tcp(localhost:3306)/chatgpt_plus?charset=utf8mb4&collation=utf8mb4_unicode_ci&parseTime=True&loc=Local" +StaticDir = "./static" +StaticUrl = "http://localhost:5678/static" +AesEncryptKey = "YOUR_AES_KEY" +FunApiToken = "YOUR_FUN_API_TOKEN" +StartWechatBot = false [Session] - SecretKey = "azyehq3ivunjhbntz78isj00i4hz2mt9xtddysfucxakadq4qbfrt0b7q3lnvg80" + Driver = "cookie" + SecretKey = "m0cjm3gsuw9jk73np1ni7r42koilybjcndlycjdmq7za3pbqn7w12fyok5pqh6q5" Name = "CHAT_SESSION_ID" Path = "/" - Domain = "" + Domain = "localhost" MaxAge = 86400 Secure = false HttpOnly = false @@ -14,4 +20,17 @@ MysqlDns = "mysql_user:mysql_pass@tcp(localhost:3306)/chatgpt_plus?charset=utf8& [Manager] Username = "admin" - Password = "admin123" \ No newline at end of file + Password = "admin123" + +[Redis] + Host = "localhost" + Port = 6379 + Password = "" + +[SmsConfig] + AccessKey = "YOUR_ACCESS_KEY" + AccessSecret = "YOUR_SECRET_KEY" + Product = "Dysmsapi" + Domain = "dysmsapi.aliyuncs.com" + + diff --git a/api/core/config.go b/api/core/config.go index e870cc9a..637d78b6 100644 --- a/api/core/config.go +++ b/api/core/config.go @@ -33,7 +33,7 @@ func NewDefaultConfig() *types.AppConfig { HttpOnly: false, SameSite: http.SameSiteLaxMode, }, - AlApiToken: "", + FunApiToken: "", StartWechatBot: false, } } diff --git a/api/core/types/config.go b/api/core/types/config.go index ada71ca0..35cb0bf3 100644 --- a/api/core/types/config.go +++ b/api/core/types/config.go @@ -16,10 +16,11 @@ type AppConfig struct { StaticUrl string // 静态资源 URL Redis RedisConfig // redis 连接信息 - AesEncryptKey string - SmsConfig AliYunSmsConfig // 短信发送配置 - AlApiToken string // AL API 服务 token - StartWechatBot bool // 是否启动微信机器人 + AesEncryptKey string + SmsConfig AliYunSmsConfig // 短信发送配置 + FunApiToken string // 函数服务 API token + StartWechatBot bool // 是否启动微信机器人 + EnabledMsgService bool // 是否启用短信服务 } type AliYunSmsConfig struct { diff --git a/api/handler/chat_handler.go b/api/handler/chat_handler.go index b513bfd1..eba35eab 100644 --- a/api/handler/chat_handler.go +++ b/api/handler/chat_handler.go @@ -47,6 +47,10 @@ func (h *ChatHandler) ChatHandle(c *gin.Context) { logger.Error(err) return } + // 设置读写超时时间 + _ = ws.SetWriteDeadline(time.Now().Add(300 * time.Second)) + _ = ws.SetReadDeadline(time.Now().Add(300 * time.Second)) + sessionId := c.Query("session_id") roleId := h.GetInt(c, "role_id", 0) chatId := c.Query("chat_id") diff --git a/api/handler/verify_handler.go b/api/handler/verify_handler.go index a3c5a776..1154169d 100644 --- a/api/handler/verify_handler.go +++ b/api/handler/verify_handler.go @@ -46,6 +46,7 @@ type CodeStats struct { // Token 生成自验证 token func (h *VerifyHandler) Token(c *gin.Context) { // 如果不是通过浏览器访问,则返回错误的 token + // TODO: 引入验证码机制防刷机制 if c.GetHeader("Sec-Fetch-Mode") != "cors" { token := fmt.Sprintf("%s:%d", utils.RandString(32), time.Now().Unix()) encrypt, err := utils.AesEncrypt(h.App.Config.AesEncryptKey, []byte(token)) @@ -109,7 +110,6 @@ func (h *VerifyHandler) SendMsg(c *gin.Context) { var stat CodeStats err = h.db.Get(MobileStatPrefix+data.Mobile, &stat) if err != nil { - logger.Error(err) stat = CodeStats{ Mobile: data.Mobile, Count: 0, diff --git a/api/main.go b/api/main.go index 45fcdbb9..ec23f177 100644 --- a/api/main.go +++ b/api/main.go @@ -114,13 +114,13 @@ func main() { // 创建函数 fx.Provide(func(config *types.AppConfig) (function.FuncZaoBao, error) { - return function.NewZaoBao(config.AlApiToken), nil + return function.NewZaoBao(config.FunApiToken), nil }), fx.Provide(func(config *types.AppConfig) (function.FuncWeiboHot, error) { - return function.NewWeiboHot(config.AlApiToken), nil + return function.NewWeiboHot(config.FunApiToken), nil }), fx.Provide(func(config *types.AppConfig) (function.FuncHeadlines, error) { - return function.NewHeadLines(config.AlApiToken), nil + return function.NewHeadLines(config.FunApiToken), nil }), // 创建控制器 diff --git a/docker/conf/config.toml b/docker/conf/config.toml index b2a920b3..b1337cb1 100644 --- a/docker/conf/config.toml +++ b/docker/conf/config.toml @@ -1,15 +1,18 @@ Listen = "0.0.0.0:5678" ProxyURL = "http://172.22.11.200:7777" -MysqlDns = "root:12345678@tcp(172.28.173.76:3307)/chatgpt_plus?charset=utf8mb4&collation=utf8mb4_unicode_ci&parseTime=True&loc=Local" +MysqlDns = "root:mysql_pass@tcp(localhost:3306)/chatgpt_plus?charset=utf8mb4&collation=utf8mb4_unicode_ci&parseTime=True&loc=Local" StaticDir = "./static" -StaticUrl = "http://localhost:8080/static" +StaticUrl = "http://localhost:5678/static" +AesEncryptKey = "YOUR_AES_KEY" +FunApiToken = "YOUR_FUN_API_TOKEN" +StartWechatBot = false [Session] Driver = "cookie" - SecretKey = "8k0c67y2or1n7kbmn1w1c86ygqscguoktuf9t524jm64ls585z8uibpdssiy128s" - Name = "CHAT_PLUS_SESSION" + SecretKey = "m0cjm3gsuw9jk73np1ni7r42koilybjcndlycjdmq7za3pbqn7w12fyok5pqh6q5" + Name = "CHAT_SESSION_ID" Path = "/" - Domain = "" + Domain = "localhost" MaxAge = 86400 Secure = false HttpOnly = false @@ -23,3 +26,11 @@ StaticUrl = "http://localhost:8080/static" Host = "localhost" Port = 6379 Password = "" + +[SmsConfig] + AccessKey = "YOUR_ACCESS_KEY" + AccessSecret = "YOUR_SECRET_KEY" + Product = "Dysmsapi" + Domain = "dysmsapi.aliyuncs.com" + + diff --git a/web/src/views/ChatPlus.vue b/web/src/views/ChatPlus.vue index c6ee8c27..21054f8c 100644 --- a/web/src/views/ChatPlus.vue +++ b/web/src/views/ChatPlus.vue @@ -304,9 +304,6 @@ onMounted(() => { checkSession().then((user) => { loginUser.value = user isLogin.value = true - if (user.mobile === '') { - showBindMobileDialog.value = true - } // 加载角色列表 httpGet(`/api/role/list?user_id=${user.id}`).then((res) => { roles.value = res.data; diff --git a/web/src/views/mobile/ChatList.vue b/web/src/views/mobile/ChatList.vue index 89733623..3d30bc82 100644 --- a/web/src/views/mobile/ChatList.vue +++ b/web/src/views/mobile/ChatList.vue @@ -97,9 +97,6 @@ const showBindMobileDialog = ref(false) checkSession().then((user) => { loginUser.value = user isLogin.value = true - if (user.mobile === '') { - showBindMobileDialog.value = true - } // 加载角色列表 httpGet(`/api/role/list?user_id=${user.id}`).then((res) => { if (res.data) {