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
bdfb26e9
Commit
bdfb26e9
authored
Apr 21, 2016
by
lanrion
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #85 from wikimo/master
add config option for redis key expired
parents
555ac834
77af8d4d
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
13 additions
and
4 deletions
+13
-4
lib/weixin_authorize.rb
+4
-0
lib/weixin_authorize/config.rb
+5
-1
lib/weixin_authorize/js_ticket/store.rb
+1
-1
lib/weixin_authorize/token/redis_store.rb
+1
-1
lib/weixin_authorize/token/store.rb
+1
-1
spec/spec_helper.rb
+1
-0
No files found.
lib/weixin_authorize.rb
View file @
bdfb26e9
...
...
@@ -88,6 +88,10 @@ module WeixinAuthorize
"https://open.weixin.qq.com
#{
url
}
"
end
def
calculate_expire
(
expires_in
)
Time
.
now
+
expires_in
.
to_i
-
key_expired
end
end
end
lib/weixin_authorize/config.rb
View file @
bdfb26e9
...
...
@@ -13,6 +13,10 @@ module WeixinAuthorize
@redis
||=
config
.
redis
end
def
key_expired
config
.
key_expired
||
100
end
# 可选配置: RestClient timeout, etc.
# key 必须是符号
# 如果出现 RestClient::SSLCertificateNotVerified Exception: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
...
...
@@ -26,6 +30,6 @@ module WeixinAuthorize
end
class
Config
attr_accessor
:redis
,
:rest_client_options
attr_accessor
:redis
,
:rest_client_options
,
:key_expired
end
end
lib/weixin_authorize/js_ticket/store.rb
View file @
bdfb26e9
...
...
@@ -32,7 +32,7 @@ module WeixinAuthorize
def
set_jsticket
result
=
client
.
http_get
(
"/ticket/getticket"
,
{
type:
1
}).
result
client
.
jsticket
=
result
[
"ticket"
]
client
.
jsticket_expired_at
=
result
[
"expires_in"
]
+
Time
.
now
.
to_i
client
.
jsticket_expired_at
=
WeixinAuthorize
.
calculate_expire
(
result
[
"expires_in"
])
end
end
...
...
lib/weixin_authorize/token/redis_store.rb
View file @
bdfb26e9
...
...
@@ -19,7 +19,7 @@ module WeixinAuthorize
client
.
access_token
,
"expired_at"
,
client
.
expired_at
)
weixin_redis
.
expireat
(
client
.
redis_key
,
client
.
expired_at
.
to_i
-
100
)
# 提前10秒超时
weixin_redis
.
expireat
(
client
.
redis_key
,
client
.
expired_at
.
to_i
)
end
def
access_token
...
...
lib/weixin_authorize/token/store.rb
View file @
bdfb26e9
...
...
@@ -47,7 +47,7 @@ module WeixinAuthorize
def
set_access_token
(
access_token_infos
=
nil
)
token_infos
=
access_token_infos
||
http_get_access_token
.
result
client
.
access_token
=
token_infos
[
"access_token"
]
client
.
expired_at
=
Time
.
now
.
to_i
+
token_infos
[
"expires_in"
].
to_i
client
.
expired_at
=
WeixinAuthorize
.
calculate_expire
(
token_infos
[
"expires_in"
])
end
def
http_get_access_token
...
...
spec/spec_helper.rb
View file @
bdfb26e9
...
...
@@ -55,6 +55,7 @@ redis_with_ns = Redis::Namespace.new("#{namespace}", :redis => redis)
WeixinAuthorize
.
configure
do
|
config
|
config
.
redis
=
redis_with_ns
# config.key_expired = 200
config
.
rest_client_options
=
{
timeout:
10
,
open_timeout:
10
,
verify_ssl:
true
}
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