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
5d73b474
Commit
5d73b474
authored
Mar 27, 2014
by
lanrion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added is_valid? method to valid app_id and app_secret
parent
caa57a87
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
4 deletions
+19
-4
lib/weixin_authorize/client.rb
+19
-4
No files found.
lib/weixin_authorize/client.rb
View file @
5d73b474
...
...
@@ -37,12 +37,22 @@ module WeixinAuthorize
# authenticate access_token
def
authenticate
if
is_weixin_redis_blank?
http_get_access_token
set_access_token_for_client
else
authenticate_with_redis
end
end
# 检查appid和app_secret是否有效。
def
is_valid?
valid_result
=
http_get_access_token
if
valid_result
.
keys
.
include?
(
"access_token"
)
set_access_token_for_client
(
valid_result
)
return
true
end
false
end
def
token_expired?
if
is_weixin_redis_blank?
# 如果当前token过期时间小于现在的时间,则重新获取一次
...
...
@@ -55,15 +65,20 @@ module WeixinAuthorize
private
def
authenticate_with_redis
http_get_access_token
set_access_token_for_client
weixin_redis
.
hmset
(
redis_key
,
:access_token
,
access_token
,
:expired_at
,
expired_at
)
weixin_redis
.
expireat
(
redis_key
,
expired_at
.
to_i
-
10
)
# 提前10秒超时
end
def
set_access_token_for_client
(
access_token_infos
=
nil
)
token_infos
=
access_token_infos
||
http_get_access_token
self
.
access_token
=
token_infos
[
"access_token"
]
self
.
expired_at
=
Time
.
now
.
to_i
+
token_infos
[
"expires_in"
]
end
def
http_get_access_token
hash_infos
=
http_get_without_token
(
"/token"
,
authenticate_options
)
self
.
access_token
=
hash_infos
[
"access_token"
]
self
.
expired_at
=
Time
.
now
.
to_i
+
hash_infos
[
"expires_in"
]
hash_infos
end
def
authenticate_options
...
...
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