123456789101112131415161718192021222324252627282930313233343536373839 |
- package models
- import (
- "github.com/beego/beego/v2/client/orm"
- "time"
- )
- func GetSessionByToken(token string) (item *CygxMfyxGzhSession, err error) {
- sql := `SELECT * FROM cygx_mfyx_gzh_session WHERE access_token=? AND expire_time> NOW() ORDER BY session_id DESC LIMIT 1 `
- o := orm.NewOrm()
- err = o.Raw(sql, token).QueryRow(&item)
- return
- }
- type CygxMfyxGzhSession 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 *CygxMfyxGzhSession) (err error) {
- o := orm.NewOrm()
- _, err = o.Insert(item)
- return
- }
- // 根据用户openid获取token
- func GetTokenByOpenId(openId string) (item *CygxMfyxGzhSession, err error) {
- sql := `SELECT * FROM cygx_mfyx_gzh_session WHERE open_id=? AND expire_time> NOW() ORDER BY session_id DESC LIMIT 1 `
- o := orm.NewOrm()
- err = o.Raw(sql, openId).QueryRow(&item)
- return
- }
|