123456789101112131415161718192021222324252627282930 |
- package session
- import (
- "gorm.io/gorm"
- "hongze/hongze_yb/global"
- "time"
- )
- // GetTokenByOpenId 根据用户id获取token
- func GetTokenByOpenId(openID string) (item *Session, err error) {
- err = getDb().Where("open_id = ? ", openID).First(&item).Error
- return
- }
- // GetTokenByToken 根据token获取信息
- func GetTokenByToken(token string) (item *Session, err error) {
- err = getDb().Where("access_token = ? and expire_time> ? ", token, time.Now()).Order("session_id DESC").First(&item).Error
- return
- }
- // 获取数据库链接
- func getDb() *gorm.DB {
- return global.MYSQL["rddp"]
- }
- // GetTokenByUid 根据用户id获取token
- func GetTokenByUid(userId int) (item *Session, err error) {
- err = getDb().Where("user_id = ? ", userId).First(&item).Error
- return
- }
|