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
a1513769
Commit
a1513769
authored
Apr 05, 2014
by
lanrion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor codes
parent
721a335f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
16 deletions
+31
-16
lib/weixin_authorize/adapter/redis_storage.rb
+1
-1
lib/weixin_authorize/adapter/storage.rb
+15
-14
lib/weixin_authorize/error_handler/result_handler.rb
+15
-1
No files found.
lib/weixin_authorize/adapter/redis_storage.rb
View file @
a1513769
...
...
@@ -15,7 +15,7 @@ module WeixinAuthorize
def
refresh_token
super
weixin_redis
.
hmset
(
client
.
redis_key
,
:access_token
,
client
.
access_token
,
:expired_at
,
client
.
expired_at
)
:expired_at
,
client
.
expired_at
)
weixin_redis
.
expireat
(
client
.
redis_key
,
client
.
expired_at
.
to_i
-
10
)
# 提前10秒超时
end
...
...
lib/weixin_authorize/adapter/storage.rb
View file @
a1513769
...
...
@@ -18,20 +18,17 @@ module WeixinAuthorize
end
def
valid?
valid
[
"valid"
]
authenticate
[
"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
{
"valid"
=>
true
,
"handler"
=>
valid_result
}
def
authenticate
auth_result
=
http_get_access_token
auth
=
false
if
auth_result
.
is_ok?
set_access_token_for_client
(
auth_result
.
result
)
auth
=
true
end
{
"valid"
=>
false
,
"handler"
=>
valid_result
}
end
def
token_expired?
raise
NotImplementedError
,
"Subclasses must implement a token_expired? method"
{
"valid"
=>
auth
,
"handler"
=>
auth_result
}
end
def
refresh_token
...
...
@@ -43,6 +40,10 @@ module WeixinAuthorize
refresh_token
if
token_expired?
end
def
token_expired?
raise
NotImplementedError
,
"Subclasses must implement a token_expired? method"
end
def
set_access_token_for_client
(
access_token_infos
=
nil
)
token_infos
=
access_token_infos
||
http_get_access_token
.
result
client
.
access_token
=
token_infos
[
"access_token"
]
...
...
@@ -60,9 +61,9 @@ module WeixinAuthorize
private
def
handle_valid_exception
valid_result
=
valid
if
!
valid
_result
[
"valid"
]
result_handler
=
valid
_result
[
"handler"
]
auth_result
=
authenticate
if
!
auth
_result
[
"valid"
]
result_handler
=
auth
_result
[
"handler"
]
raise
ValidAccessTokenException
,
"
#{
result_handler
.
code
}
:
#{
result_handler
.
en_msg
}
(
#{
result_handler
.
cn_msg
}
)"
end
end
...
...
lib/weixin_authorize/error_handler/result_handler.rb
View file @
a1513769
# encoding: utf-8
module
WeixinAuthorize
class
ResultHandler
...
...
@@ -12,6 +11,21 @@ module WeixinAuthorize
@result
=
package_result
(
result
)
end
# This method is to valid the current request if is true or is false
def
is_ok?
code
==
OK_CODE
end
# e.g.:
# 45009: api freq out of limit(接口调用超过限制)
def
full_message
"
#{
code
}
:
#{
en_msg
}
(
#{
cn_msg
}
)."
end
def
full_error_message
full_message
if
!
is_ok?
end
private
# if define Rails constant
...
...
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