third_party_wxa 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6dffc2691e88b602b30d03ebe706b6dfb571e5b3c8dbffd8fbba08177fa4cb96
4
- data.tar.gz: 2711574efa8242f31566cf14338c8a1585c89c433b02e46bfdbc38e2d20de4a7
3
+ metadata.gz: 280928b0721a0434248e99da225d36754c1ccfa37871ceff0da650149aeae8a4
4
+ data.tar.gz: dd5825c6eef9f208ef353abc6b2375c7c93af1875654775f3aa09cedf97521c9
5
5
  SHA512:
6
- metadata.gz: 5c539156efc90e1c249537b70e5ffd1b997ce74de3a4ab0888b4ffad3986a287271cd5c2088c208b0a7545a5b4f23b7203728c4e9ea6b22144686dd9cbc52e5c
7
- data.tar.gz: 7df3a2d3d98a0f43cacdee0dfedb55d6e7e5c66cd069e82e3fe3593adb1b5a2b0b63a59dc9c2549d83f2b0e16b8b989003e0f7de62dfd0fd8172222fdd91fc7c
6
+ metadata.gz: 7ccee3ffb383e9ae8325ef9162a872d129d3cea7a95c885eef036ff5b49d31167832c5265e35c5f1b7aaa4b7c4e7910474b88b4ef5205c02542d3d304190d949
7
+ data.tar.gz: cc7b50cf0f3c00f56f1069d67d63aa4a26b51f1a2876be8cbe49499103efbe59403254fe349ae3bf23ae6b34ff6c08e4de3a7a129ea4ffd24950d7a8ea575767
data/Gemfile.lock CHANGED
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- third_party_wxa (0.1.3)
4
+ third_party_wxa (0.1.4)
5
5
  json (>= 1.8.6)
6
+ redis
6
7
  rest-client (>= 2.0)
7
8
 
8
9
  GEM
@@ -18,6 +19,7 @@ GEM
18
19
  mime-types-data (3.2018.0812)
19
20
  netrc (0.11.0)
20
21
  rake (10.4.2)
22
+ redis (4.1.2)
21
23
  rest-client (2.0.2)
22
24
  http-cookie (>= 1.0.2, < 2.0)
23
25
  mime-types (>= 1.16, < 4.0)
@@ -1,8 +1,10 @@
1
1
  module ThirdPartyWxa
2
2
  module Api
3
3
  module Authorize
4
- def componentloginpage_url redirect, type=2
5
- "https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid=#{appid}&pre_auth_code=#{get_pre_auth_code}&auth_type=#{type}&redirect_uri=#{redirect}"
4
+
5
+ def componentloginpage_url redirect, sign, type=2
6
+ redirect_uri = "#{redirect}?sign=#{sign}"
7
+ "https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid=#{appid}&pre_auth_code=#{get_pre_auth_code}&auth_type=#{type}&redirect_uri=#{redirect_uri}"
6
8
  end
7
9
 
8
10
  def bindcomponent redirect, type=2
@@ -19,8 +21,8 @@ module ThirdPartyWxa
19
21
 
20
22
  params = {
21
23
  "component_appid": appid,
22
- "authorizer_appid": authorizer_appid,
23
- "authorizer_refresh_token": authorizer_refresh_token,
24
+ "authorizer_appid": wx_redis.hget(sign, 'appid'),
25
+ "authorizer_refresh_token": wx_redis.hget(sign, 'refresh_token'),
24
26
  }
25
27
  http_post 'cgi-bin', 'component/api_authorizer_token', params
26
28
  end
@@ -4,25 +4,25 @@ module ThirdPartyWxa
4
4
 
5
5
  # 1、绑定微信用户为小程序体验者
6
6
  # https://api.weixin.qq.com/wxa/bind_tester?access_token=TOKEN
7
- def bind_tester test_id
8
- http_post_with_token 'wxa', 'bind_tester', {wechatid: test_id}
7
+ def bind_tester sign, test_id
8
+ http_post_with_token sign, 'wxa', 'bind_tester', {wechatid: test_id}
9
9
  end
10
10
 
11
11
  # 2、解除绑定小程序的体验者
12
12
  # https://api.weixin.qq.com/wxa/unbind_tester?access_token=TOKEN
13
- def unbind_tester test_id
14
- http_post_with_token 'wxa', 'unbind_tester', {wechatid: test_id}
13
+ def unbind_tester sign, test_id
14
+ http_post_with_token sign, 'wxa', 'unbind_tester', {wechatid: test_id}
15
15
  end
16
16
 
17
17
  # 3. 获取体验者列表
18
18
  # https://api.weixin.qq.com/wxa/memberauth?access_token=TOKEN
19
- def get_experiencer
20
- http_post_with_token 'wxa', 'memberauth', {action:"get_experiencer"}
19
+ def get_experiencer sign
20
+ http_post_with_token sign, 'wxa', 'memberauth', {action:"get_experiencer"}
21
21
  end
22
22
 
23
23
  # 发送消息
24
- def send_message query_auth_code
25
- http_post_with_token 'cgi-bin', 'memberauth', {"touser": "OPENID", "msgtype": "text", "text": {"content":"#{query_auth_code}_from_api"}}
24
+ def send_message sign, query_auth_code
25
+ http_post_with_token sign, 'cgi-bin', 'memberauth', {"touser": "OPENID", "msgtype": "text", "text": {"content":"#{query_auth_code}_from_api"}}
26
26
  end
27
27
 
28
28
 
@@ -4,44 +4,44 @@ module ThirdPartyWxa
4
4
 
5
5
  # 获取授权小程序帐号的可选类目
6
6
  # https://api.weixin.qq.com/wxa/get_category?access_token=TOKEN
7
- def get_category
8
- http_get_with_token 'wxa', 'get_category'
7
+ def get_category sign
8
+ http_get_with_token sign, 'wxa', 'get_category'
9
9
  end
10
10
 
11
11
  # 获取小程序的第三方提交代码的页面配置(仅供第三方开发者代小程序调用)
12
12
  # https://api.weixin.qq.com/wxa/get_page?access_token=TOKEN
13
- def get_page
14
- http_get_with_token 'wxa', 'get_page'
13
+ def get_page sign
14
+ http_get_with_token 'sign', 'wxa', 'get_page'
15
15
  end
16
16
 
17
17
  # 将第三方提交的代码包提交审核(仅供第三方开发者代小程序调用
18
18
  # https://api.weixin.qq.com/wxa/submit_audit?access_token=TOKEN
19
- def submit_audit config_json
20
- http_post_with_token 'wxa', 'submit_audit', config_json
19
+ def submit_audit sign, config_json
20
+ http_post_with_token 'sign', 'wxa', 'submit_audit', config_json
21
21
  end
22
22
 
23
23
  # 7、查询某个指定版本的审核状态(仅供第三方代小程序调用
24
24
  # https://api.weixin.qq.com/wxa/get_auditstatus?access_token=TOKEN
25
- def get_auditstatus auditid
26
- http_post_with_token 'wxa', 'get_auditstatus', {auditid: auditid}
25
+ def get_auditstatus sign, auditid
26
+ http_post_with_token sign, 'wxa', 'get_auditstatus', {auditid: auditid}
27
27
  end
28
28
 
29
29
  # 8、查询最新一次提交的审核状态(仅供第三方代小程序调用)
30
30
  # https://api.weixin.qq.com/wxa/get_latest_auditstatus?access_token=TOKEN
31
- def get_latest_auditstatus
32
- http_get_with_token 'wxa', 'get_latest_auditstatus'
31
+ def get_latest_auditstatus sign
32
+ http_get_with_token 'sign', 'wxa', 'get_latest_auditstatus'
33
33
  end
34
34
 
35
35
  # 9、发布已通过审核的小程序(仅供第三方代小程序调用)
36
36
  # https://api.weixin.qq.com/wxa/release?access_token=TOKEN
37
- def release
38
- http_post_with_token 'wxa', 'release'
37
+ def release sign
38
+ http_post_with_token sign, 'wxa', 'release'
39
39
  end
40
40
 
41
41
  # 10、修改小程序线上代码的可见状态(仅供第三方代小程序调用)close为不可见,open为可见
42
42
  # https://api.weixin.qq.com/wxa/change_visitstatus?access_token=TOKEN
43
- def change_visitstatus action
44
- http_post_with_token 'wxa', 'change_visitstatus', {action: action}
43
+ def change_visitstatus sign, action
44
+ http_post_with_token sign, 'wxa', 'change_visitstatus', {action: action}
45
45
  end
46
46
 
47
47
  end
@@ -5,17 +5,17 @@ module ThirdPartyWxa
5
5
  # 获取小程序码
6
6
  # 接口A: 适用于需要的码数量较少的业务场景 接口地址:
7
7
  # https://api.weixin.qq.com/wxa/getwxacode?access_token=ACCESS_TOKEN
8
- def get_wxa_code(path , width = 430 )
8
+ def get_wxa_code(sign, path , width = 430 )
9
9
  params
10
- http_post_with_token 'wxa', 'getwxacode', {path: path, width: width}
10
+ http_post_with_token sign, 'wxa', 'getwxacode', {path: path, width: width}
11
11
  end
12
12
 
13
13
  # 获取体验小程序的体验二维码
14
14
  # https://api.weixin.qq.com/wxa/ get_qrcode?access_token=TOKEN&path=page%2Findex%3Faction%3D1
15
- def get_qrcode(path = nil )
15
+ def get_qrcode(sign, path = nil)
16
16
  params = {}
17
17
  params.merge!({path: path}) if path.present?
18
- http_get_with_token 'wxa', 'get_qrcode', params
18
+ http_get_with_token sign, 'wxa', 'get_qrcode', params
19
19
  end
20
20
 
21
21
  end
@@ -0,0 +1,29 @@
1
+ module ThirdPartyWxa
2
+
3
+ class << self
4
+
5
+ attr_accessor :config
6
+
7
+ def configure
8
+ yield self.config ||= Config.new
9
+ end
10
+
11
+ def wx_redis
12
+ config.redis
13
+ end
14
+
15
+ def appid
16
+ config.appid
17
+ end
18
+
19
+ def appsecret
20
+ config.appsecret
21
+ end
22
+
23
+ end
24
+
25
+ class Config
26
+ attr_accessor :redis, :appid, :appsecret
27
+ end
28
+
29
+ end
@@ -12,12 +12,13 @@ module ThirdPartyWxa
12
12
  attr_accessor :component_verify_ticket, :ticket_expire_at
13
13
  attr_accessor :component_access_token, :component_expire_at #2小时
14
14
  attr_accessor :pre_auth_code, :pre_expire_at #10分钟
15
- attr_accessor :authorizer_appid
16
- attr_accessor :authorizer_access_token, :authorizer_refresh_token, :authorizer_expire_at
15
+ # attr_accessor :authorizer_appid
16
+ # attr_accessor :authorizer_access_token, :authorizer_refresh_token, :authorizer_expire_at
17
+ # attr_accessor :authorizer
17
18
 
18
19
  def initialize
19
- @appid = ENV['appid']
20
- @appsecret = ENV['appsecret']
20
+ @appid = ThirdPartyWxa.appid
21
+ @appsecret = ThirdPartyWxa.appsecret
21
22
  end
22
23
 
23
24
  def set_tickect ticket, expire_in
@@ -31,7 +32,7 @@ module ThirdPartyWxa
31
32
  @component_expire_at <= Time.now.to_i
32
33
  end
33
34
 
34
- def get_component_access_token
35
+ def get_component_access_token
35
36
  set_component_access_token if !component_access_token_valid?
36
37
  @component_access_token
37
38
  end
@@ -60,37 +61,42 @@ module ThirdPartyWxa
60
61
  self
61
62
  end
62
63
 
63
- def authorizer_access_token_valid?
64
- return false if @authorizer_access_token.nil? || @authorizer_expire_at.blank?
65
- @authorizer_expire_at <= Time.now.to_i
64
+ def authorizer_access_token_valid? sign
65
+ expire_at = wx_redis.hget sign, 'expire_at'
66
+ return false if wx_redis.hget(sign, 'access_token').blank? || expire_at.blank?
67
+ expire_at <= Time.now.to_i
66
68
  end
67
69
 
68
- def get_authorizer_access_token
70
+ def get_authorizer_access_token sign
69
71
  if !authorizer_access_token_valid? # raise exception?
70
- if @authorizer_refresh_token.present?
72
+ if wx_redis.hget(sign, 'refresh_token').present?
71
73
  refresh_authorizer_access_token
72
74
  else
73
- throw 'refresh token is missing, please authorize again'
75
+ raise 'refresh token is missing, please authorize again'
74
76
  end
75
77
  end
76
- @authorizer_access_token
78
+ wx_redis.hget(sign, 'access_token')
77
79
  end
78
80
 
79
- def set_authorizer_access_token code
81
+ def set_authorizer_access_token sign, code
80
82
  res = authorizer_access_token_api code
81
- @authorizer_access_token = res['authorization_info']['authorizer_access_token']
82
- @authorizer_appid = res['authorization_info']['authorizer_appid']
83
- @authorizer_expire_at = ThirdPartyWxa.cal_expire_at res['authorization_info']['expire_in']
84
- @authorizer_refresh_token = res['authorization_info']['authorizer_refresh_token']
85
- self
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
86
90
  end
87
91
 
88
- def refresh_authorizer_access_token
89
- res = authorizer_access_token_fresh
90
- @authorizer_access_token = res['authorizer_access_token']
91
- @authorizer_expire_at = ThirdPartyWxa.cal_expire_at res['expires_in']
92
- @authorizer_refresh_token = res['authorizer_refresh_token']
93
- self
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
94
100
  end
95
101
 
96
102
  def http_get scope, url, url_params={}
@@ -103,12 +109,12 @@ module ThirdPartyWxa
103
109
  ThirdPartyWxa.http_post_without_component_access_token scope, url, post_params, url_params
104
110
  end
105
111
 
106
- def http_get_with_token scope, url, url_params={}
112
+ def http_get_with_token sign, scope, url, url_params={}
107
113
  url_params.merge! auth_token_params
108
114
  ThirdPartyWxa.http_get_without_component_access_token scope, url, url_params
109
115
  end
110
116
 
111
- def http_post_with_token scope, url, post_params={}, url_params={}
117
+ def http_post_with_token sign, scope, url, post_params={}, url_params={}
112
118
  url_params.merge! auth_token_params
113
119
  ThirdPartyWxa.http_post_without_component_access_token scope, url, post_params, url_params
114
120
  end
@@ -119,8 +125,12 @@ module ThirdPartyWxa
119
125
  {access_token: get_component_access_token}
120
126
  end
121
127
 
122
- def auth_token_params
123
- {access_token: get_authorizer_access_token}
128
+ def auth_token_params sign
129
+ {access_token: get_authorizer_access_token(sign)}
130
+ end
131
+
132
+ def wx_redis
133
+ ThirdPartyWxa.wx_redis
124
134
  end
125
135
 
126
136
 
@@ -1,3 +1,3 @@
1
1
  module ThirdPartyWxa
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -1,5 +1,7 @@
1
- require "third_party_wxa/version"
2
1
  require 'rest_client'
2
+ require 'redis'
3
+ # require "third_party_wxa/version"
4
+ require 'third_party_wxa/config'
3
5
  require "third_party_wxa/api"
4
6
  require 'third_party_wxa/plugin'
5
7
  module ThirdPartyWxa
@@ -37,6 +37,7 @@ Gem::Specification.new do |spec|
37
37
 
38
38
  spec.add_dependency 'rest-client', ['>= 2.0']
39
39
  spec.add_dependency 'json', ['>=1.8.6']
40
+ spec.add_dependency 'redis'
40
41
 
41
42
  spec.add_development_dependency "bundler", "~> 2.0"
42
43
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: third_party_wxa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - hzy
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.8.6
41
+ - !ruby/object:Gem::Dependency
42
+ name: redis
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -88,6 +102,7 @@ files:
88
102
  - lib/third_party_wxa/api/qrcode.rb
89
103
  - lib/third_party_wxa/api/template.rb
90
104
  - lib/third_party_wxa/api/token.rb
105
+ - lib/third_party_wxa/config.rb
91
106
  - lib/third_party_wxa/plugin.rb
92
107
  - lib/third_party_wxa/version.rb
93
108
  - third_party_wxa.gemspec