From d6df81de11c06348e06db28f804a9c3a7425ad7e Mon Sep 17 00:00:00 2001 From: DengBiao <2319963317@qq.com> Date: Tue, 26 Sep 2023 11:33:44 +0800 Subject: [PATCH] update --- app/customer/hdl/hdl_login.go | 53 +++++++++++++++-------------------- 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/app/customer/hdl/hdl_login.go b/app/customer/hdl/hdl_login.go index 17afa5b..2615efc 100644 --- a/app/customer/hdl/hdl_login.go +++ b/app/customer/hdl/hdl_login.go @@ -11,6 +11,7 @@ import ( svc2 "applet/app/svc" "applet/app/utils" "applet/app/utils/cache" + "applet/app/utils/logx" "fmt" "github.com/gin-gonic/gin" "github.com/medivhzhan/weapp/v2" @@ -30,36 +31,28 @@ func WxAppletLogin(c *gin.Context) { e.OutErr(c, err1.Code, err1.Error()) return } - //userDb := db.UserDb{} - //userDb.Set() - //user, err := userDb.GetUserByOpenId(req.OpenID) - //if err != nil { - // e.OutErr(c, e.ERR_DB_ORM, err) - // return - //} - //if user == nil { - // now := time.Now() - // user = &model.User{ - // OpenId: user.UserId, - // UnionId: user.UnionId, - // UserId: "", - // Nickname: "", - // Avatar: "", - // Phone: "", - // Memo: "", - // CreateAt: now.Format("2006-01-02 15:04:05"), - // UpdateAt: now.Format("2006-01-02 15:04:05"), - // } - // insertAffected, err1 := userDb.UserInsert(user) - // if err1 != nil { - // e.OutErr(c, e.ERR_DB_ORM, err1) - // return - // } - // if insertAffected <= 0 { - // e.OutErr(c, e.ERR_DB_ORM, "新增用户数据失败") - // return - // } - //} + + // key是否存在 + cacheKey := md.WxSessionCacheKey + cacheKeyExist := false + if cache.Exists(cacheKey) { + cacheKeyExist = true + } + + // 设置缓存 + _, err = cache.HSet(cacheKey, req.OpenID, req.SessionKey) + if err != nil { + _ = logx.Error(err) + e.OutErr(c, e.ERR, err.Error()) + return + } + if !cacheKeyExist { // 如果是首次设置 设置过期时间 + //_, err := cache.Expire(cacheKey, md.CfgCacheTime) + //if err != nil { + // _ = logx.Error(err) + // return "" + //} + } e.OutSuc(c, md.WxAppletLoginResponse{ OpenId: req.OpenID,