wx_sesssion.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package models
  2. import (
  3. "time"
  4. "github.com/beego/beego/v2/client/orm"
  5. )
  6. type WxSession struct {
  7. WxSessionId int `orm:"pk" description:"id"`
  8. OpenId string `description:"openId"`
  9. UnionId string `description:"unionId"`
  10. AccessToken string `description:"微信token"`
  11. CreateTime time.Time `description:"创建时间"`
  12. LastUpdateTime time.Time `description:"最后更新时间"`
  13. }
  14. func (w *WxSession) Insert() (insertId int64, err error) {
  15. o := orm.NewOrm()
  16. insertId, err = o.Insert(w)
  17. return
  18. }
  19. func (w *WxSession) Update(cols []string) (err error) {
  20. o := orm.NewOrm()
  21. _, err = o.Update(w, cols...)
  22. return
  23. }
  24. func GetWxSessionByAccessToken(accessToken string) (item *WxSession, err error) {
  25. o := orm.NewOrm()
  26. sql := `SELECT * FROM wx_session WHERE access_token = ?`
  27. err = o.Raw(sql, accessToken).QueryRow(&item)
  28. return
  29. }
  30. func GetWxSessionByOpenId(openId string) (item *WxSession, err error) {
  31. o := orm.NewOrm()
  32. sql := `SELECT * FROM wx_session WHERE open_id = ?`
  33. err = o.Raw(sql, openId).QueryRow(&item)
  34. return
  35. }