Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
weixin_authorize
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
weixin_authorize
Commits
1884fb75
Commit
1884fb75
authored
Mar 30, 2014
by
lanrion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added storage adapter
parent
19729d3d
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
69 additions
and
0 deletions
+69
-0
lib/weixin_authorize/adapter/storage.rb
+69
-0
No files found.
lib/weixin_authorize/adapter/storage.rb
0 → 100644
View file @
1884fb75
# encoding: utf-8
module
WeixinAuthorize
class
Storage
attr_accessor
:storage
def
initialize
(
storage
)
@storage
=
storage
end
def
self
.
init_with
(
storage
)
if
storage
.
is_a?
Client
ObjectStorage
.
new
(
storage
)
else
RedisStorage
.
new
(
storage
)
end
end
def
valid?
raise
NotImplementedError
,
"Subclasses must implement a valid? method"
end
def
token_expired?
raise
NotImplementedError
,
"Subclasses must implement a token_expired? method"
end
def
authenticate
raise
NotImplementedError
,
"Subclasses must implement a authenticate method"
end
def
get_access_token
end
end
class
RedisStorage
<
Storage
def
valid?
storage
.
del
(
storage
.
redis_key
)
end
def
token_expired?
storage
.
hvals
(
redis_key
).
empty?
end
def
authenticate
end
end
class
ObjectStorage
<
Storage
def
valid?
end
def
token_expired?
# 如果当前token过期时间小于现在的时间,则重新获取一次
stoage
.
expired_at
<=
Time
.
now
.
to_i
end
def
authenticate
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment