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
053755de
Commit
053755de
authored
Mar 29, 2014
by
lanrion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed bug when invoke is_valid? twice
parent
869dfd9e
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
3 deletions
+12
-3
lib/weixin_authorize/client.rb
+3
-3
spec/api/user_spec.rb
+9
-0
No files found.
lib/weixin_authorize/client.rb
View file @
053755de
...
@@ -33,6 +33,8 @@ module WeixinAuthorize
...
@@ -33,6 +33,8 @@ module WeixinAuthorize
# 检查appid和app_secret是否有效。
# 检查appid和app_secret是否有效。
def
is_valid?
def
is_valid?
# 重新验证,清除存储在Redis的access_token
weixin_redis
.
del
(
redis_key
)
if
!
is_weixin_redis_blank?
valid_result
=
http_get_access_token
valid_result
=
http_get_access_token
if
valid_result
.
keys
.
include?
(
"access_token"
)
if
valid_result
.
keys
.
include?
(
"access_token"
)
set_access_token_for_client
(
valid_result
)
set_access_token_for_client
(
valid_result
)
...
@@ -55,15 +57,13 @@ module WeixinAuthorize
...
@@ -55,15 +57,13 @@ module WeixinAuthorize
# authenticate access_token
# authenticate access_token
def
authenticate
def
authenticate
raise
"APPID or APPSECRET is invalid"
if
!
is_valid?
raise
"APPID or APPSECRET is invalid"
if
!
is_valid?
if
is_weixin_redis_blank?
set_access_token_for_client
set_access_token_for_client
else
if
!
is_weixin_redis_blank?
authenticate_with_redis
authenticate_with_redis
end
end
end
end
def
authenticate_with_redis
def
authenticate_with_redis
set_access_token_for_client
weixin_redis
.
hmset
(
redis_key
,
:access_token
,
access_token
,
:expired_at
,
expired_at
)
weixin_redis
.
hmset
(
redis_key
,
:access_token
,
access_token
,
:expired_at
,
expired_at
)
weixin_redis
.
expireat
(
redis_key
,
expired_at
.
to_i
-
10
)
# 提前10秒超时
weixin_redis
.
expireat
(
redis_key
,
expired_at
.
to_i
-
10
)
# 提前10秒超时
end
end
...
...
spec/api/user_spec.rb
View file @
053755de
...
@@ -7,7 +7,16 @@ describe WeixinAuthorize::Api::User do
...
@@ -7,7 +7,16 @@ describe WeixinAuthorize::Api::User do
end
end
it
"can get followers infos"
do
it
"can get followers infos"
do
valid_info
=
$client
.
is_valid?
expect
(
valid_info
).
to
eq
(
true
)
followers
=
$client
.
followers
followers
=
$client
.
followers
expect
(
followers
.
keys
).
to
eq
([
"total"
,
"count"
,
"data"
,
"next_openid"
])
expect
(
followers
.
keys
).
to
eq
([
"total"
,
"count"
,
"data"
,
"next_openid"
])
puts
valid_info
valid_info
=
$client
.
is_valid?
expect
(
valid_info
).
to
eq
(
true
)
followers
=
$client
.
followers
expect
(
followers
.
keys
).
to
eq
([
"total"
,
"count"
,
"data"
,
"next_openid"
])
puts
valid_info
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