wechat 0.8.0 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e557486566741fde96f95013826e225fb60a8655
4
- data.tar.gz: bbcfb11df1063caf51f64ca68ab23c4ce41b0360
3
+ metadata.gz: ae9351f61a2b192bcb892dcdf95f85a540738b5a
4
+ data.tar.gz: 6d2b9e4c9ebb1e68195abe00ccec070f991f8b92
5
5
  SHA512:
6
- metadata.gz: d6b1b39c6d6e7cd385842041b8125534db5a3f8007e2e0e7e4e79700c6691f27edeb00e34bb79e3077b22a611f06ecb7f37212cb8e5fc0fac4d746d9efd5e984
7
- data.tar.gz: e6149d522aeefda20229604a835604a6d106f8f3a90194a5c498cb411cdeb1619e07752e84752951f3679a0e0530e5182fd687d7e5c02fa10362124fbd402d8e
6
+ metadata.gz: 1e8ccc4da8e5fec561612d22f3c2c7890d8447bd401e5c78541bf984378ecf2cc32473bc3d3b65a7dce7532b1872a0044b81ec9d54160f3f3552651476deb519
7
+ data.tar.gz: fe059c2d7670b4fdf92c18386adc4158fd4c8c8d6fabfb0844a20954d5dc6a38470a0796adc8e990413ee29ff757cd594b2060bf87aeab079b047384355df823
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.8.2 (released at 11/2/2016)
4
+
5
+ # Bug which if not using multi-account but using web login.
6
+
7
+ ## v0.8.1 (released at 11/2/2016)
8
+
9
+ * After allow sub controller using wechat_api, it's possible not initialise at first time. by @IvanChou #155
10
+ * Support web application login scope snsapi_login.
11
+ * Add unionid support for public account.
12
+ * Remove OpenId in Enterprise OAuth2 as it's not supported by Tecent.
13
+
3
14
  ## v0.8.0 (released at 10/24/2016)
4
15
 
5
16
  * Complete support multi-wechat public account. by @xiewenwei #150
@@ -2,23 +2,23 @@ module ActionController
2
2
  module WechatResponder
3
3
  def wechat_api(opts = {})
4
4
  include Wechat::ControllerApi
5
- self.wechat_api_client = load_controller_wechat(opts)
5
+ self.wechat_cfg_account = opts[:account].present? ? opts[:account].to_sym : :default
6
+ self.wechat_api_client = load_controller_wechat(wechat_cfg_account, opts)
6
7
  end
7
8
 
8
9
  def wechat_responder(opts = {})
9
10
  include Wechat::Responder
10
- self.wechat_api_client = load_controller_wechat(opts)
11
+ self.wechat_cfg_account = opts[:account].present? ? opts[:account].to_sym : :default
12
+ self.wechat_api_client = load_controller_wechat(wechat_cfg_account, opts)
11
13
  end
12
14
 
13
15
  def wechat
14
- self.wechat_api_client ||= load_controller_wechat
16
+ self.wechat_api_client ||= load_controller_wechat(wechat_cfg_account)
15
17
  end
16
18
 
17
19
  private
18
20
 
19
- def load_controller_wechat(opts = {})
20
- account = opts[:account].present? ? opts[:account].to_sym : :default
21
-
21
+ def load_controller_wechat(account, opts = {})
22
22
  self.token = opts[:token] || Wechat.config(account).token
23
23
  self.appid = opts[:appid] || Wechat.config(account).appid
24
24
  self.corpid = opts[:corpid] || Wechat.config(account).corpid
@@ -23,6 +23,7 @@ HELP
23
23
  @configs = nil
24
24
 
25
25
  def self.config(account = :default)
26
+ account = :default if account.nil?
26
27
  @configs ||= loading_config!
27
28
  @configs[account.to_sym] || raise("Wechat configuration for #{account} is missing.")
28
29
  end
@@ -3,7 +3,7 @@ module Wechat
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  module ClassMethods
6
- attr_accessor :wechat_api_client, :token, :appid, :corpid, :agentid, :encrypt_mode, :timeout,
6
+ attr_accessor :wechat_api_client, :wechat_cfg_account, :token, :appid, :corpid, :agentid, :encrypt_mode, :timeout,
7
7
  :skip_verify_ssl, :encoding_aes_key, :trusted_domain_fullname, :oauth2_cookie_duration
8
8
  end
9
9
 
@@ -13,13 +13,22 @@ module Wechat
13
13
 
14
14
  def wechat_oauth2(scope = 'snsapi_base', page_url = nil, &block)
15
15
  appid = self.class.corpid || self.class.appid
16
+ if appid.blank?
17
+ self.class.wechat # to initialize wechat_api_client at first time call wechat_oauth2
18
+ appid = self.class.corpid || self.class.appid
19
+ raise 'Can not get corpid or appid, so please configure it first to using wechat_oauth2' if appid.blank?
20
+ end
16
21
  page_url ||= if self.class.trusted_domain_fullname
17
22
  "#{self.class.trusted_domain_fullname}#{request.original_fullpath}"
18
23
  else
19
24
  request.original_url
20
25
  end
21
26
  redirect_uri = CGI.escape(page_url)
22
- oauth2_url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{appid}&redirect_uri=#{redirect_uri}&response_type=code&scope=#{scope}&state=#{wechat.jsapi_ticket.oauth2_state}#wechat_redirect"
27
+ if scope == 'snsapi_login'
28
+ oauth2_url = "https://open.weixin.qq.com/connect/qrconnect?appid=#{appid}&redirect_uri=#{redirect_uri}&response_type=code&scope=#{scope}&state=#{wechat.jsapi_ticket.oauth2_state}#wechat_redirect"
29
+ else
30
+ oauth2_url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{appid}&redirect_uri=#{redirect_uri}&response_type=code&scope=#{scope}&state=#{wechat.jsapi_ticket.oauth2_state}#wechat_redirect"
31
+ end
23
32
 
24
33
  return oauth2_url unless block_given?
25
34
  if self.class.corpid
@@ -39,9 +48,11 @@ module Wechat
39
48
  params[:state].to_s == wechat.jsapi_ticket.oauth2_state.to_s # params[:state] maybe '' and wechat.jsapi_ticket.oauth2_state may be nil
40
49
  access_info = wechat.web_access_token(params[:code])
41
50
  cookies.signed_or_encrypted[:we_openid] = { value: access_info['openid'], expires: self.class.oauth2_cookie_duration.from_now }
51
+ cookies.signed_or_encrypted[:we_unionid] = { value: access_info['unionid'], expires: self.class.oauth2_cookie_duration.from_now }
42
52
  yield access_info['openid'], access_info
43
53
  else
44
- yield cookies.signed_or_encrypted[:we_openid], { 'openid' => cookies.signed_or_encrypted[:we_openid] }
54
+ yield cookies.signed_or_encrypted[:we_openid], { 'openid' => cookies.signed_or_encrypted[:we_openid],
55
+ 'unionid' => cookies.signed_or_encrypted[:we_unionid] }
45
56
  end
46
57
  end
47
58
 
@@ -52,12 +63,10 @@ module Wechat
52
63
  userinfo = wechat.getuserinfo(params[:code])
53
64
  cookies.signed_or_encrypted[:we_userid] = { value: userinfo['UserId'], expires: self.class.oauth2_cookie_duration.from_now }
54
65
  cookies.signed_or_encrypted[:we_deviceid] = { value: userinfo['DeviceId'], expires: self.class.oauth2_cookie_duration.from_now }
55
- cookies.signed_or_encrypted[:we_openid] = { value: userinfo['OpenId'], expires: self.class.oauth2_cookie_duration.from_now }
56
66
  yield userinfo['UserId'], userinfo
57
67
  else
58
68
  yield cookies.signed_or_encrypted[:we_userid], { 'UserId' => cookies.signed_or_encrypted[:we_userid],
59
- 'DeviceId' => cookies.signed_or_encrypted[:we_deviceid],
60
- 'OpenId' => cookies.signed_or_encrypted[:we_openid] }
69
+ 'DeviceId' => cookies.signed_or_encrypted[:we_deviceid] }
61
70
  end
62
71
  end
63
72
  end
data/lib/wechat.rb CHANGED
@@ -25,7 +25,7 @@ module Wechat
25
25
 
26
26
  def self.api(account = :default)
27
27
  @wechat_apis ||= {}
28
- @wechat_apis[account.to_sym] ||= ApiLoader.with({account: account})
28
+ @wechat_apis[account.to_sym] ||= ApiLoader.with(account: account)
29
29
  end
30
30
  end
31
31
 
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wechat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Skinnyworm
@@ -31,7 +31,7 @@ cert_chain:
31
31
  R5k6Ma92sW8jupX4cqbSu9rntdVQkNRpoHIrfU0MZT0cKsg/D1zMteylxrO3KMsz
32
32
  SPQRv+nrI1J0zevFqb8010heoR8SDyUA0Mm3+Q==
33
33
  -----END CERTIFICATE-----
34
- date: 2016-10-24 00:00:00.000000000 Z
34
+ date: 2016-11-02 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: activesupport
@@ -206,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
206
206
  version: '0'
207
207
  requirements: []
208
208
  rubyforge_project:
209
- rubygems_version: 2.6.7
209
+ rubygems_version: 2.6.8
210
210
  signing_key:
211
211
  specification_version: 4
212
212
  summary: DSL for wechat message handling and API
metadata.gz.sig CHANGED
Binary file