From c7ce4c6b25dcd872e90a25676dda09f1406eb73b Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Thu, 16 May 2024 18:16:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/db/db_master_list_cfg.go | 31 +++++++++++++++++++++++++++++++ app/hdl/hdl_kuaishou_auth.go | 17 +++++++---------- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/app/db/db_master_list_cfg.go b/app/db/db_master_list_cfg.go index ce4ced2..f8a9452 100644 --- a/app/db/db_master_list_cfg.go +++ b/app/db/db_master_list_cfg.go @@ -98,3 +98,34 @@ func (masterListCfgDb *MasterListCfgDb) MasterListCfgDel(HKey string) error { } return nil } + +func MasterListCfgGetOneData(uid, key string) string { + var cfgList model.MasterListCfg + has, err := ZhimengDb.Where("`k`=? and uid=?", key, uid).Get(&cfgList) + if err != nil { + return "" + } + if has == false { + cfgList = model.MasterListCfg{Uid: uid, K: key} + ZhimengDb.InsertOne(&cfgList) + } + return cfgList.V +} +func MasterListCfgGetKeyAll(key string) *[]model.MasterListCfg { + var cfgList []model.MasterListCfg + err := ZhimengDb.Where("`k`=? ", key).Find(&cfgList) + if err != nil { + return nil + } + return &cfgList +} +func MasterListCfgSave(uid, key, val string) { + var cfgList model.MasterListCfg + has, err := ZhimengDb.Where("`k`=? and uid=?", key, uid).Get(&cfgList) + if err != nil || has == false { + return + } + cfgList.V = val + ZhimengDb.Where("`k`=? and uid=?", key, uid).Update(&cfgList) + return +} diff --git a/app/hdl/hdl_kuaishou_auth.go b/app/hdl/hdl_kuaishou_auth.go index be44442..bb9da65 100644 --- a/app/hdl/hdl_kuaishou_auth.go +++ b/app/hdl/hdl_kuaishou_auth.go @@ -1,19 +1,16 @@ package hdl import ( - offical "applet/app/db/official" + "applet/app/db" "github.com/gin-gonic/gin" ) func KuaishouAuth(c *gin.Context) { - kuaishouOfficialAccessToken := offical.MasterListCfgGetOneData("0", "kuaishou_official_access_token") - kuaishouOfficialAccessToken = c.PostForm("access_token") - offical.MasterListCfgSave("0", "kuaishou_official_access_token", kuaishouOfficialAccessToken) - kuaishouOfficialExpiresIn := offical.MasterListCfgGetOneData("0", "kuaishou_official_expires_in") - kuaishouOfficialExpiresIn = c.PostForm("expires_in") - offical.MasterListCfgSave("0", "kuaishou_official_expires_in", kuaishouOfficialExpiresIn) - kuaishouOfficialRefreshToken := offical.MasterListCfgGetOneData("0", "kuaishou_official_refresh_token") - kuaishouOfficialRefreshToken = c.PostForm("refresh_token") - offical.MasterListCfgSave("0", "kuaishou_official_refresh_token", kuaishouOfficialRefreshToken) + kuaishouOfficialAccessToken := c.PostForm("access_token") + db.MasterListCfgSave("0", "kuaishou_official_access_token", kuaishouOfficialAccessToken) + kuaishouOfficialExpiresIn := c.PostForm("expires_in") + db.MasterListCfgSave("0", "kuaishou_official_expires_in", kuaishouOfficialExpiresIn) + kuaishouOfficialRefreshToken := c.PostForm("refresh_token") + db.MasterListCfgSave("0", "kuaishou_official_refresh_token", kuaishouOfficialRefreshToken) return }