package models import ( "github.com/beego/beego/v2/client/orm" "time" ) func GetSessionByToken(token string) (item *CygxXzsSession, err error) { sql := `SELECT * FROM cygx_xzs_session WHERE access_token=? AND expire_time> NOW() ORDER BY session_id DESC LIMIT 1 ` o := orm.NewOrmUsingDB("hz_cygx") err = o.Raw(sql, token).QueryRow(&item) return } type CygxXzsSession struct { SessionId int `orm:"column(session_id);pk"` UnionId string UserId int OpenId string AccessToken string ExpireTime time.Time CreatedTime time.Time LastUpdatedTime time.Time } // 添加用户session信息 func AddCygxXzsSession(item *CygxXzsSession) (err error) { o := orm.NewOrmUsingDB("hz_cygx") _, err = o.Insert(item) return } // 根据用户openid获取token func GetTokenByOpenId(openId string) (item *CygxXzsSession, err error) { sql := `SELECT * FROM cygx_xzs_session WHERE open_id=? AND expire_time> NOW() ORDER BY session_id DESC LIMIT 1 ` o := orm.NewOrmUsingDB("hz_cygx") err = o.Raw(sql, openId).QueryRow(&item) return }