session.go 651 B

123456789101112131415161718192021222324252627282930
  1. package models
  2. import (
  3. "rdluck_tools/orm"
  4. "time"
  5. )
  6. type Session struct {
  7. SessionId int `orm:"column(session_id);pk"`
  8. UserId int
  9. OpenId string
  10. AccessToken string
  11. ExpireTime time.Time
  12. CreatedTime time.Time
  13. LastUpdatedTime time.Time
  14. }
  15. func GetSessionByToken(token string) (item *Session, err error) {
  16. sql := `SELECT * FROM session WHERE access_token=? AND expired_time> NOW() ORDER BY expired_time DESC LIMIT 1 `
  17. o := orm.NewOrm()
  18. err = o.Raw(sql, token).QueryRow(&item)
  19. return
  20. }
  21. //添加用户信息
  22. func AddSession(item *Session) (err error) {
  23. o := orm.NewOrm()
  24. _, err = o.Insert(item)
  25. return
  26. }