package models type WxToken struct { Id int `gorm:"column:id;primaryKey;autoIncrement:'id'"` AccessToken string `gorm:"column:access_token;type:varchar(512);comment:微信token"` ExpiresIn int64 `gorm:"column:expires_in;type:timestamps;comment:过期时间"` // 过期时间 } func RegisterWxToken(wxToken *WxToken) (err error) { err = Main().Table("wx_token").Create(&wxToken).Error return } func UpdateWxToken(accessToken string, expiresIn int64) (err error) { err = Main().Table("wx_token").Where("id = ?", 0).Updates(map[string]interface{}{"access_token": accessToken, "expires_in": expiresIn}).Error return } // GetById 根据id获取accessToken信息 func GetWxTokenById() (info WxToken, err error) { err = Main().Table("wx_token").Unscoped().Where("id", 0).First(&info).Error return }