# 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 #保存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 end end