third_party_wxa 0.2.8 → 0.2.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/third_party_wxa/api.rb +1 -1
- data/lib/third_party_wxa/config.rb +6 -2
- data/lib/third_party_wxa/plugin.rb +7 -33
- data/lib/third_party_wxa/token/local_store.rb +10 -10
- data/lib/third_party_wxa/token/redis_store.rb +13 -33
- data/lib/third_party_wxa/token/store.rb +6 -0
- data/lib/third_party_wxa/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d86a2b49ebb8160b49e2dc745611a5ea9ae9b88e3a89994ae2300ad6ab752a8
|
4
|
+
data.tar.gz: 28c917e3dd5c60b91773970dcfe64ef163e6991a0dd7d8277f01e260c4515909
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efbc0f2c2146249d6650c500479e66183938ce1bcc6e62b043823aedeb08ae178ec5db325d5d6abf6200fd39167c1ce95acf6f356396c8c634c1d7560465d0a8
|
7
|
+
data.tar.gz: 0b99ea68184fdff32c52515104cad80ab20c44f3cea89ca97114448c1ec431e29b332c6b27d99da45d93c62edd052f65288be736aec14e2c4e5db7e0eaf04717
|
data/lib/third_party_wxa/api.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module ThirdPartyWxa
|
2
2
|
|
3
3
|
class << self
|
4
|
-
|
4
|
+
|
5
5
|
attr_accessor :config
|
6
6
|
|
7
7
|
def configure
|
@@ -20,10 +20,14 @@ module ThirdPartyWxa
|
|
20
20
|
config.appsecret
|
21
21
|
end
|
22
22
|
|
23
|
+
def redis_key
|
24
|
+
config.redis_key
|
25
|
+
end
|
26
|
+
|
23
27
|
end
|
24
28
|
|
25
29
|
class Config
|
26
|
-
attr_accessor :redis, :appid, :appsecret
|
30
|
+
attr_accessor :redis, :appid, :appsecret, :redis_key
|
27
31
|
end
|
28
32
|
|
29
33
|
end
|
@@ -13,49 +13,31 @@ module ThirdPartyWxa
|
|
13
13
|
attr_accessor :component_verify_ticket, :ticket_expire_at
|
14
14
|
attr_accessor :component_access_token, :component_expire_at #2小时
|
15
15
|
attr_accessor :pre_auth_code, :pre_expire_at #10分钟
|
16
|
-
attr_accessor :token_store
|
16
|
+
attr_accessor :token_store, :redis_key
|
17
17
|
|
18
18
|
def initialize ticket = nil
|
19
19
|
@appid = ThirdPartyWxa.appid
|
20
20
|
@appsecret = ThirdPartyWxa.appsecret
|
21
21
|
@component_verify_ticket = ticket
|
22
22
|
@token_store = token_store_init
|
23
|
+
@redis_key = ThirdPartyWxa.redis_key || 'third_party_wxa_component_token'
|
23
24
|
p "third party wxa use #{@token_store.class.to_s}"
|
24
25
|
end
|
25
26
|
|
26
|
-
def test_case
|
27
|
-
a = {z: 1, x: 2, c: 3}
|
28
|
-
p a.slice!(:z, :x)
|
29
|
-
p a
|
30
|
-
nil
|
31
|
-
end
|
32
|
-
|
33
27
|
def set_tickect ticket, expire_in
|
34
28
|
@component_verify_ticket = ticket
|
35
29
|
@ticket_expire_at = ThirdPartyWxa.cal_expire_at expire_in
|
36
30
|
self
|
37
31
|
end
|
38
32
|
|
39
|
-
def component_access_token_valid?
|
40
|
-
return false if @component_access_token.nil? || @component_expire_at.nil?
|
41
|
-
Time.now.to_i <= @component_expire_at
|
42
|
-
end
|
43
|
-
|
44
33
|
def get_component_access_token
|
45
34
|
m = Mutex.new
|
46
35
|
m.synchronize{
|
47
|
-
|
48
|
-
|
36
|
+
token_store.set_token if !token_store.valid?
|
37
|
+
token_store.get_token
|
49
38
|
}
|
50
39
|
end
|
51
40
|
|
52
|
-
def set_component_access_token
|
53
|
-
res = component_access_token_api
|
54
|
-
@component_access_token = res['component_access_token']
|
55
|
-
@component_expire_at = ThirdPartyWxa.cal_expire_at res['expires_in']
|
56
|
-
self
|
57
|
-
end
|
58
|
-
|
59
41
|
def pre_auth_code_valid?
|
60
42
|
return false if @pre_auth_code.nil? || @pre_expire_at.nil?
|
61
43
|
Time.now.to_i <= @pre_expire_at
|
@@ -77,20 +59,12 @@ module ThirdPartyWxa
|
|
77
59
|
Token::Store.init_with(self)
|
78
60
|
end
|
79
61
|
|
80
|
-
def authorizer_access_token_valid? options={}
|
81
|
-
token_store.authorizer_access_token_valid options
|
82
|
-
end
|
83
|
-
|
84
62
|
def get_authorizer_access_token options={}
|
85
|
-
|
86
|
-
end
|
87
|
-
|
88
|
-
def exchange_authorizer_access_token options={}
|
89
|
-
token_store.exchange_authorizer_access_token options
|
63
|
+
authorizer_access_token_api options.delete(:code)
|
90
64
|
end
|
91
65
|
|
92
66
|
def refresh_authorizer_access_token options={}
|
93
|
-
|
67
|
+
authorizer_access_token_fresh options.delete(:appid), options.delete(:refresh_token)
|
94
68
|
end
|
95
69
|
|
96
70
|
def http_get scope, url, url_params={}
|
@@ -120,7 +94,7 @@ module ThirdPartyWxa
|
|
120
94
|
end
|
121
95
|
|
122
96
|
def auth_token_params options
|
123
|
-
{access_token:
|
97
|
+
{access_token: options.delete(:access_token)}
|
124
98
|
end
|
125
99
|
|
126
100
|
def wx_redis
|
@@ -3,20 +3,20 @@ module ThirdPartyWxa
|
|
3
3
|
|
4
4
|
class LocalStore < Store
|
5
5
|
|
6
|
-
def
|
7
|
-
|
6
|
+
def valid?
|
7
|
+
return false if plugin.component_access_token.nil? || plugin.component_expire_at.nil?
|
8
|
+
Time.now.to_i <= plugin.component_expire_at
|
8
9
|
end
|
9
10
|
|
10
|
-
def
|
11
|
-
|
11
|
+
def set_token
|
12
|
+
res = plugin.component_access_token_api
|
13
|
+
plugin.component_access_token = res['component_access_token']
|
14
|
+
plugin.component_expire_at = ThirdPartyWxa.cal_expire_at res['expires_in']
|
15
|
+
plugin
|
12
16
|
end
|
13
17
|
|
14
|
-
def
|
15
|
-
plugin.
|
16
|
-
end
|
17
|
-
|
18
|
-
def refresh_authorizer_access_token options
|
19
|
-
plugin.authorizer_access_token_fresh options.delete(:appid), options.delete(:refresh_token)
|
18
|
+
def get_token
|
19
|
+
plugin.component_access_token
|
20
20
|
end
|
21
21
|
|
22
22
|
|
@@ -3,45 +3,25 @@ module ThirdPartyWxa
|
|
3
3
|
|
4
4
|
class RedisStore < Store
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
return false if wx_redis.hget(options[:redis_key], 'access_token').blank? || expire_at.blank?
|
10
|
-
Time.now.to_i <= expire_at.to_i
|
6
|
+
def valid?
|
7
|
+
return false if wx_redis.hget(plugin.redis_key, 'component_access_token').blank?
|
8
|
+
Time.now.to_i <= wx_redis.hget(plugin.redis_key, 'component_expire_at').to_i
|
11
9
|
end
|
12
10
|
|
13
|
-
def
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
else
|
20
|
-
raise 'refresh token is missing, please authorize again'
|
21
|
-
end
|
22
|
-
end
|
23
|
-
wx_redis.hget(options[:redis_key], 'access_token')
|
11
|
+
def set_token
|
12
|
+
res = plugin.component_access_token_api
|
13
|
+
wx_redis.hmset plugin.redis_key,
|
14
|
+
'component_access_token', res['component_access_token'],
|
15
|
+
'component_expire_at', ThirdPartyWxa.cal_expire_at(res['expires_in'])
|
16
|
+
plugin
|
24
17
|
end
|
25
18
|
|
26
|
-
def
|
27
|
-
|
28
|
-
authorizer_access_token = res['authorization_info']['authorizer_access_token']
|
29
|
-
authorizer_appid = res['authorization_info']['authorizer_appid']
|
30
|
-
authorizer_expire_at = ThirdPartyWxa.cal_expire_at res['authorization_info']['expires_in']
|
31
|
-
authorizer_refresh_token = res['authorization_info']['authorizer_refresh_token']
|
32
|
-
wx_redis.hset options[:redis_key], 'access_token', authorizer_access_token, 'appid', authorizer_appid,
|
33
|
-
'expire_at', authorizer_expire_at, 'refresh_token', authorizer_refresh_token
|
34
|
-
authorizer_access_token
|
19
|
+
def get_token
|
20
|
+
wx_redis.hget(plugin.redis_key, 'component_access_token')
|
35
21
|
end
|
36
22
|
|
37
|
-
def
|
38
|
-
|
39
|
-
authorizer_access_token = res['authorizer_access_token']
|
40
|
-
authorizer_expire_at = ThirdPartyWxa.cal_expire_at res['expires_in']
|
41
|
-
authorizer_refresh_token = res['authorizer_refresh_token']
|
42
|
-
wx_redis.hset options[:redis_key], 'access_token', authorizer_access_token,
|
43
|
-
'expire_at', authorizer_expire_at, 'refresh_token', authorizer_refresh_token
|
44
|
-
authorizer_access_token
|
23
|
+
def wx_redis
|
24
|
+
ThirdPartyWxa.wx_redis
|
45
25
|
end
|
46
26
|
|
47
27
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: third_party_wxa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hzy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-10-
|
11
|
+
date: 2019-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|