From 4bdb6793523b33ea893b12620db5eebd65f45884 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Tue, 26 Jul 2016 18:27:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E5=BE=AE=E4=BF=A1token=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E5=88=B0rails=E4=BD=93=E7=B3=BB=E9=87=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .access_token | 1 - Gemfile | 2 ++ lib/email_verifier | 1 - lib/wechat/lib/wechat.rb | 1 + lib/wechat/lib/wechat/cache_file.rb | 25 +++++++++++++++++++ lib/wechat/lib/wechat/ticket/jsapi_base.rb | 4 +-- .../lib/wechat/token/access_token_base.rb | 4 +-- plugins/redmine_ckeditor/.gitmodules | 3 --- 8 files changed, 32 insertions(+), 9 deletions(-) delete mode 100644 .access_token delete mode 160000 lib/email_verifier create mode 100644 lib/wechat/lib/wechat/cache_file.rb delete mode 100644 plugins/redmine_ckeditor/.gitmodules diff --git a/.access_token b/.access_token deleted file mode 100644 index 2e228963c..000000000 --- a/.access_token +++ /dev/null @@ -1 +0,0 @@ -{"access_token":"b_Pc60Dd5eyg_ut3cHbsjQO9EJJdj2Qj5F99o9LH9ltKSme7_FZ3Of22lWLL-K2V0siWzv-bd9PO0Dn-L1PBvIy9LhXa0qPVaFl6vTtZHR2kA8qjo1ps2ancya0t7KmzURGbAFAAXM","expires_in":7200,"got_token_at":1467976842} \ No newline at end of file diff --git a/Gemfile b/Gemfile index a94f1b33b..6e8a4dcdf 100644 --- a/Gemfile +++ b/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' diff --git a/lib/email_verifier b/lib/email_verifier deleted file mode 160000 index 222a9bdd7..000000000 --- a/lib/email_verifier +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 222a9bdd72014f197baf2131ab71cc41660111ed diff --git a/lib/wechat/lib/wechat.rb b/lib/wechat/lib/wechat.rb index 266e1aa06..c223844b7 100644 --- a/lib/wechat/lib/wechat.rb +++ b/lib/wechat/lib/wechat.rb @@ -1,3 +1,4 @@ +require 'wechat/cache_file.rb' require 'wechat/api_loader' require 'wechat/api' require 'wechat/corp_api' diff --git a/lib/wechat/lib/wechat/cache_file.rb b/lib/wechat/lib/wechat/cache_file.rb new file mode 100644 index 000000000..0e51b24ee --- /dev/null +++ b/lib/wechat/lib/wechat/cache_file.rb @@ -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 + diff --git a/lib/wechat/lib/wechat/ticket/jsapi_base.rb b/lib/wechat/lib/wechat/ticket/jsapi_base.rb index b6ab510a0..cc02ce243 100644 --- a/lib/wechat/lib/wechat/ticket/jsapi_base.rb +++ b/lib/wechat/lib/wechat/ticket/jsapi_base.rb @@ -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 diff --git a/lib/wechat/lib/wechat/token/access_token_base.rb b/lib/wechat/lib/wechat/token/access_token_base.rb index 7b8cecfac..ba980e319 100644 --- a/lib/wechat/lib/wechat/token/access_token_base.rb +++ b/lib/wechat/lib/wechat/token/access_token_base.rb @@ -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 diff --git a/plugins/redmine_ckeditor/.gitmodules b/plugins/redmine_ckeditor/.gitmodules deleted file mode 100644 index de30e7590..000000000 --- a/plugins/redmine_ckeditor/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "app/assets/javascripts/ckeditor-releases"] - path = app/assets/javascripts/ckeditor-releases - url = git://github.com/ckeditor/ckeditor-releases.git