wechat 0.7.13 → 0.7.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README-CN.md +19 -2
- data/README.md +20 -3
- data/bin/wechat +5 -0
- data/lib/action_controller/wechat_responder.rb +2 -1
- data/lib/wechat/api.rb +4 -0
- data/lib/wechat/corp_api.rb +2 -2
- data/lib/wechat/message.rb +2 -2
- data/lib/wechat/ticket/jsapi_base.rb +4 -1
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ee9e70f17f62c608e75487348f1931638db3acc
|
4
|
+
data.tar.gz: 2324834ce8690aeab08707612d230e3831fa5267
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1edab9326f1f48c5eefa7993f7fcac909eda38d8c9141446bf2c49a201bfe4caae1458dbe970f7ce5686316f1927c700a87684d8aa3af6ffefc132d876341828
|
7
|
+
data.tar.gz: 6a383130d1f5015aa8e81e6230a27e5a66f7d85ab69afc6e26290d569b048390c34986c95ef8038c2ed9a882d051fad2051731e823e3c0a532a9ed4c38e2af8d
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v0.7.14 (released at 5/29/2016)
|
4
|
+
|
5
|
+
* Fix when access_token failed lead ticket can not refresh problem.
|
6
|
+
* Default duration should be 1 hours instead of 0 seconds for wechat_oauth2.
|
7
|
+
* New short_url allowing convert from long URL to short.
|
8
|
+
|
3
9
|
## v0.7.13 (released at 5/14/2016)
|
4
10
|
|
5
11
|
* Wechat.config.oauth2_cookie_duration need convert to secondes, found by @gabrieltong #111
|
data/README-CN.md
CHANGED
@@ -242,6 +242,8 @@ end
|
|
242
242
|
|
243
243
|
`wechat_oauth2`封装了OAuth2.0验证接口和cookie处理逻辑,用户仅需提供业务代码块即可。userid指的是微信企业成员UserID,openid是关注该公众号的用户openid。
|
244
244
|
|
245
|
+
注意: 如果使用 `wechat_responder`, 请不要在 Controller 里定义 `show` 和 `create` 方法, 否则会报错。
|
246
|
+
|
245
247
|
## 关于接口权限
|
246
248
|
|
247
249
|
wechat gems 内部不会检查权限。但因公众号类型不同,和微信服务器端通讯时,可能会被拒绝,详细权限控制可参考[官方文档](http://mp.weixin.qq.com/wiki/7/2d301d4b757dedc333b9a9854b457b47.html)。
|
@@ -284,6 +286,7 @@ Wechat commands:
|
|
284
286
|
wechat qrcode_create_limit_scene [SCENE_ID_OR_STR] # 请求永久二维码
|
285
287
|
wechat qrcode_create_scene [SCENE_ID, EXPIRE_SECONDS] # 请求临时二维码
|
286
288
|
wechat qrcode_download [TICKET, QR_CODE_PIC_PATH] # 通过ticket下载二维码
|
289
|
+
wechat short_url [LONG_URL] # 长链接转短链接
|
287
290
|
wechat template_message [OPENID, TEMPLATE_YAML_PATH] # 模板消息接口
|
288
291
|
wechat user [OPEN_ID] # 获取用户基本信息
|
289
292
|
wechat user_batchget [OPEN_ID_LIST] # 批量获取用户基本信息
|
@@ -327,7 +330,7 @@ Wechat commands:
|
|
327
330
|
wechat menu # 当前菜单
|
328
331
|
wechat menu_create [MENU_YAML_PATH] # 创建菜单
|
329
332
|
wechat menu_delete # 删除菜单
|
330
|
-
wechat message_send [
|
333
|
+
wechat message_send [USERID, TEXT_MESSAGE] # 发送文字消息
|
331
334
|
wechat qrcode_download [TICKET, QR_CODE_PIC_PATH] # 通过ticket下载二维码
|
332
335
|
wechat tag [TAG_ID] # 获取标签成员
|
333
336
|
wechat tag_add_department [TAG_ID, PARTY_IDS] # 增加标签部门
|
@@ -479,6 +482,20 @@ template:
|
|
479
482
|
$ wechat template_message oCfEht9oM*********** template.yml
|
480
483
|
```
|
481
484
|
|
485
|
+
在代码中可以这样使用:
|
486
|
+
|
487
|
+
```ruby
|
488
|
+
template = YAML.load(File.read(template_yaml_path)).symbolize_keys
|
489
|
+
Wechat.api.template_message_send Wechat::Message.to(openid).template(template)
|
490
|
+
```
|
491
|
+
|
492
|
+
若在Controller中使用wechat_api或者wechat_responder,可以使用wechat:
|
493
|
+
|
494
|
+
```ruby
|
495
|
+
template = YAML.load(File.read(template_yaml_path)).symbolize_keys
|
496
|
+
wechat.template_message_send Wechat::Message.to(openid).template(template)
|
497
|
+
```
|
498
|
+
|
482
499
|
## wechat_api - Rails Controller Wechat API
|
483
500
|
|
484
501
|
虽然用户可以随时通过`Wechat.api`在任意代码中访问wechat的API功能,但是更推荐的做法是仅在controller中,通过引入`wechat_api`,使用`wechat`调用API功能,不仅因为这样是支持多个微信公众号的必然要求,而且也避免了在模型层内过多引入微信相关代码。
|
@@ -589,7 +606,7 @@ class WechatsController < ActionController::Base
|
|
589
606
|
|
590
607
|
# 处理上报地理位置事件
|
591
608
|
on :location do |request|
|
592
|
-
request.reply.text("Latitude: #{
|
609
|
+
request.reply.text("Latitude: #{request[:Latitude]} Longitude: #{request[:Longitude]} Precision: #{request[:Precision]}")
|
593
610
|
end
|
594
611
|
|
595
612
|
# 当用户取消关注订阅
|
data/README.md
CHANGED
@@ -255,6 +255,8 @@ end
|
|
255
255
|
|
256
256
|
`wechat_oauth2` already implement the necessory OAuth2.0 and cookie logic. userid defined as the enterprise member UserID. openid defined as the user who following the public account, also notice openid will be different for the same user for different following public account.
|
257
257
|
|
258
|
+
Notice: If you use `wechat_responder` in your controller, you cannot use `create` and `show` action in your controller, otherwise will throw errors.
|
259
|
+
|
258
260
|
|
259
261
|
## The API privilege
|
260
262
|
|
@@ -300,6 +302,7 @@ Wechat commands:
|
|
300
302
|
wechat qrcode_create_limit_scene [SCENE_ID_OR_STR] # 请求永久二维码
|
301
303
|
wechat qrcode_create_scene [SCENE_ID, EXPIRE_SECONDS] # 请求临时二维码
|
302
304
|
wechat qrcode_download [TICKET, QR_CODE_PIC_PATH] # 通过ticket下载二维码
|
305
|
+
wechat short_url [LONG_URL] # 长链接转短链接
|
303
306
|
wechat template_message [OPENID, TEMPLATE_YAML_PATH] # 模板消息接口
|
304
307
|
wechat user [OPEN_ID] # 获取用户基本信息
|
305
308
|
wechat user_batchget [OPEN_ID_LIST] # 批量获取用户基本信息
|
@@ -343,7 +346,7 @@ Wechat commands:
|
|
343
346
|
wechat menu # 当前菜单
|
344
347
|
wechat menu_create [MENU_YAML_PATH] # 创建菜单
|
345
348
|
wechat menu_delete # 删除菜单
|
346
|
-
wechat message_send [
|
349
|
+
wechat message_send [USERID, TEXT_MESSAGE] # 发送文字消息
|
347
350
|
wechat qrcode_download [TICKET, QR_CODE_PIC_PATH] # 通过ticket下载二维码
|
348
351
|
wechat tag [TAG_ID] # 获取标签成员
|
349
352
|
wechat tag_add_department [TAG_ID, PARTY_IDS] # 增加标签部门
|
@@ -442,7 +445,7 @@ Caution: make sure you having management privilege for those application, othe
|
|
442
445
|
##### Sent custom news
|
443
446
|
|
444
447
|
|
445
|
-
Sending custom_news should also defined as a yaml file, like `articles.
|
448
|
+
Sending custom_news should also defined as a yaml file, like `articles.yml`
|
446
449
|
|
447
450
|
```
|
448
451
|
articles:
|
@@ -494,6 +497,20 @@ After that, can running command:
|
|
494
497
|
$ wechat template_message oCfEht9oM*********** template.yml
|
495
498
|
```
|
496
499
|
|
500
|
+
In code:
|
501
|
+
|
502
|
+
```ruby
|
503
|
+
template = YAML.load(File.read(template_yaml_path)).symbolize_keys
|
504
|
+
Wechat.api.template_message_send Wechat::Message.to(openid).template(template)
|
505
|
+
```
|
506
|
+
|
507
|
+
If using wechat_api or wechat_responder in Controller, can alse use wechat as shortcut(Support multi account):
|
508
|
+
|
509
|
+
```ruby
|
510
|
+
template = YAML.load(File.read(template_yaml_path)).symbolize_keys
|
511
|
+
wechat.template_message_send Wechat::Message.to(openid).template(template)
|
512
|
+
```
|
513
|
+
|
497
514
|
## wechat_api - Rails Controller Wechat API
|
498
515
|
|
499
516
|
Although user can always access all wechat feature via Wechat.api, but it's much more recommand to using `wechat` directly in controller. It's not only mandatory require if you plan to support multi-account, also help to seperate the wechat specific logic from the model layer.
|
@@ -604,7 +621,7 @@ class WechatsController < ActionController::Base
|
|
604
621
|
|
605
622
|
# When user sent location
|
606
623
|
on :location do |request|
|
607
|
-
request.reply.text("Latitude: #{
|
624
|
+
request.reply.text("Latitude: #{request[:Latitude]} Longitude: #{request[:Longitude]} Precision: #{request[:Precision]}")
|
608
625
|
end
|
609
626
|
|
610
627
|
on :event, with: 'unsubscribe' do |request|
|
data/bin/wechat
CHANGED
@@ -282,6 +282,11 @@ class App < Thor
|
|
282
282
|
puts wechat_api.qrcode_create_limit_scene(scene_id_or_str)
|
283
283
|
end
|
284
284
|
|
285
|
+
desc 'short_url [LONG_URL]', '长链接转短链接'
|
286
|
+
def short_url(long_url)
|
287
|
+
puts wechat_api.short_url(long_url)
|
288
|
+
end
|
289
|
+
|
285
290
|
desc 'customservice_getonlinekflist', '获取在线客服接待信息'
|
286
291
|
def customservice_getonlinekflist
|
287
292
|
puts wechat_api.customservice_getonlinekflist
|
@@ -22,7 +22,8 @@ module ActionController
|
|
22
22
|
self.skip_verify_ssl = opts[:skip_verify_ssl]
|
23
23
|
self.encoding_aes_key = opts[:encoding_aes_key] || Wechat.config.encoding_aes_key
|
24
24
|
self.trusted_domain_fullname = opts[:trusted_domain_fullname] || Wechat.config.trusted_domain_fullname
|
25
|
-
|
25
|
+
Wechat.config.oauth2_cookie_duration ||= 1.hour
|
26
|
+
self.oauth2_cookie_duration = opts[:oauth2_cookie_duration] || Wechat.config.oauth2_cookie_duration.to_i.seconds
|
26
27
|
|
27
28
|
return self.wechat = Wechat.api if opts.empty?
|
28
29
|
if corpid.present?
|
data/lib/wechat/api.rb
CHANGED
data/lib/wechat/corp_api.rb
CHANGED
@@ -161,8 +161,8 @@ module Wechat
|
|
161
161
|
get 'material/del', params: { media_id: media_id, agentid: agentid }
|
162
162
|
end
|
163
163
|
|
164
|
-
def message_send(
|
165
|
-
post 'message/send', Message.to(
|
164
|
+
def message_send(userid, message)
|
165
|
+
post 'message/send', Message.to(userid).text(message).agent_id(agentid).to_json, content_type: :json
|
166
166
|
end
|
167
167
|
end
|
168
168
|
end
|
data/lib/wechat/message.rb
CHANGED
@@ -13,11 +13,14 @@ module Wechat
|
|
13
13
|
@random_generator = Random.new
|
14
14
|
end
|
15
15
|
|
16
|
-
def ticket
|
16
|
+
def ticket(tries = 2)
|
17
17
|
# Possible two worker running, one worker refresh ticket, other unaware, so must read every time
|
18
18
|
read_ticket_from_store
|
19
19
|
refresh if remain_life_seconds < @random_generator.rand(30..3 * 60)
|
20
20
|
access_ticket
|
21
|
+
rescue AccessTokenExpiredError
|
22
|
+
access_token.refresh
|
23
|
+
retry unless (tries -= 1).zero?
|
21
24
|
end
|
22
25
|
|
23
26
|
# Obtain the wechat jssdk config signature parameter and return below hash
|
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.14
|
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-05-
|
12
|
+
date: 2016-05-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -63,22 +63,22 @@ dependencies:
|
|
63
63
|
name: http
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '1.0'
|
69
66
|
- - ">="
|
70
67
|
- !ruby/object:Gem::Version
|
71
|
-
version: 1.0.
|
68
|
+
version: 1.0.4
|
69
|
+
- - "<"
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '3'
|
72
72
|
type: :runtime
|
73
73
|
prerelease: false
|
74
74
|
version_requirements: !ruby/object:Gem::Requirement
|
75
75
|
requirements:
|
76
|
-
- - "~>"
|
77
|
-
- !ruby/object:Gem::Version
|
78
|
-
version: '1.0'
|
79
76
|
- - ">="
|
80
77
|
- !ruby/object:Gem::Version
|
81
|
-
version: 1.0.
|
78
|
+
version: 1.0.4
|
79
|
+
- - "<"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '3'
|
82
82
|
- !ruby/object:Gem::Dependency
|
83
83
|
name: rspec-rails
|
84
84
|
requirement: !ruby/object:Gem::Requirement
|