third_party_wxa 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/third_party_wxa/api/authorize.rb +3 -3
- data/lib/third_party_wxa/plugin.rb +14 -32
- data/lib/third_party_wxa/token/local_store.rb +26 -0
- data/lib/third_party_wxa/token/redis_store.rb +51 -0
- data/lib/third_party_wxa/token/store.rb +26 -0
- data/lib/third_party_wxa/version.rb +1 -1
- data/lib/third_party_wxa.rb +8 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9a1361eab458413e4dbb16d7e239c177be96ebcf92dc89ab016e876c88647a8
|
4
|
+
data.tar.gz: 93a74483b992a8cb255c65555eb9476e1bafc3201e5557eb8f9527403cf6b7f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10bc4b22d61c06e568609d88d4d41c6f13c3ba9f1ef3e11705a1773a809d3c4b338bb01a4f662f28029d77473c8018690a57ca3edd9f105d32ec6baea536cd2c
|
7
|
+
data.tar.gz: 7674429c7029324b75cf00cbc16b38815e2ed1d382068fbeb86642441d1dadc7210ac944b5dc55c87d5cdbaa753bce1609bbe0e25d621343a6231835268af216
|
data/Gemfile.lock
CHANGED
@@ -17,12 +17,12 @@ module ThirdPartyWxa
|
|
17
17
|
end
|
18
18
|
|
19
19
|
#https:// api.weixin.qq.com /cgi-bin/component/api_authorizer_token?component_access_token=xxxxx
|
20
|
-
def authorizer_access_token_fresh
|
20
|
+
def authorizer_access_token_fresh auth_appid, refresh_token
|
21
21
|
|
22
22
|
params = {
|
23
23
|
"component_appid": appid,
|
24
|
-
"authorizer_appid":
|
25
|
-
"authorizer_refresh_token":
|
24
|
+
"authorizer_appid": auth_appid,
|
25
|
+
"authorizer_refresh_token": refresh_token,
|
26
26
|
}
|
27
27
|
http_post 'cgi-bin', 'component/api_authorizer_token', params
|
28
28
|
end
|
@@ -61,42 +61,24 @@ module ThirdPartyWxa
|
|
61
61
|
self
|
62
62
|
end
|
63
63
|
|
64
|
+
def token_store
|
65
|
+
Token::Store.init_with(self)
|
66
|
+
end
|
67
|
+
|
64
68
|
def authorizer_access_token_valid? sign
|
65
|
-
|
66
|
-
return false if wx_redis.hget(sign, 'access_token').blank? || expire_at.blank?
|
67
|
-
expire_at <= Time.now.to_i
|
69
|
+
token_store.authorizer_access_token_valid sign
|
68
70
|
end
|
69
71
|
|
70
72
|
def get_authorizer_access_token sign
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
def set_authorizer_access_token sign, code
|
82
|
-
res = authorizer_access_token_api code
|
83
|
-
authorizer_access_token = res['authorization_info']['authorizer_access_token']
|
84
|
-
authorizer_appid = res['authorization_info']['authorizer_appid']
|
85
|
-
authorizer_expire_at = ThirdPartyWxa.cal_expire_at res['authorization_info']['expire_in']
|
86
|
-
authorizer_refresh_token = res['authorization_info']['authorizer_refresh_token']
|
87
|
-
wx_redis.hset sign, 'access_token', authorizer_access_token, 'appid', authorizer_appid,
|
88
|
-
'expire_at', authorizer_expire_at, 'refresh_token', authorizer_refresh_token
|
89
|
-
authorizer_access_token
|
90
|
-
end
|
91
|
-
|
92
|
-
def refresh_authorizer_access_token sign
|
93
|
-
res = authorizer_access_token_fresh sign
|
94
|
-
authorizer_access_token = res['authorizer_access_token']
|
95
|
-
authorizer_expire_at = ThirdPartyWxa.cal_expire_at res['expires_in']
|
96
|
-
authorizer_refresh_token = res['authorizer_refresh_token']
|
97
|
-
wx_redis.hset sign, 'access_token', authorizer_access_token,
|
98
|
-
'expire_at', authorizer_expire_at, 'refresh_token', authorizer_refresh_token
|
99
|
-
authorizer_access_token
|
73
|
+
token_store.get_authorizer_access_token sign
|
74
|
+
end
|
75
|
+
|
76
|
+
def exchange_authorizer_access_token code, sign = nil
|
77
|
+
token_store.exchange_authorizer_access_token code, sign
|
78
|
+
end
|
79
|
+
|
80
|
+
def refresh_authorizer_access_token auth_appid, refresh_token
|
81
|
+
token_store.refresh_authorizer_access_token auth_appid, refresh_token
|
100
82
|
end
|
101
83
|
|
102
84
|
def http_get scope, url, url_params={}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module ThirdPartyWxa
|
2
|
+
module Token
|
3
|
+
|
4
|
+
class LocalStore < Store
|
5
|
+
|
6
|
+
def authorizer_access_token_valid *args
|
7
|
+
raise 'local_store --- please check expire_time yourself'
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_authorizer_access_token *args
|
11
|
+
raise 'local_store --- get token from your local store'
|
12
|
+
end
|
13
|
+
|
14
|
+
def exchange_authorizer_access_token code, sign=nil
|
15
|
+
plugin.authorizer_access_token_api code
|
16
|
+
end
|
17
|
+
|
18
|
+
def refresh_authorizer_access_token auth_appid, refresh_token
|
19
|
+
plugin.authorizer_access_token_fresh auth_appid, refresh_tokne
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module ThirdPartyWxa
|
2
|
+
module Token
|
3
|
+
|
4
|
+
class RedisStore < Store
|
5
|
+
|
6
|
+
|
7
|
+
def authorizer_access_token_valid? sign
|
8
|
+
expire_at = wx_redis.hget sign, 'expire_at'
|
9
|
+
return false if wx_redis.hget(sign, 'access_token').blank? || expire_at.blank?
|
10
|
+
expire_at <= Time.now.to_i
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_authorizer_access_token sign
|
14
|
+
if !authorizer_access_token_valid? # raise exception?
|
15
|
+
if wx_redis.hget(sign, 'refresh_token').present?
|
16
|
+
auth_appid = wx_redis.hget(sign, 'appid')
|
17
|
+
refresh_token = wx_redis.hget(sign, 'refresh_token')
|
18
|
+
refresh_authorizer_access_token auth_appid, refresh_token
|
19
|
+
else
|
20
|
+
raise 'refresh token is missing, please authorize again'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
wx_redis.hget(sign, 'access_token')
|
24
|
+
end
|
25
|
+
|
26
|
+
def exchange_authorizer_access_token code, sign
|
27
|
+
res = plugin.authorizer_access_token_api code
|
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']['expire_in']
|
31
|
+
authorizer_refresh_token = res['authorization_info']['authorizer_refresh_token']
|
32
|
+
wx_redis.hset sign, 'access_token', authorizer_access_token, 'appid', authorizer_appid,
|
33
|
+
'expire_at', authorizer_expire_at, 'refresh_token', authorizer_refresh_token
|
34
|
+
authorizer_access_token
|
35
|
+
end
|
36
|
+
|
37
|
+
def refresh_authorizer_access_token auth_appid, refresh_tokne
|
38
|
+
res = plugin.authorizer_access_token_fresh auth_appid, refresh_tokne
|
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 sign, 'access_token', authorizer_access_token,
|
43
|
+
'expire_at', authorizer_expire_at, 'refresh_token', authorizer_refresh_token
|
44
|
+
authorizer_access_token
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module ThirdPartyWxa
|
2
|
+
module Token
|
3
|
+
|
4
|
+
class Store
|
5
|
+
attr_accessor :plugin
|
6
|
+
|
7
|
+
def initialize plugin
|
8
|
+
@plugin = plugin
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.init_with plugin
|
12
|
+
if ThirdPartyWxa.wx_redis.nil?
|
13
|
+
LocalStore.new plugin
|
14
|
+
else
|
15
|
+
RedisStore.new plugin
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def wx_redis
|
20
|
+
ThirdPartyWxa.wx_redis
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
data/lib/third_party_wxa.rb
CHANGED
@@ -5,6 +5,14 @@ require 'third_party_wxa/config'
|
|
5
5
|
require "third_party_wxa/api"
|
6
6
|
require 'third_party_wxa/plugin'
|
7
7
|
module ThirdPartyWxa
|
8
|
+
|
9
|
+
module Token
|
10
|
+
autoload(:Store, "third_party_wxa/token/store")
|
11
|
+
autoload(:LocalStore, "third_party_wxa/token/local_store")
|
12
|
+
autoload(:RedisStore, "third_party_wxa/token/redis_store")
|
13
|
+
end
|
14
|
+
|
15
|
+
|
8
16
|
BASE = 'https://api.weixin.qq.com/'.freeze
|
9
17
|
# scope => [cgi-bin, wxa]
|
10
18
|
class << self
|
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.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hzy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-06-
|
11
|
+
date: 2019-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -104,6 +104,9 @@ files:
|
|
104
104
|
- lib/third_party_wxa/api/token.rb
|
105
105
|
- lib/third_party_wxa/config.rb
|
106
106
|
- lib/third_party_wxa/plugin.rb
|
107
|
+
- lib/third_party_wxa/token/local_store.rb
|
108
|
+
- lib/third_party_wxa/token/redis_store.rb
|
109
|
+
- lib/third_party_wxa/token/store.rb
|
107
110
|
- lib/third_party_wxa/version.rb
|
108
111
|
- third_party_wxa.gemspec
|
109
112
|
homepage: https://github.com/cs-cj/third_party_wxa
|