将微信token缓存到rails体系里面
This commit is contained in:
parent
652e56dec4
commit
4bdb679352
|
@ -1 +0,0 @@
|
|||
{"access_token":"b_Pc60Dd5eyg_ut3cHbsjQO9EJJdj2Qj5F99o9LH9ltKSme7_FZ3Of22lWLL-K2V0siWzv-bd9PO0Dn-L1PBvIy9LhXa0qPVaFl6vTtZHR2kA8qjo1ps2ancya0t7KmzURGbAFAAXM","expires_in":7200,"got_token_at":1467976842}
|
2
Gemfile
2
Gemfile
|
@ -49,6 +49,8 @@ gem 'kaminari'
|
|||
gem 'elasticsearch-model'
|
||||
gem 'elasticsearch-rails'
|
||||
|
||||
#rails 3.2.22.2 bug
|
||||
gem "test-unit", "~>3.0"
|
||||
|
||||
### profile
|
||||
# gem 'oneapm_rpm'
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
Subproject commit 222a9bdd72014f197baf2131ab71cc41660111ed
|
|
@ -1,3 +1,4 @@
|
|||
require 'wechat/cache_file.rb'
|
||||
require 'wechat/api_loader'
|
||||
require 'wechat/api'
|
||||
require 'wechat/corp_api'
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
#coding=utf-8
|
||||
#
|
||||
|
||||
module Wechat
|
||||
class CacheFile
|
||||
class << self
|
||||
def cache
|
||||
if defined?(Rails)
|
||||
Rails.cache
|
||||
else
|
||||
File
|
||||
end
|
||||
end
|
||||
|
||||
def read(key)
|
||||
cache.read(key) || ''
|
||||
end
|
||||
|
||||
def write(key, val)
|
||||
cache.write(key, val)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -44,7 +44,7 @@ module Wechat
|
|||
protected
|
||||
|
||||
def read_ticket_from_file
|
||||
td = JSON.parse(File.read(jsapi_ticket_file))
|
||||
td = JSON.parse(CacheFile.read(jsapi_ticket_file))
|
||||
@got_ticket_at = td.fetch('got_ticket_at').to_i
|
||||
@ticket_life_in_seconds = td.fetch('expires_in').to_i
|
||||
@access_ticket = td.fetch('ticket')
|
||||
|
@ -54,7 +54,7 @@ module Wechat
|
|||
|
||||
def write_ticket_to_file(ticket_hash)
|
||||
ticket_hash.merge!('got_ticket_at'.freeze => Time.now.to_i)
|
||||
File.write(jsapi_ticket_file, ticket_hash.to_json)
|
||||
CacheFile.write(jsapi_ticket_file, ticket_hash.to_json)
|
||||
end
|
||||
|
||||
def remain_life_seconds
|
||||
|
|
|
@ -21,7 +21,7 @@ module Wechat
|
|||
protected
|
||||
|
||||
def read_token_from_file
|
||||
td = JSON.parse(File.read(token_file))
|
||||
td = JSON.parse(CacheFile.read(token_file))
|
||||
@got_token_at = td.fetch('got_token_at').to_i
|
||||
@token_life_in_seconds = td.fetch('expires_in').to_i
|
||||
@access_token = td.fetch('access_token')
|
||||
|
@ -31,7 +31,7 @@ module Wechat
|
|||
|
||||
def write_token_to_file(token_hash)
|
||||
token_hash.merge!('got_token_at'.freeze => Time.now.to_i)
|
||||
File.write(token_file, token_hash.to_json)
|
||||
CacheFile.write(token_file, token_hash.to_json)
|
||||
end
|
||||
|
||||
def remain_life_seconds
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
[submodule "app/assets/javascripts/ckeditor-releases"]
|
||||
path = app/assets/javascripts/ckeditor-releases
|
||||
url = git://github.com/ckeditor/ckeditor-releases.git
|
Loading…
Reference in New Issue