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