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
e9eac006
Commit
e9eac006
authored
Apr 05, 2014
by
lanrion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor storage
parent
1c7e65c2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
7 deletions
+21
-7
lib/weixin_authorize/adapter/client_storage.rb
+1
-1
lib/weixin_authorize/adapter/redis_storage.rb
+1
-1
lib/weixin_authorize/adapter/storage.rb
+19
-5
No files found.
lib/weixin_authorize/adapter/client_storage.rb
View file @
e9eac006
...
...
@@ -11,7 +11,7 @@ module WeixinAuthorize
client
.
expired_at
<=
Time
.
now
.
to_i
end
def
authenticate
def
refresh_token
super
end
...
...
lib/weixin_authorize/adapter/redis_storage.rb
View file @
e9eac006
...
...
@@ -12,7 +12,7 @@ module WeixinAuthorize
weixin_redis
.
hvals
(
client
.
redis_key
).
empty?
end
def
authenticate
def
refresh_token
super
weixin_redis
.
hmset
(
client
.
redis_key
,
:access_token
,
client
.
access_token
,
:expired_at
,
client
.
expired_at
)
...
...
lib/weixin_authorize/adapter/storage.rb
View file @
e9eac006
...
...
@@ -18,25 +18,29 @@ module WeixinAuthorize
end
def
valid?
valid
[
"valid"
]
end
def
valid
valid_result
=
http_get_access_token
if
valid_result
.
code
==
OK_CODE
set_access_token_for_client
(
valid_result
.
result
)
return
true
return
{
"valid"
=>
true
,
"handler"
=>
valid_result
}
end
false
{
"valid"
=>
false
,
"handler"
=>
valid_result
}
end
def
token_expired?
raise
NotImplementedError
,
"Subclasses must implement a token_expired? method"
end
def
authenticate
raise
"APPID or APPSECRET is invalid"
if
!
valid?
def
refresh_token
handle_valid_exception
set_access_token_for_client
end
def
access_token
authenticate
if
token_expired?
refresh_token
if
token_expired?
end
def
set_access_token_for_client
(
access_token_infos
=
nil
)
...
...
@@ -53,6 +57,16 @@ module WeixinAuthorize
{
grant_type:
"client_credential"
,
appid:
client
.
app_id
,
secret:
client
.
app_secret
}
end
private
def
handle_valid_exception
valid_result
=
valid
if
!
valid_result
[
"valid"
]
result_handler
=
valid_result
[
"handler"
]
raise
ValidAccessTokenException
,
"
#{
result_handler
.
code
}
:
#{
result_handler
.
en_msg
}
(
#{
result_handler
.
cn_msg
}
)"
end
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