wx_token.go 820 B

1234567891011121314151617181920212223
  1. package models
  2. type WxToken struct {
  3. Id int `gorm:"column:id;primaryKey;autoIncrement:'id'"`
  4. AccessToken string `gorm:"column:access_token;type:varchar(512);comment:微信token"`
  5. ExpiresIn int64 `gorm:"column:expires_in;type:timestamps;comment:过期时间"` // 过期时间
  6. }
  7. func RegisterWxToken(wxToken *WxToken) (err error) {
  8. err = Main().Table("wx_token").Create(&wxToken).Error
  9. return
  10. }
  11. func UpdateWxToken(accessToken string, expiresIn int64) (err error) {
  12. err = Main().Table("wx_token").Where("id = ?", 0).Updates(map[string]interface{}{"access_token": accessToken, "expires_in": expiresIn}).Error
  13. return
  14. }
  15. // GetById 根据id获取accessToken信息
  16. func GetWxTokenById() (info WxToken, err error) {
  17. err = Main().Table("wx_token").Unscoped().Where("id", 0).First(&info).Error
  18. return
  19. }