wechat 0.8.2 → 0.8.3
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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +1 -3
- data/CHANGELOG.md +5 -0
- data/lib/wechat/controller_api.rb +43 -36
- data/lib/wechat/message.rb +4 -3
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b273bb48c285ec8d726d97d680156b5180f9a68
|
4
|
+
data.tar.gz: 92b12bbec57a35485761ecf3dc42d38b404dbf38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f044872a1d3403b948bb63cb9661cc0f2de98dd4b02b1a4bf22a94cc1a1863e99d2685090bfcd48b9cb567f61d6245468c53c9584e8d604efcf4c3ccfbc5af52
|
7
|
+
data.tar.gz: 4e1ba0770dc92898a9962d55d6e0738ce128cbd391ecb4f4a35bf240596baf3232877332cc743f5d84ea9e2d9cb76f398260eea3c33e94f769c44c131ffe37c7
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
@@ -1,3 +1 @@
|
|
1
|
-
|
2
|
-
���S8�!s��T�5N�
|
3
|
-
�7��-�4�WO�H_X~"��-(����U3�f�����(Ո�!�z���v�elF�7��Oi����x�}�˭��d��*?���J���<q�B7Z"�VC�.ݰķ��+k53\9��� ���U
|
1
|
+
��P��Dp�X���Lp1U�D����� ���S3@�D�vg�z��d�z1iO�[�|����k_>��
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v0.8.3 (released at 11/26/2016)
|
4
|
+
|
5
|
+
# Fix wechat template key has camelCase problem, by @RyanChenDji #159
|
6
|
+
# Fix long time of oauth2_state bug for wechat_oauth2 methods, by @IvanChou #162
|
7
|
+
|
3
8
|
## v0.8.2 (released at 11/2/2016)
|
4
9
|
|
5
10
|
# Bug which if not using multi-account but using web login.
|
@@ -12,61 +12,68 @@ module Wechat
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def wechat_oauth2(scope = 'snsapi_base', page_url = nil, &block)
|
15
|
-
appid = self.class.corpid || self.class.appid
|
16
|
-
if appid.blank?
|
15
|
+
appid = self.class.corpid || self.class.appid || lambda do
|
17
16
|
self.class.wechat # to initialize wechat_api_client at first time call wechat_oauth2
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
page_url ||= if self.class.trusted_domain_fullname
|
22
|
-
"#{self.class.trusted_domain_fullname}#{request.original_fullpath}"
|
23
|
-
else
|
24
|
-
request.original_url
|
25
|
-
end
|
26
|
-
redirect_uri = CGI.escape(page_url)
|
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
|
17
|
+
self.class.corpid || self.class.appid
|
18
|
+
end.call
|
19
|
+
raise 'Can not get corpid or appid, so please configure it first to using wechat_oauth2' if appid.blank?
|
32
20
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
21
|
+
wechat.jsapi_ticket.ticket if wechat.jsapi_ticket.oauth2_state.nil?
|
22
|
+
oauth2_params = {
|
23
|
+
appid: appid,
|
24
|
+
redirect_uri: page_url,
|
25
|
+
scope: scope,
|
26
|
+
response_type: 'code',
|
27
|
+
state: wechat.jsapi_ticket.oauth2_state
|
28
|
+
}
|
29
|
+
|
30
|
+
return generate_oauth2_url(oauth2_params) unless block_given?
|
31
|
+
self.class.corpid ? wechat_corp_oauth2(oauth2_params, &block) : wechat_public_oauth2(oauth2_params, &block)
|
39
32
|
end
|
40
33
|
|
41
34
|
private
|
42
35
|
|
43
|
-
def wechat_public_oauth2(
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
36
|
+
def wechat_public_oauth2(oauth2_params)
|
37
|
+
openid = cookies.signed_or_encrypted[:we_openid]
|
38
|
+
unionid = cookies.signed_or_encrypted[:we_unionid]
|
39
|
+
if openid.present?
|
40
|
+
yield openid, { 'openid' => openid, 'unionid' => unionid }
|
41
|
+
elsif params[:code].present? && params[:state] == oauth2_params[:state]
|
49
42
|
access_info = wechat.web_access_token(params[:code])
|
50
43
|
cookies.signed_or_encrypted[:we_openid] = { value: access_info['openid'], expires: self.class.oauth2_cookie_duration.from_now }
|
51
44
|
cookies.signed_or_encrypted[:we_unionid] = { value: access_info['unionid'], expires: self.class.oauth2_cookie_duration.from_now }
|
52
45
|
yield access_info['openid'], access_info
|
53
46
|
else
|
54
|
-
|
55
|
-
'unionid' => cookies.signed_or_encrypted[:we_unionid] }
|
47
|
+
redirect_to generate_oauth2_url(oauth2_params)
|
56
48
|
end
|
57
49
|
end
|
58
50
|
|
59
|
-
def wechat_corp_oauth2(
|
60
|
-
|
61
|
-
|
62
|
-
|
51
|
+
def wechat_corp_oauth2(oauth2_params)
|
52
|
+
userid = cookies.signed_or_encrypted[:we_userid]
|
53
|
+
deviceid = cookies.signed_or_encrypted[:we_deviceid]
|
54
|
+
if userid.present? && deviceid.present?
|
55
|
+
yield userid, { 'UserId' => userid, 'DeviceId' => deviceid }
|
56
|
+
elsif params[:code].present? && params[:state] == oauth2_params[:state]
|
63
57
|
userinfo = wechat.getuserinfo(params[:code])
|
64
58
|
cookies.signed_or_encrypted[:we_userid] = { value: userinfo['UserId'], expires: self.class.oauth2_cookie_duration.from_now }
|
65
59
|
cookies.signed_or_encrypted[:we_deviceid] = { value: userinfo['DeviceId'], expires: self.class.oauth2_cookie_duration.from_now }
|
66
60
|
yield userinfo['UserId'], userinfo
|
67
61
|
else
|
68
|
-
|
69
|
-
|
62
|
+
redirect_to generate_oauth2_url(oauth2_params)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def generate_oauth2_url(oauth2_params)
|
67
|
+
if oauth2_params[:redirect_uri].blank?
|
68
|
+
page_url = (td = self.class.trusted_domain_fullname) ? "#{td}#{request.original_fullpath}" : request.original_url
|
69
|
+
safe_query = request.query_parameters.reject { |k, _| %w(code state access_token).include? k }.to_query
|
70
|
+
oauth2_params[:redirect_uri] = page_url.sub(request.query_string, safe_query)
|
71
|
+
end
|
72
|
+
|
73
|
+
if oauth2_params[:scope] == 'snsapi_login'
|
74
|
+
"https://open.weixin.qq.com/connect/qrconnect?#{oauth2_params.to_query}#wechat_redirect"
|
75
|
+
else
|
76
|
+
"https://open.weixin.qq.com/connect/oauth2/authorize?#{oauth2_params.to_query}#wechat_redirect"
|
70
77
|
end
|
71
78
|
end
|
72
79
|
end
|
data/lib/wechat/message.rb
CHANGED
@@ -131,7 +131,7 @@ module Wechat
|
|
131
131
|
end
|
132
132
|
|
133
133
|
def template(opts = {})
|
134
|
-
template_fields =
|
134
|
+
template_fields = opts.symbolize_keys.slice(:template_id, :topcolor, :url, :data)
|
135
135
|
update(MsgType: 'template', Template: template_fields)
|
136
136
|
end
|
137
137
|
|
@@ -152,12 +152,13 @@ module Wechat
|
|
152
152
|
TO_JSON_ALLOWED = %w(touser msgtype content image voice video file music news articles template agentid).freeze
|
153
153
|
|
154
154
|
def to_json
|
155
|
+
keep_camel_case_key = message_hash[:MsgType] == 'template'
|
155
156
|
json_hash = deep_recursive(message_hash) do |key, value|
|
156
157
|
key = key.to_s
|
157
|
-
[(TO_JSON_KEY_MAP[key] || key.downcase), value]
|
158
|
+
[(TO_JSON_KEY_MAP[key] || (keep_camel_case_key ? key : key.downcase)), value]
|
158
159
|
end
|
160
|
+
json_hash = json_hash.transform_keys(&:downcase).select { |k, _v| TO_JSON_ALLOWED.include? k }
|
159
161
|
|
160
|
-
json_hash = json_hash.select { |k, _v| TO_JSON_ALLOWED.include? k }
|
161
162
|
case json_hash['msgtype']
|
162
163
|
when 'text'
|
163
164
|
json_hash['text'] = { 'content' => json_hash.delete('content') }
|
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.
|
4
|
+
version: 0.8.3
|
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-11-
|
34
|
+
date: 2016-11-26 00:00:00.000000000 Z
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: activesupport
|
metadata.gz.sig
CHANGED
Binary file
|