wechat 0.7.4 → 0.7.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README-CN.md +22 -9
- data/README.md +18 -4
- data/lib/action_controller/wechat_responder.rb +6 -9
- data/lib/generators/wechat/templates/config/wechat.yml +1 -0
- data/lib/wechat.rb +3 -0
- data/lib/wechat/api_loader.rb +2 -1
- data/lib/wechat/helpers.rb +23 -0
- data/lib/wechat/responder.rb +5 -5
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51c5c439ece595c22e3382f948a56643c49fe613
|
4
|
+
data.tar.gz: 79f38b3fb01e9ffe6b6ef25beb214ff7976ce3f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22bc4cf0506b8a59f4f13c3bf209dff2e723693e40abb8472e3abf1578c3f155c133ed7f5861998e8f7a371250fbfdb726124ccb5c7e9950b5a8137a1766d65a
|
7
|
+
data.tar.gz: 1f8c0f29f74dd3ce86c6829a0f4bc594241ce70b0353946b886425332cf8d97c86bc531915d8d2c9b819438ac39d6bca76665001fd264971954f8e563d52cbf8
|
data/CHANGELOG.md
CHANGED
data/README-CN.md
CHANGED
@@ -13,10 +13,11 @@ WeChat gem 可以帮助开发者方便地在Rails环境中集成微信[公众平
|
|
13
13
|
|
14
14
|
命令行工具`wechat`可以调用各种无需web环境的API。同时也提供了Rails Controller的responder DSL, 可以帮助开发者方便地在Rails应用中集成微信的消息处理,包括主动推送的和被动响应的消息。
|
15
15
|
|
16
|
-
|
16
|
+
如果您的App还需要集成微信OAuth2.0, 您可以考虑[omniauth-wechat-oauth2](https://github.com/skinnyworm/omniauth-wechat-oauth2), 以便和devise集成,提供完整的用户认证。
|
17
17
|
|
18
|
-
|
18
|
+
如果您对如何制作微信网页UI没有灵感,可以参考官方的[weui](https://github.com/weui/weui),针对Rails的Gem是[weui-rails](https://github.com/Eric-Guo/weui-rails)。
|
19
19
|
|
20
|
+
如果您想从一个稍微完整一些的示例开始微信开发,可以参考[wechat-starter](https://github.com/goofansu/wechat-starter),这个示例甚至包括了微信支付的内容。
|
20
21
|
|
21
22
|
## 安装
|
22
23
|
|
@@ -104,6 +105,7 @@ production:
|
|
104
105
|
|
105
106
|
development:
|
106
107
|
<<: *default
|
108
|
+
trusted_domain_fullname: "http://your_dev.proxy.qqbrowser.cc"
|
107
109
|
|
108
110
|
test:
|
109
111
|
<<: *default
|
@@ -142,7 +144,8 @@ production:
|
|
142
144
|
|
143
145
|
development:
|
144
146
|
<<: *default
|
145
|
-
|
147
|
+
trusted_domain_fullname: "http://your_dev.proxy.qqbrowser.cc"
|
148
|
+
|
146
149
|
test:
|
147
150
|
<<: *default
|
148
151
|
```
|
@@ -171,14 +174,24 @@ class WechatFirstController < ActionController::Base
|
|
171
174
|
end
|
172
175
|
```
|
173
176
|
|
174
|
-
####
|
177
|
+
#### JS-SDK 支持
|
175
178
|
|
176
|
-
|
179
|
+
通过JS-SDK可以在HTML网页中控制微信客户端的行为,但必须先注入配置信息,wechat gems提供了帮助方法`wechat_config_js`使这个过程更简单:
|
177
180
|
|
178
|
-
```
|
179
|
-
|
181
|
+
```erb
|
182
|
+
<body>
|
183
|
+
<%= wechat_config_js debug: false, api: %w(hideMenuItems closeWindow) -%>
|
184
|
+
<script type="application/javascript">
|
185
|
+
wx.ready(function() {
|
186
|
+
wx.hideOptionMenu();
|
187
|
+
});
|
188
|
+
</script>
|
189
|
+
<a href="javascript:wx.closeWindow();">Close</a>
|
190
|
+
</body>
|
180
191
|
```
|
181
192
|
|
193
|
+
在开发模式下,由于程序往往通过微信调试工具的服务器端调试工具反向代理被访问,此时需要配置`trusted_domain_fullname`以便wechat gem可以使用正确的域名做JS-SDK的权限签名。
|
194
|
+
|
182
195
|
## 关于接口权限
|
183
196
|
|
184
197
|
wechat gems 内部不会检查权限。但因公众号类型不同,和微信服务器端通讯时,可能会被拒绝,详细权限控制可参考[官方文档](http://mp.weixin.qq.com/wiki/7/2d301d4b757dedc333b9a9854b457b47.html)。
|
@@ -388,7 +401,7 @@ template:
|
|
388
401
|
topcolor: "#FF0000"
|
389
402
|
data:
|
390
403
|
first:
|
391
|
-
value: "
|
404
|
+
value: "您好,您已报名成功"
|
392
405
|
color: "#0A0A0A"
|
393
406
|
keynote1:
|
394
407
|
value: "XX活动"
|
@@ -575,7 +588,7 @@ end
|
|
575
588
|
class WechatsController < ActionController::Base
|
576
589
|
# 当无任何responder处理用户信息时,转发至客服处理。
|
577
590
|
on :fallback do |message|
|
578
|
-
|
591
|
+
message.reply.transfer_customer_service
|
579
592
|
end
|
580
593
|
end
|
581
594
|
```
|
data/README.md
CHANGED
@@ -24,6 +24,8 @@ Wechat provide OAuth2.0 as authentication service and possible to intergrated wi
|
|
24
24
|
|
25
25
|
There is official [weui](https://github.com/weui/weui), which corresponding Rails gems called [weui-rails](https://github.com/Eric-Guo/weui-rails) available, if you prefer following the same UI design as wechat.
|
26
26
|
|
27
|
+
There is a more complete [wechat-starter](https://github.com/goofansu/wechat-starter) demo available, even include the payment SDK feature.
|
28
|
+
|
27
29
|
## Installation
|
28
30
|
|
29
31
|
Using `gem install`
|
@@ -113,6 +115,7 @@ production:
|
|
113
115
|
|
114
116
|
development:
|
115
117
|
<<: *default
|
118
|
+
trusted_domain_fullname: "http://your_dev.proxy.qqbrowser.cc"
|
116
119
|
|
117
120
|
test:
|
118
121
|
<<: *default
|
@@ -140,7 +143,7 @@ default: &default
|
|
140
143
|
token: ""
|
141
144
|
encoding_aes_key: ""
|
142
145
|
jsapi_ticket: "C:/Users/[user_name]/wechat_jsapi_ticket"
|
143
|
-
|
146
|
+
|
144
147
|
production:
|
145
148
|
corpid: <%= ENV['WECHAT_CORPID'] %>
|
146
149
|
corpsecret: <%= ENV['WECHAT_CORPSECRET'] %>
|
@@ -154,6 +157,7 @@ production:
|
|
154
157
|
|
155
158
|
development:
|
156
159
|
<<: *default
|
160
|
+
trusted_domain_fullname: "http://your_dev.proxy.qqbrowser.cc"
|
157
161
|
|
158
162
|
test:
|
159
163
|
<<: *default
|
@@ -185,12 +189,22 @@ end
|
|
185
189
|
|
186
190
|
#### JS-SDK helper
|
187
191
|
|
188
|
-
JS-SDK enable you control
|
192
|
+
JS-SDK enable you control Wechat App behavior in html, by inject a config signature, helper `wechat_config_js` do that in more simple way:
|
189
193
|
|
190
|
-
```
|
191
|
-
|
194
|
+
```erb
|
195
|
+
<body>
|
196
|
+
<%= wechat_config_js debug: false, api: %w(hideMenuItems closeWindow) -%>
|
197
|
+
<script type="application/javascript">
|
198
|
+
wx.ready(function() {
|
199
|
+
wx.hideOptionMenu();
|
200
|
+
});
|
201
|
+
</script>
|
202
|
+
<a href="javascript:wx.closeWindow();">Close</a>
|
203
|
+
</body>
|
192
204
|
```
|
193
205
|
|
206
|
+
Configure the `trusted_domain_fullname` if you are in development mode and app running behind a reverse proxy server, otherwise wechat gem can not get the correct url to be signature later.
|
207
|
+
|
194
208
|
## The API privilege
|
195
209
|
|
196
210
|
wechat gems won't handle any privilege exception. (except token time out, but it's not important to you as it's auto retry/recovery in gems internally), but Tencent will control a lot of privilege based on your public account type and certification, more info, please reference [official document](http://mp.weixin.qq.com/wiki/7/2d301d4b757dedc333b9a9854b457b47.html).
|
@@ -10,16 +10,13 @@ module ActionController
|
|
10
10
|
self.skip_verify_ssl = opts[:skip_verify_ssl]
|
11
11
|
self.token = opts[:token] || Wechat.config.token
|
12
12
|
self.encoding_aes_key = opts[:encoding_aes_key] || Wechat.config.encoding_aes_key
|
13
|
+
self.trusted_domain_fullname = opts[:trusted_domain_fullname] || Wechat.config.trusted_domain_fullname
|
13
14
|
|
14
|
-
if opts.empty?
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
else
|
20
|
-
self.wechat = Wechat::Api.new(opts[:appid], opts[:secret], opts[:access_token], timeout, skip_verify_ssl, opts[:jsapi_ticket])
|
21
|
-
end
|
22
|
-
end
|
15
|
+
return self.wechat = Wechat.api if opts.empty?
|
16
|
+
return self.wechat = Wechat::CorpApi.new(corpid, opts[:corpsecret], opts[:access_token], \
|
17
|
+
agentid, timeout, skip_verify_ssl, opts[:jsapi_ticket]) if corpid.present?
|
18
|
+
self.wechat = Wechat::Api.new(opts[:appid], opts[:secret], opts[:access_token], \
|
19
|
+
timeout, skip_verify_ssl, opts[:jsapi_ticket])
|
23
20
|
end
|
24
21
|
end
|
25
22
|
|
data/lib/wechat.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'wechat/api_loader'
|
2
2
|
require 'wechat/api'
|
3
3
|
require 'wechat/corp_api'
|
4
|
+
require 'wechat/helpers'
|
4
5
|
require 'action_controller/wechat_responder'
|
5
6
|
|
6
7
|
module Wechat
|
@@ -25,3 +26,5 @@ module Wechat
|
|
25
26
|
@wechat_api ||= ApiLoader.with({})
|
26
27
|
end
|
27
28
|
end
|
29
|
+
|
30
|
+
ActionView::Base.send :include, Wechat::Helpers if defined? ActionView::Base
|
data/lib/wechat/api_loader.rb
CHANGED
@@ -75,7 +75,8 @@ HELP
|
|
75
75
|
timeout: ENV['WECHAT_TIMEOUT'],
|
76
76
|
skip_verify_ssl: ENV['WECHAT_SKIP_VERIFY_SSL'],
|
77
77
|
encoding_aes_key: ENV['WECHAT_ENCODING_AES_KEY'],
|
78
|
-
jsapi_ticket: ENV['WECHAT_JSAPI_TICKET']
|
78
|
+
jsapi_ticket: ENV['WECHAT_JSAPI_TICKET'],
|
79
|
+
trusted_domain_fullname: ENV['WECHAT_TRUSTED_DOMAIN_FULLNAME'] }
|
79
80
|
end
|
80
81
|
|
81
82
|
def self.class_exists?(class_name)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Wechat
|
2
|
+
module Helpers
|
3
|
+
def wechat_config_js(config_options = {})
|
4
|
+
page_url = if Wechat.config.trusted_domain_fullname
|
5
|
+
"#{Wechat.config.trusted_domain_fullname}#{controller.request.original_fullpath}"
|
6
|
+
else
|
7
|
+
controller.request.original_url
|
8
|
+
end
|
9
|
+
js_hash = Wechat.api.jsapi_ticket.signature(page_url)
|
10
|
+
config_js = <<-WECHAT_CONFIG_JS
|
11
|
+
wx.config({
|
12
|
+
debug: #{config_options[:debug]},
|
13
|
+
appId: "#{Wechat.config.corpid || Wechat.config.appid}",
|
14
|
+
timestamp: "#{js_hash[:timestamp]}",
|
15
|
+
nonceStr: "#{js_hash[:noncestr]}",
|
16
|
+
signature: "#{js_hash[:signature]}",
|
17
|
+
jsApiList: ['#{config_options[:api].join("','")}']
|
18
|
+
});
|
19
|
+
WECHAT_CONFIG_JS
|
20
|
+
javascript_tag config_js, type: 'application/javascript'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/wechat/responder.rb
CHANGED
@@ -19,10 +19,10 @@ module Wechat
|
|
19
19
|
end
|
20
20
|
|
21
21
|
module ClassMethods
|
22
|
-
attr_accessor :wechat, :token, :corpid, :agentid, :encrypt_mode, :timeout, :skip_verify_ssl, :encoding_aes_key
|
22
|
+
attr_accessor :wechat, :token, :corpid, :agentid, :encrypt_mode, :timeout, :skip_verify_ssl, :encoding_aes_key, :trusted_domain_fullname
|
23
23
|
|
24
24
|
def on(message_type, with: nil, respond: nil, &block)
|
25
|
-
fail 'Unknow message type' unless [:text, :image, :voice, :video, :link, :event, :click, :view, :scan, :batch_job, :location, :fallback].include?(message_type)
|
25
|
+
fail 'Unknow message type' unless [:text, :image, :voice, :video, :shortvideo, :link, :event, :click, :view, :scan, :batch_job, :location, :fallback].include?(message_type)
|
26
26
|
config = respond.nil? ? {} : { respond: respond }
|
27
27
|
config.merge!(proc: block) if block_given?
|
28
28
|
|
@@ -162,9 +162,9 @@ module Wechat
|
|
162
162
|
def show
|
163
163
|
if self.class.corpid.present?
|
164
164
|
echostr, _corp_id = unpack(decrypt(Base64.decode64(params[:echostr]), self.class.encoding_aes_key))
|
165
|
-
render
|
165
|
+
render plain: echostr
|
166
166
|
else
|
167
|
-
render
|
167
|
+
render plain: params[:echostr]
|
168
168
|
end
|
169
169
|
end
|
170
170
|
|
@@ -195,7 +195,7 @@ module Wechat
|
|
195
195
|
|
196
196
|
msg_encrypt = nil unless self.class.corpid.present?
|
197
197
|
|
198
|
-
render
|
198
|
+
render plain: 'Forbidden', status: 403 if signature != Signature.hexdigest(self.class.token,
|
199
199
|
params[:timestamp],
|
200
200
|
params[:nonce],
|
201
201
|
msg_encrypt)
|
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.7.
|
4
|
+
version: 0.7.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Skinnyworm
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-02-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -150,6 +150,7 @@ files:
|
|
150
150
|
- lib/wechat/cipher.rb
|
151
151
|
- lib/wechat/client.rb
|
152
152
|
- lib/wechat/corp_api.rb
|
153
|
+
- lib/wechat/helpers.rb
|
153
154
|
- lib/wechat/message.rb
|
154
155
|
- lib/wechat/responder.rb
|
155
156
|
- lib/wechat/signature.rb
|