wechat 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/README.md +38 -15
- data/bin/wechat +18 -0
- data/lib/generators/wechat/templates/app/controllers/wechats_controller.rb +28 -12
- data/lib/wechat/access_token.rb +1 -1
- data/lib/wechat/corp_api.rb +12 -0
- data/lib/wechat/jsapi_ticket.rb +2 -1
- data/lib/wechat/responder.rb +50 -17
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c3c86998923262ea14fc33f0118b074d736b4d6
|
4
|
+
data.tar.gz: d0eae32ca05d72b784f1950bfd2da4f4ba6eac52
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9b65631598a034c1c9dd037f95e96f84d8b52e7559f2f85df610b53ba4f184530191e334a3e25409f523c4b108d9054dcdb90ca91e9675db7a756a30ba67703
|
7
|
+
data.tar.gz: a7f897913b4fb244a4de5d9ee8fcf40ae369ca3a302e4a5ba0e483bc99ab7ef932d53098c92f2c892e5c99cd20390439884b7dab7a0d838eec6832a398290360
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,18 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v0.6.0 (released at 10/08/2015)
|
4
|
+
|
5
|
+
### Scan and Batch job are BREAK CHANGE!
|
6
|
+
|
7
|
+
* Scan 2D barcode using new syntax `on :scan, with: 'BINDING_QR_CODE' ` instead of `on :event, with: 'BINDING_QR_CODE' ` in previous version #55
|
8
|
+
Which will fix can not using `on :event, with: "scan" ` problem
|
9
|
+
* Batch job using new syntax `on :batch_job, with: 'replace_user' `
|
10
|
+
instead of previous `on :event, with: 'replace_user' `.
|
11
|
+
* Click menu support new syntax `on :click, with: 'BOOK_LUNCH' `, but `on :event, with: 'BOOK_LUNCH' ` still supported. perfer `on :click` because it running faster and more nature expression.
|
12
|
+
* Wechat::Responder using Hash for new :client and :batch_job event, avoid time consuming Array match responder
|
13
|
+
* Fix refresh token not working problem under ruby 2.0.0 #54
|
14
|
+
* New department_update, user_batchdelete, convert_to_openid API
|
15
|
+
|
3
16
|
## v0.5.0 (released at 9/25/2015)
|
4
17
|
|
5
18
|
* Only relay on activesupport on run time, so will greatly improve wechat cli startup time
|
data/README.md
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
WeChat
|
2
2
|
======
|
3
3
|
|
4
|
-
[![Build Status](https://travis-ci.org/Eric-Guo/wechat.svg)](https://travis-ci.org/Eric-Guo/wechat) [![Code Climate](https://codeclimate.com/github/Eric-Guo/wechat.png)](https://codeclimate.com/github/Eric-Guo/wechat) [![Code Coverage](https://codeclimate.com/github/Eric-Guo/wechat/coverage.png)](https://codeclimate.com/github/Eric-Guo/wechat)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/wechat.svg)](https://badge.fury.io/for/rb/wechat) [![Build Status](https://travis-ci.org/Eric-Guo/wechat.svg)](https://travis-ci.org/Eric-Guo/wechat) [![Code Climate](https://codeclimate.com/github/Eric-Guo/wechat.png)](https://codeclimate.com/github/Eric-Guo/wechat) [![Code Coverage](https://codeclimate.com/github/Eric-Guo/wechat/coverage.png)](https://codeclimate.com/github/Eric-Guo/wechat)
|
5
|
+
|
6
|
+
[![Issue Stats](http://issuestats.com/github/Eric-Guo/wechat/badge/issue)](http://issuestats.com/github/Eric-Guo/wechat) [![PR Stats](http://issuestats.com/github/Eric-Guo/wechat/badge/pr)](http://issuestats.com/github/Eric-Guo/wechat)
|
5
7
|
|
6
8
|
|
7
9
|
WeChat gem 可以帮助开发者方便地在Rails环境中集成微信[公众平台](https://mp.weixin.qq.com/)和[企业平台](https://qy.weixin.qq.com)提供的服务,包括:
|
@@ -160,6 +162,7 @@ Wechat commands:
|
|
160
162
|
wechat batch_replaceuser [BATCH_USER_CSV_MEDIA_ID] # 全量覆盖成员
|
161
163
|
wechat batch_syncuser [SYNC_USER_CSV_MEDIA_ID] # 增量更新成员
|
162
164
|
wechat callbackip # 获取微信服务器IP地址
|
165
|
+
wechat convert_to_openid [USER_ID] # userid转换成openid
|
163
166
|
wechat custom_image [OPENID, IMAGE_PATH] # 发送图片客服消息
|
164
167
|
wechat custom_music [OPENID, THUMBNAIL_PATH, MUSIC_URL] # 发送音乐客服消息
|
165
168
|
wechat custom_news [OPENID, NEWS_YAML_PATH] # 发送图文客服消息
|
@@ -169,6 +172,7 @@ Wechat commands:
|
|
169
172
|
wechat department [DEPARTMENT_ID] # 获取部门列表
|
170
173
|
wechat department_create [NAME, PARENT_ID] # 创建部门
|
171
174
|
wechat department_delete [DEPARTMENT_ID] # 删除部门
|
175
|
+
wechat department_update [DEPARTMENT_ID, NAME] # 更新部门
|
172
176
|
wechat group_create [GROUP_NAME] # 创建分组
|
173
177
|
wechat group_delete [GROUP_ID] # 删除分组
|
174
178
|
wechat group_update [GROUP_ID, NEW_GROUP_NAME] # 修改分组名
|
@@ -199,6 +203,7 @@ Wechat commands:
|
|
199
203
|
wechat tags # 获取标签列表
|
200
204
|
wechat template_message [OPENID, TEMPLATE_YAML_PATH] # 模板消息接口
|
201
205
|
wechat user [OPEN_ID] # 获取用户基本信息
|
206
|
+
wechat user_batchdelete [USER_ID_LIST] # 批量删除成员
|
202
207
|
wechat user_change_group [OPEN_ID, TO_GROUP_ID] # 移动用户分组
|
203
208
|
wechat user_delete [USER_ID] # 删除成员
|
204
209
|
wechat user_group [OPEN_ID] # 查询用户所在分组
|
@@ -377,18 +382,38 @@ class WechatsController < ApplicationController
|
|
377
382
|
end
|
378
383
|
end
|
379
384
|
|
380
|
-
#
|
381
|
-
on :event, with: '
|
385
|
+
# 当用户加关注
|
386
|
+
on :event, with: 'subscribe' do |request|
|
387
|
+
request.reply.text "User #{request[:FromUserName]} subscribe now"
|
388
|
+
end
|
389
|
+
|
390
|
+
# 公众号收到未关注用户扫描qrscene_xxxxxx二维码时。注意此次扫描事件将不再引发上条的用户加关注事件
|
391
|
+
on :scan, with: 'qrscene_xxxxxx' do |request, ticket|
|
392
|
+
request.reply.text "Unsubscribe user #{request[:FromUserName]} Ticket #{ticket}"
|
393
|
+
end
|
394
|
+
|
395
|
+
# 公众号收到已关注用户扫描创建二维码的scene_id事件时
|
396
|
+
on :scan, with: 'scene_id' do |request, ticket|
|
397
|
+
request.reply.text "Subscribe user #{request[:FromUserName]} Ticket #{ticket}"
|
398
|
+
end
|
399
|
+
|
400
|
+
# 企业号收到EventKey 为二维码扫描结果事件时
|
401
|
+
on :scan, with: 'BINDING_QR_CODE' do |request, scan_result, scan_type|
|
382
402
|
request.reply.text "User #{request[:FromUserName]} ScanResult #{scan_result} ScanType #{scan_type}"
|
383
403
|
end
|
384
404
|
|
385
|
-
#
|
386
|
-
on :
|
405
|
+
# 企业号收到EventKey 为CODE 39码扫描结果事件时
|
406
|
+
on :scan, with: 'BINDING_BARCODE' do |message, scan_result|
|
387
407
|
if scan_result.start_with? 'CODE_39,'
|
388
408
|
message.reply.text "User: #{message[:FromUserName]} scan barcode, result is #{scan_result.split(',')[1]}"
|
389
409
|
end
|
390
410
|
end
|
391
411
|
|
412
|
+
# 当用户点击菜单时
|
413
|
+
on :click, with: 'BOOK_LUNCH' do |request, key|
|
414
|
+
request.reply.text "User: #{request[:FromUserName]} click #{key}"
|
415
|
+
end
|
416
|
+
|
392
417
|
# 处理图片信息
|
393
418
|
on :image do |request|
|
394
419
|
request.reply.image(request[:MediaId]) #直接将图片返回给用户
|
@@ -410,11 +435,6 @@ class WechatsController < ApplicationController
|
|
410
435
|
request.reply.text("#{request[:Location_X]}, #{request[:Location_Y]}") #回复地理位置
|
411
436
|
end
|
412
437
|
|
413
|
-
# 当用户加关注
|
414
|
-
on :event, with: 'subscribe' do |request|
|
415
|
-
request.reply.text "#{request[:FromUserName]} subscribe now"
|
416
|
-
end
|
417
|
-
|
418
438
|
# 当用户取消关注订阅
|
419
439
|
on :event, with: 'unsubscribe' do |request|
|
420
440
|
request.reply.text "#{request[:FromUserName]} can not receive this message"
|
@@ -426,22 +446,22 @@ class WechatsController < ApplicationController
|
|
426
446
|
end
|
427
447
|
|
428
448
|
# 当异步任务增量更新成员完成时推送
|
429
|
-
on :
|
449
|
+
on :batch_job, with: 'sync_user' do |request, batch_job|
|
430
450
|
request.reply.text "job #{batch_job[:JobId]} finished, return code #{batch_job[:ErrCode]}, return message #{batch_job[:ErrMsg]}"
|
431
451
|
end
|
432
452
|
|
433
453
|
# 当异步任务全量覆盖成员完成时推送
|
434
|
-
on :
|
454
|
+
on :batch_job, with: 'replace_user' do |request, batch_job|
|
435
455
|
request.reply.text "job #{batch_job[:JobId]} finished, return code #{batch_job[:ErrCode]}, return message #{batch_job[:ErrMsg]}"
|
436
456
|
end
|
437
457
|
|
438
458
|
# 当异步任务邀请成员关注完成时推送
|
439
|
-
on :
|
459
|
+
on :batch_job, with: 'invite_user' do |request, batch_job|
|
440
460
|
request.reply.text "job #{batch_job[:JobId]} finished, return code #{batch_job[:ErrCode]}, return message #{batch_job[:ErrMsg]}"
|
441
461
|
end
|
442
462
|
|
443
463
|
# 当异步任务全量覆盖部门完成时推送
|
444
|
-
on :
|
464
|
+
on :batch_job, with: 'replace_party' do |request, batch_job|
|
445
465
|
request.reply.text "job #{batch_job[:JobId]} finished, return code #{batch_job[:ErrCode]}, return message #{batch_job[:ErrMsg]}"
|
446
466
|
end
|
447
467
|
|
@@ -456,8 +476,8 @@ end
|
|
456
476
|
on <message_type> do |message|
|
457
477
|
message.reply.text "some text"
|
458
478
|
end
|
459
|
-
|
460
479
|
```
|
480
|
+
|
461
481
|
来响应用户信息。
|
462
482
|
|
463
483
|
目前支持的message_type有如下几种
|
@@ -469,6 +489,9 @@ end
|
|
469
489
|
- :location 响应地理位置消息
|
470
490
|
- :link 响应链接消息
|
471
491
|
- :event 响应事件消息, 可以用`:with`参数来匹配事件类型
|
492
|
+
- :click 虚拟响应事件消息, 微信仍然传入:event,但gem内部会单独处理
|
493
|
+
- :scan 虚拟响应事件消息
|
494
|
+
- :batch_job 虚拟响应事件消息
|
472
495
|
- :fallback 默认响应,当收到的消息无法被其他responder响应时,会使用这个responder.
|
473
496
|
|
474
497
|
### 多客服消息转发
|
data/bin/wechat
CHANGED
@@ -107,6 +107,14 @@ HELP
|
|
107
107
|
puts Helper.with(options).department_delete(departmentid)
|
108
108
|
end
|
109
109
|
|
110
|
+
desc 'department_update [DEPARTMENT_ID, NAME]', '更新部门'
|
111
|
+
method_option :parentid, aliases: '-p', desc: '父亲部门id。根部门id为1', default: nil
|
112
|
+
method_option :order, aliases: '-o', desc: '在父部门中的次序值。order值小的排序靠前。', default: nil
|
113
|
+
def department_update(departmentid, name)
|
114
|
+
api_opts = options.slice(:parentid, :order)
|
115
|
+
puts Helper.with(options).department_update(departmentid, name, api_opts[:parentid], api_opts[:order])
|
116
|
+
end
|
117
|
+
|
110
118
|
desc 'department [DEPARTMENT_ID]', '获取部门列表'
|
111
119
|
def department(departmentid = 0)
|
112
120
|
r = Helper.with(options).department(departmentid)
|
@@ -229,6 +237,11 @@ HELP
|
|
229
237
|
puts Helper.with(options).user(open_id)
|
230
238
|
end
|
231
239
|
|
240
|
+
desc 'convert_to_openid [USER_ID]', 'userid转换成openid'
|
241
|
+
def convert_to_openid(userid)
|
242
|
+
puts Helper.with(options).convert_to_openid(userid)
|
243
|
+
end
|
244
|
+
|
232
245
|
desc 'invite_user [USER_ID]', '邀请成员关注'
|
233
246
|
def invite_user(userid)
|
234
247
|
puts Helper.with(options).invite_user(userid)
|
@@ -239,6 +252,11 @@ HELP
|
|
239
252
|
puts Helper.with(options).user_delete(userid)
|
240
253
|
end
|
241
254
|
|
255
|
+
desc 'user_batchdelete [USER_ID_LIST]', '批量删除成员'
|
256
|
+
def user_batchdelete(useridlist)
|
257
|
+
puts Helper.with(options).user_batchdelete(useridlist.split(','))
|
258
|
+
end
|
259
|
+
|
242
260
|
desc 'batch_job_result [JOB_ID]', '获取异步任务结果'
|
243
261
|
def batch_job_result(job_id)
|
244
262
|
puts Helper.with(options).batch_job_result(job_id)
|
@@ -20,18 +20,38 @@ class WechatsController < ApplicationController
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
on :event, with: 'subscribe' do |request|
|
24
|
+
request.reply.text "#{request[:FromUserName]} subscribe now"
|
25
|
+
end
|
26
|
+
|
27
|
+
# When unsubscribe user scan qrcode qrscene_xxxxxx to subscribe in public account
|
28
|
+
# notice user will subscribe public account at same time, so wechat won't trigger subscribe event any more
|
29
|
+
on :scan, with: 'qrscene_xxxxxx' do |request, ticket|
|
30
|
+
request.reply.text "Unsubscribe user #{request[:FromUserName]} Ticket #{ticket}"
|
31
|
+
end
|
32
|
+
|
33
|
+
# When subscribe user scan scene_id in public account
|
34
|
+
on :scan, with: 'scene_id' do |request, ticket|
|
35
|
+
request.reply.text "Subscribe user #{request[:FromUserName]} Ticket #{ticket}"
|
36
|
+
end
|
37
|
+
|
38
|
+
# When enterprise user press menu BINDING_QR_CODE and success to scan bar code
|
39
|
+
on :scan, with: 'BINDING_QR_CODE' do |request, scan_result, scan_type|
|
25
40
|
request.reply.text "User #{request[:FromUserName]} ScanResult #{scan_result} ScanType #{scan_type}"
|
26
41
|
end
|
27
42
|
|
28
|
-
# Except QR code, wechat can also scan CODE_39 bar code
|
29
|
-
on :
|
43
|
+
# Except QR code, wechat can also scan CODE_39 bar code in enterprise account
|
44
|
+
on :scan, with: 'BINDING_BARCODE' do |message, scan_result|
|
30
45
|
if scan_result.start_with? 'CODE_39,'
|
31
46
|
message.reply.text "User: #{message[:FromUserName]} scan barcode, result is #{scan_result.split(',')[1]}"
|
32
47
|
end
|
33
48
|
end
|
34
49
|
|
50
|
+
# When user click the menu button
|
51
|
+
on :click, with: 'BOOK_LUNCH' do |request, key|
|
52
|
+
request.reply.text "User: #{request[:FromUserName]} click #{key}"
|
53
|
+
end
|
54
|
+
|
35
55
|
# When user sent the imsage
|
36
56
|
on :image do |request|
|
37
57
|
request.reply.image(request[:MediaId]) # Echo the sent image to user
|
@@ -53,10 +73,6 @@ class WechatsController < ApplicationController
|
|
53
73
|
request.reply.text("#{request[:Location_X]}, #{request[:Location_Y]}") # replay the GPS location
|
54
74
|
end
|
55
75
|
|
56
|
-
on :event, with: 'subscribe' do |request|
|
57
|
-
request.reply.text "#{request[:FromUserName]} subscribe now"
|
58
|
-
end
|
59
|
-
|
60
76
|
on :event, with: 'unsubscribe' do |request|
|
61
77
|
request.reply.text "#{request[:FromUserName]} can not receive this message"
|
62
78
|
end
|
@@ -67,22 +83,22 @@ class WechatsController < ApplicationController
|
|
67
83
|
end
|
68
84
|
|
69
85
|
# When batch job create/update user (incremental) finished.
|
70
|
-
on :
|
86
|
+
on :batch_job, with: 'sync_user' do |request, batch_job|
|
71
87
|
request.reply.text "sync_user job #{batch_job[:JobId]} finished, return code #{batch_job[:ErrCode]}, return message #{batch_job[:ErrMsg]}"
|
72
88
|
end
|
73
89
|
|
74
90
|
# When batch job replace user (full sync) finished.
|
75
|
-
on :
|
91
|
+
on :batch_job, with: 'replace_user' do |request, batch_job|
|
76
92
|
request.reply.text "replace_user job #{batch_job[:JobId]} finished, return code #{batch_job[:ErrCode]}, return message #{batch_job[:ErrMsg]}"
|
77
93
|
end
|
78
94
|
|
79
95
|
# When batch job invent user finished.
|
80
|
-
on :
|
96
|
+
on :batch_job, with: 'invite_user' do |request, batch_job|
|
81
97
|
request.reply.text "invite_user job #{batch_job[:JobId]} finished, return code #{batch_job[:ErrCode]}, return message #{batch_job[:ErrMsg]}"
|
82
98
|
end
|
83
99
|
|
84
100
|
# When batch job replace department (full sync) finished.
|
85
|
-
on :
|
101
|
+
on :batch_job, with: 'replace_party' do |request, batch_job|
|
86
102
|
request.reply.text "replace_party job #{batch_job[:JobId]} finished, return code #{batch_job[:ErrCode]}, return message #{batch_job[:ErrMsg]}"
|
87
103
|
end
|
88
104
|
|
data/lib/wechat/access_token.rb
CHANGED
@@ -23,7 +23,7 @@ module Wechat
|
|
23
23
|
|
24
24
|
def refresh
|
25
25
|
data = client.get('token', params: { grant_type: 'client_credential', appid: appid, secret: secret })
|
26
|
-
data.merge!(created_at
|
26
|
+
data.merge!('created_at'.freeze => Time.now.to_i)
|
27
27
|
File.write(token_file, data.to_json) if valid_token(data)
|
28
28
|
@token_data = data
|
29
29
|
end
|
data/lib/wechat/corp_api.rb
CHANGED
@@ -35,6 +35,10 @@ module Wechat
|
|
35
35
|
get 'user/get', params: { userid: userid }
|
36
36
|
end
|
37
37
|
|
38
|
+
def convert_to_openid(userid)
|
39
|
+
post 'user/convert_to_openid', JSON.generate(userid: userid, agentid: agentid)
|
40
|
+
end
|
41
|
+
|
38
42
|
def invite_user(userid)
|
39
43
|
post 'invite/send', JSON.generate(userid: userid)
|
40
44
|
end
|
@@ -47,6 +51,10 @@ module Wechat
|
|
47
51
|
get 'user/delete', params: { userid: userid }
|
48
52
|
end
|
49
53
|
|
54
|
+
def user_batchdelete(useridlist)
|
55
|
+
post 'user/batchdelete', JSON.generate(useridlist: useridlist)
|
56
|
+
end
|
57
|
+
|
50
58
|
def batch_job_result(jobid)
|
51
59
|
get 'batch/getresult', params: { jobid: jobid }
|
52
60
|
end
|
@@ -71,6 +79,10 @@ module Wechat
|
|
71
79
|
get 'department/delete', params: { id: departmentid }
|
72
80
|
end
|
73
81
|
|
82
|
+
def department_update(departmentid, name = nil, parentid = nil, order = nil)
|
83
|
+
post 'department/update', JSON.generate({ id: departmentid, name: name, parentid: parentid, order: order }.reject { |_k, v| v.nil? })
|
84
|
+
end
|
85
|
+
|
74
86
|
def department(departmentid = 1)
|
75
87
|
get 'department/list', params: { id: departmentid }
|
76
88
|
end
|
data/lib/wechat/jsapi_ticket.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# coding: utf-8
|
1
2
|
require 'digest/sha1'
|
2
3
|
|
3
4
|
module Wechat
|
@@ -34,7 +35,7 @@ module Wechat
|
|
34
35
|
# 刷新 jsapi_ticket
|
35
36
|
def refresh
|
36
37
|
data = client.get('ticket/getticket', params: { access_token: access_token.token, type: 'jsapi' })
|
37
|
-
data.merge!(created_at
|
38
|
+
data.merge!('created_at'.freeze => Time.now.to_i)
|
38
39
|
File.open(jsapi_ticket_file, 'w') { |f| f.write(data.to_json) } if valid_ticket(data)
|
39
40
|
@jsapi_ticket_data = data
|
40
41
|
end
|
data/lib/wechat/responder.rb
CHANGED
@@ -15,20 +15,39 @@ module Wechat
|
|
15
15
|
attr_accessor :wechat, :token, :corpid, :agentid, :encrypt_mode, :skip_verify_ssl, :encoding_aes_key
|
16
16
|
|
17
17
|
def on(message_type, with: nil, respond: nil, &block)
|
18
|
-
fail 'Unknow message type' unless [:text, :image, :voice, :video, :location, :link, :event, :fallback].include?(message_type)
|
18
|
+
fail 'Unknow message type' unless [:text, :image, :voice, :video, :location, :link, :event, :click, :scan, :batch_job, :fallback].include?(message_type)
|
19
19
|
config = respond.nil? ? {} : { respond: respond }
|
20
20
|
config.merge!(proc: block) if block_given?
|
21
21
|
|
22
|
-
if with.present?
|
23
|
-
fail 'Only text and
|
22
|
+
if with.present?
|
23
|
+
fail 'Only text, event, click, scan and batch_job can having :with parameters' unless [:text, :event, :click, :scan, :batch_job].include?(message_type)
|
24
|
+
config.merge!(with: with)
|
25
|
+
self.known_scan_key_lists = with if message_type == :scan
|
24
26
|
else
|
25
|
-
|
27
|
+
fail 'Message type click, scan and batch_job must specify :with parameters' if [:click, :scan, :batch_job].include?(message_type)
|
26
28
|
end
|
27
29
|
|
28
|
-
|
30
|
+
case message_type
|
31
|
+
when :click
|
32
|
+
user_defined_click_responders(with) << config
|
33
|
+
when :batch_job
|
34
|
+
user_defined_batch_job_responders(with) << config
|
35
|
+
else
|
36
|
+
user_defined_responders(message_type) << config
|
37
|
+
end
|
29
38
|
config
|
30
39
|
end
|
31
40
|
|
41
|
+
def user_defined_click_responders(with)
|
42
|
+
@click_responders ||= {}
|
43
|
+
@click_responders[with] ||= []
|
44
|
+
end
|
45
|
+
|
46
|
+
def user_defined_batch_job_responders(with)
|
47
|
+
@batch_job_responders ||= {}
|
48
|
+
@batch_job_responders[with] ||= []
|
49
|
+
end
|
50
|
+
|
32
51
|
def user_defined_responders(type)
|
33
52
|
@responders ||= {}
|
34
53
|
@responders[type] ||= []
|
@@ -42,16 +61,14 @@ module Wechat
|
|
42
61
|
when :text
|
43
62
|
yield(* match_responders(responders, message[:Content]))
|
44
63
|
when :event
|
45
|
-
if 'click' == message[:Event]
|
64
|
+
if 'click' == message[:Event] && !user_defined_click_responders(message[:EventKey]).empty?
|
65
|
+
yield(* user_defined_click_responders(message[:EventKey]), message[:EventKey])
|
66
|
+
elsif 'click' == message[:Event]
|
46
67
|
yield(* match_responders(responders, message[:EventKey]))
|
47
|
-
elsif
|
48
|
-
yield(*
|
49
|
-
event_key: message[:EventKey],
|
50
|
-
scan_type: message[:ScanCodeInfo][:ScanType],
|
51
|
-
scan_result: message[:ScanCodeInfo][:ScanResult]))
|
68
|
+
elsif known_scan_key_lists.include?(message[:EventKey])
|
69
|
+
yield(* known_scan_with_match_responders(user_defined_responders(:scan), message))
|
52
70
|
elsif 'batch_job_result' == message[:Event]
|
53
|
-
yield(*
|
54
|
-
batch_job: message[:BatchJob]))
|
71
|
+
yield(* user_defined_batch_job_responders(message[:BatchJob][:JobType]), message[:BatchJob])
|
55
72
|
else
|
56
73
|
yield(* match_responders(responders, message[:Event]))
|
57
74
|
end
|
@@ -73,16 +90,32 @@ module Wechat
|
|
73
90
|
|
74
91
|
if condition.is_a? Regexp
|
75
92
|
memo[:scoped] ||= [responder] + $LAST_MATCH_INFO.captures if value =~ condition
|
76
|
-
elsif value.is_a? Hash
|
77
|
-
memo[:scoped] ||= [responder, value[:scan_result], value[:scan_type]] if value[:event_key] == condition && value[:event] == 'scancode'
|
78
|
-
memo[:scoped] ||= [responder, value[:batch_job]] if value[:event] == 'batch_job' &&
|
79
|
-
%w(sync_user replace_user invite_user replace_party).include?(condition.downcase)
|
80
93
|
else
|
81
94
|
memo[:scoped] ||= [responder, value] if value == condition
|
82
95
|
end
|
83
96
|
end
|
84
97
|
matched[:scoped] || matched[:general]
|
85
98
|
end
|
99
|
+
|
100
|
+
def known_scan_with_match_responders(responders, message)
|
101
|
+
matched = responders.each_with_object({}) do |responder, memo|
|
102
|
+
if %w(scan subscribe).include?(message[:Event]) && message[:EventKey] == responder[:with]
|
103
|
+
memo[:scaned] ||= [responder, message[:Ticket]]
|
104
|
+
elsif %w(scancode_push scancode_waitmsg).include?(message[:Event]) && message[:EventKey] == responder[:with]
|
105
|
+
memo[:scaned] ||= [responder, message[:ScanCodeInfo][:ScanResult], message[:ScanCodeInfo][:ScanType]]
|
106
|
+
end
|
107
|
+
end
|
108
|
+
matched[:scaned]
|
109
|
+
end
|
110
|
+
|
111
|
+
def known_scan_key_lists
|
112
|
+
@known_scan_key_lists ||= []
|
113
|
+
end
|
114
|
+
|
115
|
+
def known_scan_key_lists=(qrscene_value)
|
116
|
+
@known_scan_key_lists ||= []
|
117
|
+
@known_scan_key_lists << qrscene_value
|
118
|
+
end
|
86
119
|
end
|
87
120
|
|
88
121
|
def wechat
|
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.
|
4
|
+
version: 0.6.0
|
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: 2015-
|
12
|
+
date: 2015-10-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -112,7 +112,13 @@ homepage: https://github.com/Eric-Guo/wechat
|
|
112
112
|
licenses:
|
113
113
|
- MIT
|
114
114
|
metadata: {}
|
115
|
-
post_install_message:
|
115
|
+
post_install_message: |-
|
116
|
+
*****WECHAT BREAK CHANGE*****
|
117
|
+
1. Scan 2D barcode using new syntax `on :scan, with: 'BINDING_QR_CODE' `
|
118
|
+
instead of previous `on :event, with: 'BINDING_QR_CODE' `.
|
119
|
+
2. Batch job using new syntax `on :batch_job, with: 'replace_user' `
|
120
|
+
instead of previous `on :event, with: 'replace_user' `.
|
121
|
+
*****************************
|
116
122
|
rdoc_options: []
|
117
123
|
require_paths:
|
118
124
|
- lib
|