1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- package wx_token
- import "hongze/hongze_yb/global"
- type WxToken struct {
- AccessToken string `gorm:"column:access_token;type:varchar(512);not null" json:"accessToken"`
- ExpiresIn int64 `gorm:"column:expires_in;type:bigint(20);not null" json:"expiresIn"`
- ID int `gorm:"primaryKey;column:id;type:int(11);not null" json:"-"`
- }
- func (m *WxToken) TableName() string {
- return "wx_token"
- }
- var WxTokenColumns = struct {
- AccessToken string
- ExpiresIn string
- ID string
- }{
- AccessToken: "access_token",
- ExpiresIn: "expires_in",
- ID: "id",
- }
- func GetAccessToken() (accessToken string, err error) {
- err = global.DEFAULT_MYSQL.Table("wx_token").Select("access_token").Where("id = ?", 0).Scan(&accessToken).Error
- return
- }
- func GetById() (info WxToken, err error) {
- err = global.DEFAULT_MYSQL.Where("id = ?", 0).First(&info).Error
- return
- }
- func SetAccessToken(accessToken string, expiresIn int64) (err error) {
- err = global.DEFAULT_MYSQL.Model(WxToken{}).Select("access_token,expires_in").Where("id = 0 ").Updates(WxToken{
- AccessToken: accessToken,
- ExpiresIn: expiresIn,
- }).Error
- return
- }
- func (wxToken *WxToken) Update(updateCols []string) (err error) {
- err = global.DEFAULT_MYSQL.Model(wxToken).Select(updateCols).Updates(*wxToken).Error
- return
- }
|