wx_token.go 742 B

123456789101112131415161718192021222324252627282930
  1. package wx_token
  2. import "github.com/beego/beego/v2/client/orm"
  3. type WxToken struct {
  4. AccessToken string
  5. ExpiresIn int64
  6. Id int `orm:"column(id);pk"`
  7. }
  8. func GetWxToken() (item *WxToken, err error) {
  9. sql := `SELECT * FROM wx_token `
  10. o := orm.NewOrm()
  11. err = o.Raw(sql).QueryRow(&item)
  12. return
  13. }
  14. func AddWxToken(token string, expiresIn int64) (err error) {
  15. sql := `INSERT INTO wx_token(access_token, expires_in)VALUES(?,?) `
  16. o := orm.NewOrm()
  17. _, err = o.Raw(sql, token, expiresIn).Exec()
  18. return
  19. }
  20. func UpdateWxToken(token string, expiresIn int64, id int) (err error) {
  21. sql := `UPDATE wx_token SET access_token=?, expires_in=? WHERE id=? `
  22. o := orm.NewOrm()
  23. _, err = o.Raw(sql, token, expiresIn, id).Exec()
  24. return
  25. }