微信二维码过期问题修改

This commit is contained in:
yuanke 2016-09-18 10:50:40 +08:00
parent ede580d03a
commit 65bd77f0ff
4 changed files with 14 additions and 2 deletions

View File

@ -495,10 +495,11 @@ class Course < ActiveRecord::Base
def generate_qrcode
ticket = self.qrcode
if !ticket || ticket.size < 10
if !ticket || ticket.size < 10 || (Time.now.to_i > self.qrcode_expiretime)
response = Wechat.api.qrcode_create_scene(invite_code, 2592000)
logger.debug "response = #{response}"
self.qrcode = response['ticket']
self.qrcode_expiretime = Time.now.to_i+response['expire_seconds']
save! && reload
ticket = qrcode
end

View File

@ -930,10 +930,11 @@ class Project < ActiveRecord::Base
def generate_qrcode
ticket = self.qrcode
if !ticket || ticket.size < 10
if !ticket || ticket.size < 10 || (Time.now.to_i > self.qrcode_expiretime)
response = Wechat.api.qrcode_create_scene(invite_code, 2592000)
logger.debug "response = #{response}"
self.qrcode = response['ticket']
self.qrcode_expiretime = Time.now.to_i+response['expire_seconds']
save!
ticket = qrcode
end

View File

@ -0,0 +1,5 @@
class AddQrcodeExpiretimeToCourses < ActiveRecord::Migration
def change
add_column :courses, :qrcode_expiretime, :integer, :default => 0
end
end

View File

@ -0,0 +1,5 @@
class AddQrcodeExpiretimeToProjects < ActiveRecord::Migration
def change
add_column :projects, :qrcode_expiretime, :integer, :default => 0
end
end