1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- package wx_token
- import "hongze/hongze_yb/global"
- // WxToken [...]
- type WxToken struct {
- AccessToken string `gorm:"column:access_token;type:varchar(512);not null" json:"accessToken"` // 微信token
- 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:"-"` // id
- }
- // TableName get sql table name.获取数据库表名
- func (m *WxToken) TableName() string {
- return "wx_token"
- }
- // WxTokenColumns get sql column name.获取数据库列名
- var WxTokenColumns = struct {
- AccessToken string
- ExpiresIn string
- ID string
- }{
- AccessToken: "access_token",
- ExpiresIn: "expires_in",
- ID: "id",
- }
- // GetAccessToken 获取accessToken
- func GetAccessToken() (accessToken string, err error) {
- err = global.DEFAULT_MYSQL.Table("wx_token").Select("access_token").Where("id = ?", 0).Scan(&accessToken).Error
- return
- }
- // GetById 根据id获取accessToken信息
- func GetById() (info WxToken, err error) {
- err = global.DEFAULT_MYSQL.Where("id = ?", 0).First(&info).Error
- return
- }
- // SetAccessToken 设置accessToken
- 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
- }
- // Update 更新对应字段数据
- func (wxToken *WxToken) Update(updateCols []string) (err error) {
- err = global.DEFAULT_MYSQL.Model(wxToken).Select(updateCols).Updates(*wxToken).Error
- return
- }
|