Sha256: ab3ebcd1bd25218ee7141d20b06ff4edfae5b8fd411416a8a6b9757a5852ed84

Contents?: true

Size: 1.19 KB

Versions: 20

Compression:

Stored size: 1.19 KB

Contents

# coding: utf-8
module BlsmMpWx
  class VdMpWx < BaseRecord
    self.table_name='vd_mp_wxes'
    validates_uniqueness_of :app_id

    #判断access_token是否过期了
    def access_token_expired?
      return true unless self.access_token
      return true unless self.access_token_expire
      DateTime.now.to_time > self.access_token_expire.to_time
    end

    #判断js_api_ticket是否过期了
    def js_api_ticket_expired?
      return true unless self.js_api_ticket
      return true unless self.js_api_ticket_expire
      DateTime.now.to_time > self.js_api_ticket_expire.to_time
    end

    #保存token的有效期
    def save_access_token(access_token, expires_in)
      update_attributes({
                            access_token: access_token,
                            access_token_expire: Time.at(DateTime.now.to_time.to_i + expires_in.to_i/4)
                        })
    end

    #保存js_api_ticket
    def save_js_api_ticket(js_api_ticket, expires_in)
      update_attributes({
                            js_api_ticket: js_api_ticket,
                            js_api_ticket_expire: Time.at(DateTime.now.to_time.to_i + expires_in.to_i/4)
                        })
    end


  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
blsm-mp-wx-0.3.6 lib/blsm-mp-wx/model/vd_mp_wx.rb
blsm-mp-wx-0.3.5 lib/blsm-mp-wx/model/vd_mp_wx.rb
blsm-mp-wx-0.3.4 lib/blsm-mp-wx/model/vd_mp_wx.rb
blsm-mp-wx-0.3.3 lib/blsm-mp-wx/model/vd_mp_wx.rb
blsm-mp-wx-0.3.2 lib/blsm-mp-wx/model/vd_mp_wx.rb
blsm-mp-wx-0.3.0 lib/blsm-mp-wx/model/vd_mp_wx.rb
blsm-mp-wx-0.2.8 lib/blsm-mp-wx/model/vd_mp_wx.rb
blsm-mp-wx-0.2.7 lib/blsm-mp-wx/model/vd_mp_wx.rb
blsm-mp-wx-0.2.6 lib/blsm-mp-wx/model/vd_mp_wx.rb
blsm-mp-wx-0.2.5 lib/blsm-mp-wx/model/vd_mp_wx.rb
blsm-mp-wx-0.2.4 lib/blsm-mp-wx/model/vd_mp_wx.rb
blsm-mp-wx-0.2.3 lib/blsm-mp-wx/model/vd_mp_wx.rb
blsm-mp-wx-0.2.2 lib/blsm-mp-wx/model/vd_mp_wx.rb
blsm-mp-wx-0.2.1 lib/blsm-mp-wx/model/vd_mp_wx.rb
blsm-mp-wx-0.1.9 lib/blsm-mp-wx/model/vd_mp_wx.rb
blsm-mp-wx-0.1.8 lib/blsm-mp-wx/model/vd_mp_wx.rb
blsm-mp-wx-0.1.7 lib/blsm-mp-wx/model/vd_mp_wx.rb
blsm-mp-wx-0.1.6 lib/blsm-mp-wx/model/vd_mp_wx.rb
blsm-mp-wx-0.1.5 lib/blsm-mp-wx/model/vd_mp_wx.rb
blsm-mp-wx-0.1.1 lib/blsm_mp_wx/model/vd_mp_wx.rb