wechat 0.12.3 → 0.13.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4f3b96f4a7e2cd18a4a2407f550cf0437fefa8766e26e1356692918932f6441a
4
- data.tar.gz: 024176770cbb290d9fa7039dbb395a6d60d0a64dd6ad20777928771be5feb93d
3
+ metadata.gz: c780f63273dd1e380af79ce5feb14fc9787f0abd47ebc797ae6528b706533e6b
4
+ data.tar.gz: f711e6f2f766db3424f827b0806ea3275fbbaacd33ab777e330eb0e73d2e1161
5
5
  SHA512:
6
- metadata.gz: 51d9e9ede2d8479c81e9b389e3bcfb3ffcf96a4daee330998d30fcde88cb35f7b36b2cf92754e537720781475105ac59e974047b81bc5c12b462b8a0cf156fa1
7
- data.tar.gz: '09fa4efec1ba2843ac564f1ef97b71728d91439849175767416abf67263916c1214b434ea542d85ccb9b1f45e3d3a9538f4555eebfe6acfd6ee85e77fb18c3a1'
6
+ metadata.gz: 83ace7fd48928bd1fb75845294ceef130ad39359b281e903ea7c87cb3e42d7a4e677677df4dfa2ae19ee7561524c6f9ec8e9ae6df13677ecbc828fb4a6b7a93c
7
+ data.tar.gz: 061b40b05dd8f4114f582cf05f2fa18da8f8616671dada4c475d5a80838d985c65ab996843745cb7f15d0fd8c8632018cd285d49653eb0b4b443f19500919880
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/CHANGELOG.md CHANGED
@@ -1,400 +1,22 @@
1
1
  # Changelog
2
2
 
3
- ## v0.12.3 (released at 3/15/2021)
3
+ ## v0.13.3 (released at 6/18/2021)
4
4
 
5
- * Fix MpApi initialize bug, by @hardywu #296
6
-
7
- ## v0.12.2 (released at 3/3/2021)
8
-
9
- * New convert_to_userid API
10
-
11
- ## v0.12.1 (released at 28/12/2020)
12
-
13
- * Support Ruby 3.0.
14
- * Qcloud_token support.
15
- * CRUD of tencent cloud DB for miniapp
16
- * TCB storage API support.
17
- * Set default branch to *main*.
18
-
19
- ## v0.11.11 (released at 09/13/2020)
20
-
21
- * FIX: fix_load_controller_wechat not support MP type, by @Msms-NJ #281
22
-
23
- ## v0.11.10 (released at 09/02/2020)
24
-
25
- * ADD: Wechat::MpApi.wxa_msg_sec_check.
26
-
27
- ## v0.11.9 (released at 04/29/2020)
28
-
29
- * CHG: upgrade ssl_version to 1.2 by @paicha #276
30
-
31
- ## v0.11.8 (released at 03/09/2020)
32
-
33
- * ADD: Wechat::CorpApi.news_message_send
34
- * FIX: Wechat API Change material/get_material. reported by @0000sir #275
35
-
36
- ## v0.11.7 (released at 11/15/2019)
37
-
38
- * ADD: Wechat::MpApi.subscribe_message_send. by @paicha #271
39
- * FIX: FrozenError: can't modify frozen String. by @paicha #272
40
- * New translatecontent support.
41
-
42
- ## v0.11.6 (released at 09/02/2019)
43
-
44
- * Fix private method `next_migration_number` introduced at #267, by @zpdsky #270
45
- * Give more clear warning about missing Rails in console. by @emtfe #268
46
-
47
- ## v0.11.5 (released at 08/30/2019)
48
-
49
- * Add rubocop check in CI by @hophacker #267
50
- * Support Rails 6 and Windows at #266
51
-
52
- ## v0.11.4 (released at 08/15/2019)
53
-
54
- * rails 6 redirect_to use allow_other_host: true by @Chen-George-Zhen #263
55
-
56
- ## v0.11.3 (released at 07/02/2019)
57
-
58
- * New addvoicetorecofortext and queryrecoresultfortext support.
59
- * improve existing class detect by @3014zhangshuo #261
60
- * new wxa_get_wxacode_unlimit API for miniapp by @paicha #260
61
-
62
- ## v0.11.2 (released at 05/08/2019)
63
-
64
- * bugfix short_url to shorturl in wechat console tool by @yuanxinyu #259
65
- * allow a message to be sent to a party (department) by @hophacker #256
66
-
67
- ## v0.11.1 (released at 03/01/2019)
68
-
69
- * Let Message support markdown, text included; allow textcard btntxt to be omitted by @hophacker #251
70
- * Enterprise account add checkin api by @hophacker #254
71
- * Suggest use secret to differentiate different acces_tokens and tickets in Enterprise account by @hophacker #255
72
-
73
-
74
- ## v0.11.0 (released at 01/22/2019)
75
-
76
- * Support Ruby 2.6.0 official
77
- * Bump http gem to 4.0
78
- * New clear quota API by @3014zhangshuo #244
79
- * Wechat::Message support textcard by @hophacker #249
80
- * New getusersummary and getusercumulate API #247
81
-
82
- ## v0.10.3 (released at 10/07/2018)
83
-
84
- * Fix new share problem in iOS by @killernova #242
85
-
86
- ## v0.10.2 (released at 8/27/2018)
87
-
88
- * Fix incompatible with Rails 5.2.1 by @chloerei #239
89
-
90
- ## v0.10.1 (released at 7/1/2018)
91
-
92
- * Allow custom_message_send using Hash as message, previous only allow Wechat::Message. by @zuoliang0 and @fogisland #234
93
-
94
- ## v0.10.0 (released at 5/31/2018)
95
-
96
- * Support multi wechat account at wechat_responder. by @tuliren #223
97
- * Support wechat mini program apis & signature check. by @oiahoon #225
98
- * Support sent template message with miniprogram. by @falm #228
99
- * Fix request_content could be nil. by @paicha #229
100
-
101
- ## v0.9.0 (released at 4/15/2018)
102
-
103
- * Support multi wechat account dynamically loading from DB. by @tuliren #222
104
- * user_create API for enterprise account. #206
105
- * Will ignore template_message_send error 43004 by @insub #214
106
- * using template with version if the migration version available by @killernova #220
107
- * Remove Deprecation oauth2_url
108
- * Remove Ruby 2.2 support, add Rails 5.2 and http v3 support
109
-
110
- ## v0.8.12 (released at 9/13/2017)
111
-
112
- * Read oauth2_state from ticket store every time to avoid invalid oauth2_state by @xiewenwei #196
113
-
114
- ## v0.8.11 (released at 7/25/2017)
115
-
116
- * oauth2 state code not refresh at the same time of jsapi tickets refresh bug, many thanks @xiewenwei #192
117
- * Add string type scene support for qrcode_create_scene. by @libuchao #191
118
-
119
- ## v0.8.10 (released at 6/19/2017)
120
-
121
- * fix material_delete correctly.
122
-
123
- ## v0.8.9 (released at 6/18/2017)
124
-
125
- * wechat material_delete failed to work, thanks @Victorialice report #78
126
-
127
- ## v0.8.8 (released at 5/18/2017)
128
-
129
- * Better support multiple account. by @xiewenwei #187
130
- * Allow load figaro via RAILS_ENV. by @goofansu #186
131
-
132
- ## v0.8.7 (released at 4/23/2017)
133
-
134
- * Support new wxa_get_wxacode API for miniapp.
135
- * Add InvalidCredentialError, support audio/amr, voice/speex as file and text/plain as json. by @acenqiu #184
136
-
137
- ## v0.8.6 (released at 3/17/2017)
138
-
139
- * Support Rails 5.1 officially.
140
- * make sure the formfile can be created outside. by @mechiland #181
141
-
142
- ## v0.8.5 (released at 3/14/2017)
143
-
144
- * Support mass send API #176
145
- * Support new media_hq API
146
- * Support new createwxaqrcode API for miniapp
147
- * Fix wechat_responder not proper injected in rails 5 API #165
148
- * parse response support XML return, by @zhangbin #167
149
- * WeChat only allow 8 article per one news, by @kikyous #175
150
- * Store token at cookies, by @jstdoit #174
151
-
152
- ## v0.8.4 (released at 1/12/2017)
153
-
154
- * Support Ruby 2.4.0
155
- * Add support of Enterprise RedPacket API, by @zhangbin #169
156
-
157
- ## v0.8.3 (released at 11/26/2016)
158
-
159
- * Fix wechat template key has camelCase problem, by @RyanChenDji #159
160
- * Fix long time of oauth2_state bug for wechat_oauth2 methods, by @IvanChou #162
161
-
162
- ## v0.8.2 (released at 11/2/2016)
163
-
164
- * Bug which if not using multi-account but using web login.
165
-
166
- ## v0.8.1 (released at 11/2/2016)
167
-
168
- * After allow sub controller using wechat_api, it's possible not initialise at first time. by @IvanChou #155
169
- * Support web application login scope snsapi_login.
170
- * Add unionid support for public account.
171
- * Remove OpenId in Enterprise OAuth2 as it's not supported by Tecent.
172
-
173
- ## v0.8.0 (released at 10/24/2016)
174
-
175
- * Complete support multi-wechat public account. by @xiewenwei #150
176
- * Support loading configure value from Figaro if application.yml exist.
177
-
178
- ## v0.7.20 (released at 8/29/2016)
179
-
180
- * Apply opt and config together when loading controller_wechat, to simplify wechat_responder params. by @bzhang443 #147
181
-
182
- ## v0.7.19 (released at 8/25/2016)
5
+ * material add video description by @zlei1 #301
6
+ * Allow using http v5
183
7
 
184
- * Enterprise account now custom_image/voice/file works now. by @zymiboxpay #145
185
- * Fix timeout setting no effective since introduct HTTP. found by @hsluo #74
8
+ ## v0.13.2 (released at 4/21/2021)
186
9
 
187
- ## v0.7.18 (released at 8/21/2016)
10
+ * New material_add_news API, by @zlei1 #300
11
+ * Support open_tag, by @xiajian2019 #299
188
12
 
189
- * Support label_location message, similar to location event, but sent by user with Label. #144
190
- * Add gem signature as additional security methods.
13
+ ## v0.13.1 (released at 3/15/2021)
191
14
 
192
- ## v0.7.17 (released at 8/18/2016)
193
-
194
- * Allow declare wechat_api at ApplicationController, but using wechat at sub controller. #104
195
-
196
- ## v0.7.16 (released at 7/27/2016)
197
-
198
- * FIX: consider '' in params as equal with nil, in ControllerApi#wechat_public_oauth2, by @snow #135
199
- * New tag API for public account, by @pynixwang #127
200
- * fix SSLv3 error by use TLSv1_client, by @IvanChou #133
201
-
202
- ## v0.7.15 (released at 7/03/2016)
203
-
204
- * RSpec testing case on Rails 5 now.
205
- * Resolve Rails 5 ActionController::Parameters issue.
206
-
207
- ## v0.7.14 (released at 5/29/2016)
208
-
209
- * Fix when access_token failed lead ticket can not refresh problem.
210
- * Default duration should be 1 hours instead of 0 seconds for wechat_oauth2.
211
- * New shorturl allowing convert from long URL to short.
212
-
213
- ## v0.7.13 (released at 5/14/2016)
214
-
215
- * Wechat.config.oauth2_cookie_duration need convert to secondes, found by @gabrieltong #111
216
-
217
- ## v0.7.12 (released at 5/12/2016)
218
-
219
- * Fix web_userinfo wrong URL, found by @gabrieltong #110
220
-
221
- ## v0.7.11 (released at 4/18/2016)
222
-
223
- * To cover wrong release 0.7.10, nothing change
224
-
225
- ## v0.7.10 (released at 4/18/2016) (yanked)
226
-
227
- ## v0.7.9 (released at 4/12/2016)
228
-
229
- * wechat_oauth2 support public account now.
230
- * Refresh and store state on jsapi ticket, using it on oauth2_url to more secure.
231
- * Remove extra sending payload in message template send json
232
- * Allow setting oauth2_cookie_duration in config
233
-
234
- ## v0.7.8 (released at 3/31/2016)
235
-
236
- * New wechat_api, similar to wechat_responder, but without messange handle DSL, support web page only wechat application
237
- * New media_uploadimg API.
238
- * New file type of Message.
239
- * Improved multi account support per different controller.
240
-
241
- ## v0.7.7 (released at 3/18/2016)
242
-
243
- * New wechat_oauth2, only support enterprise account still.
244
- * fix 'skip_before_action :verify_authenticity_token' bug for v5.0.0.beta3 by @vkill #97
245
- * Support Rails 3.2 again after support Rails 5.0, by @guange2015 #96
246
-
247
- ## v0.7.6 (released at 3/05/2016)
248
-
249
- * Support wechat public account conditional menu. #95
250
-
251
- ## v0.7.5 (released at 2/21/2016)
252
-
253
- * New wechat_config_js to simplify the Wechat jsapi config.
254
- * Support sent shortvideo.
255
-
256
- ## v0.7.4 (released at 1/23/2016)
257
-
258
- * Add Redis store token/ticket support, close #76, #60
259
- * Rails 5 support without deprecate warning or other not necessory call. #82
260
-
261
- ## v0.7.3 (released at 1/19/2016)
262
-
263
- * Allow transfer_customer_service to specific account.
264
- * New customservice_getonlinekflist API.
265
- * session support class WechatSession no need table_exists? methods exist.
266
-
267
- ## v0.7.2 (released at 1/18/2016)
268
-
269
- * Optional session support by @zfben #81, #88, #91
270
- * Replace after_wechat_response with Rails Nofications facility, by @zfben, original issue is #79
271
- * New user_batchget API. #89
272
- * Support Rails 3.2 again after support Rails 5.0. by @guange2015 #87
273
- * Fetch setting from RAILS_ENV first, then fetch default. by @kikyous #85
274
- * Warning not support on :scan with regular expression, reason see #84
275
-
276
- ## v0.7.1 (released at 1/11/2016)
277
-
278
- * Fix after using http, upload file function break. #78
279
- * Add callback function after_wechat_response support. by @zfben #79
280
- * Should using department_id instead of departmentid at enterprise api: user_simplelist/user_list.
281
-
282
- ## v0.7.0 (released at 1/1/2016)
283
-
284
- * Using [http](https://github.com/httprb/http) instead of rest-client for performance reason. (not support upload file yet)
285
-
286
- ## v0.6.10 (released at 1/17/2016)
287
-
288
- * Support Rails 3.2 again after support Rails 5.0. by @guange2015 #87
289
- * Fetch setting from RAILS_ENV first, then fetch default. by @kikyous #85
290
- * Warning not support on :scan with regular expression. by @kikyous #84
291
-
292
- ## v0.6.9 (released at 1/6/2016)
293
-
294
- * Fix token refresh bug on multi worker. #76
295
- * Rewrite the token relative code to add more storage support in future.
296
-
297
- ## v0.6.8 (released at 12/25/2015)
298
-
299
- * Support Rails 5.0.0.beta1.
300
- * English README available
301
- * Fix oauth2_url calling error, fix #75
302
-
303
- ## v0.6.7 (released at 12/18/2015)
304
-
305
- * Add timeout configuration option, close #74
306
- * New getuserinfo and oauth2_url to support getting FromUserName from web page.
307
-
308
- ## v0.6.6 (released at 12/15/2015)
309
-
310
- * Add jsapi_ticket support for Enterprise Account
311
- * Default generated WechatsController < ActionController::Base, as many Rails application may having #authenticate_user or #set_current_user in ApplicationController, so easily affect the first time using experience.
312
- * New syntax `on :view, with: 'VIEW_URL'` support.
313
- * New command `upload_replaceparty` which combine three sub command to make uploading department easier.
314
- * New command `upload_replaceuser` which combine three sub command to make uploading user easier.
315
-
316
- ## v0.6.5 (released at 11/24/2015)
317
-
318
- * Handle 48001 error if token is expire/not valid, close #71
319
- * ApiLoader will do config reading and initialize the api instead of spreading the logic.
320
-
321
- ## v0.6.4 (released at 11/16/2015)
322
-
323
- * Command mode now display different command set based on enterprise/public account setting
324
- * Move config logic in command/wechat to ApiLoader class
325
- * Unsubscribe can only reply plain text 'success' #68
326
- * Fix 404 qrcode download problem, by @huangxiangdan #69
327
-
328
- ## v0.6.3 (released at 11/14/2015)
329
-
330
- * Official testing and support public encrypt mode, also fix one cipher bug, many thanks to @hlltc #67
331
- * hlltc report public account FILE_BASE no longer needs, clean code #67
332
- * Media command line reflect recent Tecent json schema change. #67
333
-
334
- ## v0.6.2 (released at 11/05/2015)
335
-
336
- * Tecent report location API changed, so change wechat gems also. #64
337
-
338
- ## v0.6.1 (released at 10/20/2015)
339
-
340
- * Handle 40001, invalid credential, access_token is invalid or not latest hint # 57
341
- * Support at Rails 4.2.1 wechat can not run #58
342
-
343
- ## v0.6.0 (released at 10/08/2015)
344
-
345
- ### Scan and Batch job are BREAK CHANGE!
346
-
347
- * Scan 2D barcode using new syntax `on :scan, with: 'BINDING_QR_CODE' ` instead of `on :event, with: 'BINDING_QR_CODE' ` in previous version #55
348
- Which will fix can not using `on :event, with: "scan" ` problem
349
- * Batch job using new syntax `on :batch_job, with: 'replace_user' `
350
- instead of previous `on :event, with: 'replace_user' `.
351
- * 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.
352
- * Wechat::Responder using Hash for new :client and :batch_job event, avoid time consuming Array match responder
353
- * Fix refresh token not working problem under ruby 2.0.0 #54
354
- * New department_update, user_batchdelete, convert_to_openid API
355
-
356
- ## v0.5.0 (released at 9/25/2015)
357
-
358
- * Only relay on activesupport on run time, so will greatly improve wechat cli startup time
359
- * Add rails generator support `rails g wechat:install`
360
- * Add batch job support for enterprise account like batch create user/department, both API, callback responder and CLI
361
- * Add material management API and CLI
362
- * Add tag API and CLI for enterprise account
363
- * Add QR code scene function for public account
364
-
365
- ## v0.4.2 (released at 9/7/2015)
366
-
367
- * Fix wrong number of arguments at Wechat::Responder.on by using arity #47
368
- * Fix can not access wechat method after using instance level context.
369
- * Fix skip_verify_ssl parameter error.
370
-
371
- ## v0.4.1 (released at 9/6/2015)
372
-
373
- * Limit news articles collection to 10, close #5
374
- * Resolve the conflict with gem "responders" by @seamon #45
375
-
376
- ## v0.4.0 (released at 9/5/2015)
377
-
378
- * Enable the verify SSL for enterprise mode by default, as security is more importent than speed, but still can switch off by configure
379
- * Support scancode_push/scancode_waitmsg event.
380
- * New API method can get wechat server IP list
381
- * New API to query/create department/media/material
382
- * Fix can not read token_file in mingw bug, which introduce at #43
383
-
384
- ## v0.3.0 (released at 8/30/2015)
385
-
386
- * New user group management API
387
- * Allow transfer to customer service on fallback. #42
388
- * Read and write access_token properly using file locking, #43
389
-
390
- ## v0.2.0 (released at 8/27/2015)
15
+ * Fix MpApi initialize bug, by @hardywu #296
391
16
 
392
- * Add wechat enterprise account support
393
- * Make responder execute in action context, by @lazing #15
394
- * jsapi_ticket support, by @feitian124 #27
395
- * Rename gems to wechat and ambitious to being #1 gems about development wechat. thanks Xiaoning transfer this gem name.
396
- * Original gem `wechat-rails` author skinnyworm trasfer to Eric-Guo as maintainer
17
+ ## v0.13.0 (released at 3/3/2021)
397
18
 
398
- ## v0.1.1
19
+ * Support zeitwerk only and Rails 6+ only.
20
+ * Support Ruby 2.6+ only.
399
21
 
400
- * Initial release from [wechat-rails](https://github.com/skinnyworm/wechat-rails).
22
+ Previous changelog see https://github.com/Eric-Guo/wechat/blob/master/CHANGELOG_OLD.md
data/README-CN.md CHANGED
@@ -3,23 +3,23 @@ WeChat [![Gem Version](https://badge.fury.io/rb/wechat.svg)](https://rubygems.or
3
3
 
4
4
  [![Join the chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Eric-Guo/wechat?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
5
5
 
6
- WeChat gem帮助开发者方便地在Rails环境中集成[微信公众平台](https://developers.weixin.qq.com/doc/offiaccount/Getting_Started/Overview.html)、[企业微信](https://work.weixin.qq.com/api/doc)和[小程序](https://developers.weixin.qq.com/miniprogram/dev/framework/),包括功能:
6
+ WeChat Gem 帮助开发者方便地在 Rails 环境中集成[微信公众平台](https://developers.weixin.qq.com/doc/offiaccount/Getting_Started/Overview.html)、[企业微信](https://work.weixin.qq.com/api/doc)和[小程序](https://developers.weixin.qq.com/miniprogram/dev/framework/),包括功能:
7
7
 
8
- - 微信公众平台/企业微信[发送消息](http://qydev.weixin.qq.com/wiki/index.php?title=%E5%8F%91%E9%80%81%E6%B6%88%E6%81%AF)API(命令行和Web环境都可以使用)
9
- - [接收消息](http://qydev.weixin.qq.com/wiki/index.php?title=%E6%8E%A5%E6%94%B6%E6%B6%88%E6%81%AF%E4%B8%8E%E4%BA%8B%E4%BB%B6)(必须运行Web服务器)
10
- - [微信JS-SDK](http://qydev.weixin.qq.com/wiki/index.php?title=%E5%BE%AE%E4%BF%A1JS%E6%8E%A5%E5%8F%A3) config接口注入权限验证
11
- - OAuth 2.0认证机制
12
- - 接收消息会话(session)记录机制(可选)
8
+ - 微信公众平台/企业微信[发送消息](http://qydev.weixin.qq.com/wiki/index.php?title=%E5%8F%91%E9%80%81%E6%B6%88%E6%81%AF) API(命令行和 Web 环境都可以使用)
9
+ - [接收消息](http://qydev.weixin.qq.com/wiki/index.php?title=%E6%8E%A5%E6%94%B6%E6%B6%88%E6%81%AF%E4%B8%8E%E4%BA%8B%E4%BB%B6)(必须运行 Web 服务器)
10
+ - [微信JS-SDK](http://qydev.weixin.qq.com/wiki/index.php?title=%E5%BE%AE%E4%BF%A1JS%E6%8E%A5%E5%8F%A3) config 接口注入权限验证
11
+ - OAuth 2.0 认证机制
12
+ - 接收消息会话 ( Session ) 记录机制(可选)
13
13
 
14
- 命令行工具`wechat`可以调用各种无需web环境的API。同时也提供了Rails Controller的responder DSL, 可以帮助开发者方便地在Rails应用中集成微信的消息处理,包括主动推送的和被动响应的消息。
14
+ 命令行工具 `wechat` 可以调用各种无需 Web 环境的 API,同时也提供了 Rails Controller Responder DSL 。可以帮助开发者方便地在Rails 应用中集成微信的消息处理,包括主动推送的和被动响应的消息。
15
15
 
16
- 如果您的App还需要集成微信OAuth2.0, 除了简便的`wechat_oauth2`指令,也可以考虑[omniauth-wechat-oauth2](https://github.com/skinnyworm/omniauth-wechat-oauth2), 以便和devise集成,提供完整的用户认证。
16
+ 如果您的 App 还需要集成微信 OAuth2.0 除了简便的 `wechat_oauth2` 指令,也可以考虑 [omniauth-wechat-oauth2](https://github.com/skinnyworm/omniauth-wechat-oauth2) 以便和 [devise](https://github.com/heartcombo/devise) 集成提供完整的用户认证。
17
17
 
18
- 如果您对如何制作微信网页UI没有灵感,可以参考官方的[weui](https://github.com/weui/weui),针对Rails的Gem是[weui-rails](https://github.com/Eric-Guo/weui-rails)。
18
+ 如果您对如何制作微信网页 UI 没有灵感,可以参考官方的 [weui](https://github.com/weui/weui) 。针对 Rails Gem [weui-rails](https://github.com/Eric-Guo/weui-rails)。
19
19
 
20
- 主页型应用请使用[`wechat_api`](#wechat_api---rails-controller-wechat-api),传统消息型应用请使用[`wechat_responder`](#wechat_responder---rails-responder-controller-dsl)。
20
+ 主页型应用请使用 [`wechat_api`](#wechat_api---rails-controller-wechat-api),传统消息型应用请使用 [`wechat_responder`](#wechat_responder---rails-responder-controller-dsl)。
21
21
 
22
- 如果您想从一个稍微完整一些的示例开始微信开发,可以参考[wechat-starter](https://github.com/goofansu/wechat-starter),这个示例甚至包括了微信支付的内容。
22
+ 如果您想从一个稍微完整一些的示例开始微信开发,可以参考 [wechat-starter](https://github.com/goofansu/wechat-starter),这个示例甚至包括了微信支付的内容。
23
23
 
24
24
  ## 安装
25
25
 
@@ -27,12 +27,16 @@ WeChat gem帮助开发者方便地在Rails环境中集成[微信公众平台](ht
27
27
 
28
28
  ```
29
29
  gem install "wechat"
30
+ # 如果使用 Ruby 版本小于 2.6
31
+ # gem install wechat -v 0.12.2
30
32
  ```
31
33
 
32
34
  或者添加下面这行到 `Gemfile`:
33
35
 
34
36
  ```
35
37
  gem 'wechat'
38
+ # 如果使用 Rails 版本小于 6
39
+ # gem 'wechat', '~> 0.12.2'
36
40
  ```
37
41
 
38
42
  运行下面这行代码来安装:
@@ -47,24 +51,24 @@ bundle install
47
51
  rails generate wechat:install
48
52
  ```
49
53
 
50
- 运行`rails g wechat:install`后会自动生成wechat.yml配置,还有wechat controller及相关路由配置到当前Rails项目。
54
+ 运行 `rails g wechat:install` 后会自动生成 wechat.yml 配置,还有 wechats_controller 及相关路由配置到当前 Rails 项目。
51
55
 
52
- 启用session会话记录:
56
+ 启用 Session 会话记录:
53
57
 
54
58
  ```console
55
59
  rails g wechat:session
56
60
  rake db:migrate
57
61
  ```
58
62
 
59
- 运行后会自动启用回调消息会话(session)记录,wechat gem会在Rails项目中生成两个文件,用户可以在*wechat_session*表中添加更多字段或者声明一些关联关系。使用已有的**hash_store**直接保存也是可以的,但对于PostgreSQL用户,使用[hstore](http://guides.rubyonrails.org/active_record_postgresql.html#hstore)或者json格式可能更佳,当然,最佳方案仍然是添加新字段记录数据。
63
+ 运行后会自动启用回调消息会话 (Session) 记录,`wechat` Gem 会在 Rails 项目中生成两个文件,用户可以在 *wechat_session* 表中添加更多字段或者声明一些关联关系。使用已有的 **hash_store** 直接保存也是可以的,但对于 PostgreSQL 用户,使用 [hstore](http://guides.rubyonrails.org/active_record_postgresql.html#hstore) 或者 json 格式可能更佳,当然最佳方案仍然是添加新字段记录数据。
60
64
 
61
- 启用Redis存贮tokenticket:
65
+ 启用 Redis 存贮 Token Ticket:
62
66
 
63
67
  ```console
64
68
  rails g wechat:redis_store
65
69
  ```
66
70
 
67
- Redis存贮相比默认的文件存贮,可以允许Rails应用运行在多台服务器中,如果只有一台服务器,仍然推荐使用默认的文件存贮,另外命令行不会读取Redis存贮的Token或者Ticket。
71
+ Redis 存贮相比默认的文件存贮,可以允许 Rails 应用运行在多台服务器中。如果只有一台服务器,仍然推荐使用默认的文件存贮,另外命令行不会读取 Redis 存贮的 Token 或者 Ticket。
68
72
 
69
73
  启用数据库配置微信账户:
70
74
 
@@ -73,7 +77,7 @@ rails g wechat:config
73
77
  rake db:migrate
74
78
  ```
75
79
 
76
- 运行后会在数据库中创建 `wechat_configs` 表,用来记录不同微信账户的配置。
80
+ 运行后会在数据库中创建 `wechat_configs` 表用来记录不同微信账户的配置。
77
81
 
78
82
  ## 配置
79
83
 
@@ -81,13 +85,13 @@ rake db:migrate
81
85
 
82
86
  请先确保在服务器上配置成功,再到微信官网提交链接。否则微信会提示错误。
83
87
 
84
- 默认通过`rails g wechat:install`生成的URL是: `http://your-server.com/wechat`
88
+ 默认通过 `rails g wechat:install` 生成的 URL 是: `http://your-server.com/wechat`
85
89
 
86
- appid/corpid,以及secret的配置请阅读下一节
90
+ appid/corpid 以及 secret 的配置请阅读下一节
87
91
 
88
92
  #### 命令行程序的配置
89
93
 
90
- 要使用命令行程序,需要在home目录中创建一个`~/.wechat.yml`,包含以下内容。其中`access_token`是存放access_token的文件位置。
94
+ 要使用命令行程序,需要在 home 目录中创建一个 `~/.wechat.yml`,包含以下内容。其中 `access_token` 是存放 access_token 的文件位置。
91
95
 
92
96
  ```
93
97
  appid: "my_appid"
@@ -95,17 +99,17 @@ secret: "my_secret"
95
99
  access_token: "/var/tmp/wechat_access_token"
96
100
  ```
97
101
 
98
- Windows或者使用企业号,需要存放在`C:/Users/[user_name]/`下,其中corpid和corpsecret可以从企业号管理界面的设置->权限管理,通过新建任意一个管理组后获取。
102
+ Windows 或者使用企业号需要存放在 `C:/Users/[user_name]/` 下,其中 corpid corpsecret 可以从企业号管理界面的设置 -> 权限管理,通过新建任意一个管理组后获取。
99
103
 
100
104
  ```
101
105
  corpid: "my_appid"
102
106
  corpsecret: "my_secret"
103
- agentid: 1 # 企业应用的id,整型。可在应用的设置页面查看
107
+ agentid: 1 # 企业应用的 id 整型可在应用的设置页面查看
104
108
  access_token: "C:/Users/[user_name]/wechat_access_token"
105
109
  ```
106
110
 
107
111
  #### Rails 全局配置
108
- Rails应用程序中,需要将配置文件放在`config/wechat.yml`,可以为不同environment创建不同的配置。
112
+ Rails 应用程序中,需要将配置文件放在 `config/wechat.yml`,可以为不同 environment 创建不同的配置。
109
113
 
110
114
  微信公众平台配置示例:
111
115
 
@@ -141,7 +145,7 @@ default: &default
141
145
  encoding_aes_key: "my_encoding_aes_key"
142
146
  ```
143
147
 
144
- 企业微信配置下必须使用加密模式,其中token和encoding_aes_key可以从企业号管理界面的应用中心->某个应用->模式选择,选择回调模式后获得。
148
+ 企业微信配置下必须使用加密模式,其中 token encoding_aes_key 可以从企业号管理界面的应用中心 -> 某个应用 -> 模式选择,选择回调模式后获得。
145
149
 
146
150
  ```
147
151
  default: &default
@@ -192,31 +196,31 @@ test:
192
196
  # secret: "my_secret"
193
197
  ```
194
198
 
195
- 支持 微信公众平台/企业微信 多账号的注意点(例如,增加账号`wx2`):
199
+ 支持微信公众平台 / 企业微信多账号的注意点 ( 例如: 增加账号 `wx2` ):
196
200
 
197
- * 配置文件可增加多个微信公众平台(企业微信)配置,用法类似Rails中`config/database.yml`多数据库配置的处理。`development`, `test`, `production`是默认账号的配置段,要想增加账号`wx2`,你需要增加配置段`wx2_development`, `wx2_test`, `wx2_production`。
201
+ * 配置文件可增加多个微信公众平台 ( 企业微信 ) 配置,用法类似 Rails 中 `config/database.yml` 多数据库配置的处理。 `development`, `test`, `production` 是默认账号的配置段,要想增加账号 `wx2`,你需要增加配置段 `wx2_development`, `wx2_test`, `wx2_production`。
198
202
 
199
- * 声明账号`wx2`的`wechat_responder`:
203
+ * 声明账号 `wx2 `的 `wechat_responder`:
200
204
  ```ruby
201
205
  wechat_responder account: :wx2
202
206
  ```
203
207
 
204
- * `Wechat.api(:wx2)` 表示使用账号`wx2`的Wechat api,而`Wechat.api`或`Wechat.api(:default)`则表示默认账号的wechat api。
208
+ * `Wechat.api(:wx2)` 表示使用账号 `wx2` 的 Wechat api,而 `Wechat.api` 或 `Wechat.api(:default)` 则表示默认账号的 wechat api。
205
209
 
206
- * 在wechat命令行中,通过增加可选参数`-a, [--account=ACCOUNT]`来表示使用其他账号,例如`wechat users -a wx2`表示列举`wx2`这个账号的粉丝列表
210
+ * 在 wechat 命令行中,通过增加可选参数 `-a, [--account=ACCOUNT]` 来表示使用其他账号,例如 `wechat users -a wx2` 表示列举 `wx2` 这个账号的粉丝列表
207
211
 
208
- 进一步的多账号支持参见[PR 150](https://github.com/Eric-Guo/wechat/pull/150)。
212
+ 进一步的多账号支持参见 [PR 150](https://github.com/Eric-Guo/wechat/pull/150)。
209
213
 
210
214
  #### 数据库微信账户配置
211
215
  启用数据库微信配置之后,会生成如下数据表:
212
216
 
213
217
  属性 | 类型 | 备注
214
218
  ---- | ---- | ----
215
- environment | 字串 | 必填。配置对应的运行环境,一般有:`production`、`development`、`test`。比如 `production` 配置仅在生产环境有效。默认为 `development`。
216
- account | 字串 | 必填。自定义的微信账户名称。同一 `environment` 下,账户名称不允许重复。
217
- enabled | 布尔 | 必填。配置是否生效。默认 `true`。
218
- appid | 字串 | 公众号 id。此字段和 `corpid` 两者必填其一。
219
- secret | 字串 | 公众号相关配置。当公众号 `appid` 存在时必填。
219
+ environment | 字串 | 必填。配置对应的运行环境,一般有:`production`、`development`、`test`。比如 `production` 配置仅在生产环境有效。默认为 `development`。
220
+ account | 字串 | 必填。自定义的微信账户名称。同一 `environment` 下,账户名称不允许重复。
221
+ enabled | 布尔 | 必填。配置是否生效。默认 `true`。
222
+ appid | 字串 | 公众号 id , 此字段和 `corpid` 两者必填其一。
223
+ secret | 字串 | 公众号相关配置。当公众号 `appid` 存在时必填。
220
224
  corpid | 字串 | 企业号 id。此字段和 `appid` 两者必填其一。
221
225
  corpsecret | 字串 | 企业号相关配置。当企业号 `corpid` 存在时必填。
222
226
  agentid | 整数 | 企业号相关配置。当企业号 `corpid` 存在时必填。
@@ -225,7 +229,7 @@ encoding_aes_key | 字串 | 当 `encrypt_mode` 为 `true` 时必填。
225
229
  token | 字串 | 必填。
226
230
  access_token | 字串 | 必填。存储 `access token` 文件的路径。
227
231
  jsapi_ticket | 字串 | 必填。存储 `jsapi ticket` 文件的路径。
228
- skip_verify_ssl | 布尔
232
+ skip_verify_ssl | 布尔|
229
233
  timeout | 整数 | 默认值是 20。
230
234
  trusted_domain_fullname | 字串 |
231
235
 
@@ -233,21 +237,21 @@ trusted_domain_fullname | 字串 |
233
237
 
234
238
  ##### 配置优先级
235
239
 
236
- 注意在Rails项目根目录下运行`wechat`命令行工具会优先使用`config/wechat.yml`中的`default`配置,如果失败则使用`~\.wechat.yml`中的配置,以便于在生产环境下管理多个微信账号应用。
240
+ 注意在Rails项目根目录下运行 `wechat` 命令行工具会优先使用 `config/wechat.yml `中的 `default`配置,如果失败则使用 `~\.wechat.yml` 中的配置,以便于在生产环境下管理多个微信账号应用。
237
241
 
238
- 如果启用数据库账户配置,数据库中的账户信息在读入 `wechat.yml` 或环境变量之后被载入。当存在同名账户时,数据库中的配置会覆盖前两者。
242
+ 如果启用数据库账户配置,数据库中的账户信息在读入 `wechat.yml` 或环境变量之后被载入。当存在同名账户时,数据库中的配置会覆盖前两者。
239
243
 
240
244
  ##### 配置微信服务器超时
241
245
 
242
- 微信服务器有时请求会花很长时间,如果不配置,默认为20秒,可视情况配置。
246
+ 微信服务器有时请求会花很长时间,如果不配置默认为 20 秒,可视情况配置。
243
247
 
244
248
  ##### 配置跳过SSL认证
245
249
 
246
- Wechat服务器有报道曾出现[RestClient::SSLCertificateNotVerified](http://qydev.weixin.qq.com/qa/index.php?qa=11037)错误,此时可以选择关闭SSL验证。`skip_verify_ssl: true`
250
+ Wechat 服务器有报道曾出现 [RestClient::SSLCertificateNotVerified](http://qydev.weixin.qq.com/qa/index.php?qa=11037) 错误,此时可以选择关闭SSL验证。`skip_verify_ssl: true`
247
251
 
248
- #### 为每个Responder配置不同的appid和secret
252
+ #### 为每个 Responder 配置不同的 appid secret
249
253
 
250
- 有些情况下,单个Rails应用可能需要处理来自多个微信公众号的消息,您可以通过在`wechat_responder`和`wechat_api`后配置多个相关参数来支持多账号。
254
+ 有些情况下,单个 Rails 应用可能需要处理来自多个微信公众号的消息,您可以通过在 `wechat_responder` 和 `wechat_api` 后配置多个相关参数来支持多账号。
251
255
 
252
256
  ```ruby
253
257
  class WechatFirstController < ActionController::Base
@@ -272,9 +276,9 @@ end
272
276
 
273
277
  #### JS-SDK 支持
274
278
 
275
- 通过JS-SDK可以在HTML网页中控制微信客户端的行为,但必须先注入配置信息,wechat gems提供了帮助方法`wechat_config_js`使这个过程更简单:
279
+ 通过 JS-SDK 可以在 HTML 网页中控制微信客户端的行为,但必须先注入配置信息. Wechat gem 提供了帮助方法 `wechat_config_js` 使这个过程更简单:
276
280
 
277
- 注意wechat_config_js指令依赖于[`wechat_api`](#wechat_api---rails-controller-wechat-api) [`wechat_responder`](#wechat_responder---rails-responder-controller-dsl) ,需要先在controller里面添加。
281
+ 注意 wechat_config_js 指令依赖于 [`wechat_api`](#wechat_api---rails-controller-wechat-api) [`wechat_responder`](#wechat_responder---rails-responder-controller-dsl) ,需要先在 controller 里面添加。
278
282
 
279
283
  ```erb
280
284
  <body>
@@ -288,9 +292,9 @@ end
288
292
  </body>
289
293
  ```
290
294
 
291
- 在开发模式下,由于程序往往通过微信调试工具的服务器端调试工具反向代理被访问,此时需要配置`trusted_domain_fullname`以便wechat gem可以使用正确的域名做JS-SDK的权限签名。
295
+ 在开发模式下,由于程序往往通过微信调试工具的服务器端调试工具反向代理被访问,此时需要配置 `trusted_domain_fullname` 以便wechat gem 可以使用正确的域名做 JS-SDK 的权限签名。
292
296
 
293
- #### OAuth2.0验证接口支持
297
+ #### OAuth2.0 验证接口支持
294
298
 
295
299
  公众号可使用如下代码取得关注用户的相关信息。
296
300
 
@@ -303,7 +307,7 @@ class CartController < ActionController::Base
303
307
  @articles = @current_user.articles
304
308
  end
305
309
 
306
- # 指定 account_name,可以使用任意微信账户
310
+ # 指定 account_name 可以使用任意微信账户
307
311
  # wechat_oauth2('snsapi_base', nil, account_name) do |openid|
308
312
  # ...
309
313
  # end
@@ -327,27 +331,27 @@ class WechatsController < ActionController::Base
327
331
  end
328
332
  ```
329
333
 
330
- `wechat_oauth2`封装了OAuth2.0验证接口和cookie处理逻辑,用户仅需提供业务代码块即可。userid指的是微信企业成员UserID,openid是关注该公众号的用户openid。
334
+ `wechat_oauth2 `封装了 OAuth2.0 验证接口和 Cookies 处理逻辑,用户仅需提供业务代码块即可。userid 指的是微信企业成员 userid,openid 是关注该公众号的用户 openid。
331
335
 
332
336
  注意:
333
337
  * 如果使用 `wechat_responder`, 请不要在 Controller 里定义 `show` 和 `create` 方法, 否则会报错。
334
- * 如果遇到“redirect_uri参数错误”的错误信息,请登录服务号管理后台,查看“开发者中心/网页服务/网页授权获取用户基本信息”的授权回调页面域名已正确配置。
338
+ * 如果遇到“ redirect_uri 参数错误”的错误信息,请登录服务号管理后台,查看“开发者中心/网页服务/网页授权获取用户基本信息”的授权回调页面域名已正确配置。
335
339
 
336
340
  ## 关于接口权限
337
341
 
338
- wechat gems 内部不会检查权限。但因公众号类型不同,和微信服务器端通讯时,可能会被拒绝,详细权限控制可参考[官方文档](https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433401084)。
342
+ Wechat Gem 内部不会检查权限, 但因公众号类型不同和微信服务器端通讯时,可能会被拒绝详细权限控制可参考[官方文档](https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433401084)。
339
343
 
340
344
  ## 使用命令行
341
345
 
342
- 根据企业微信和微信公众平台配置不同,wechat提供了的命令行命令。
346
+ 根据企业微信和微信公众平台配置不同 Wechat 提供了的命令行命令。
343
347
 
344
348
  #### 微信公众平台命令行
345
349
 
346
350
  ```
347
351
  $ wechat
348
352
  Wechat Public Account commands:
349
- wechat addvoicetorecofortext [VOICE_ID] # AI开放接口-提交语音
350
- wechat callbackip # 获取微信服务器IP地址
353
+ wechat addvoicetorecofortext [VOICE_ID] # AI 开放接口 - 提交语音
354
+ wechat callbackip # 获取微信服务器 iP 地址
351
355
  wechat clear_quota # 接口调用次数清零
352
356
  wechat custom_image [OPENID, IMAGE_PATH] # 发送图片客服消息
353
357
  wechat custom_music [OPENID, THUMBNAIL_PATH, MUSIC_URL] # 发送音乐客服消息
@@ -360,8 +364,9 @@ Wechat Public Account commands:
360
364
  wechat group_delete [GROUP_ID] # 删除分组
361
365
  wechat group_update [GROUP_ID, NEW_GROUP_NAME] # 修改分组名
362
366
  wechat groups # 查询所有分组
363
- wechat material_get [MEDIA_ID, PATH] # 永久媒体下载
367
+ wechat material_get [MEDIA_ID, PATH] # 永久媒体下载
364
368
  wechat material_add [MEDIA_TYPE, PATH] # 永久媒体上传
369
+ wechat material_add_news [MPNEWS_YAML_PATH] # 永久图文素材上传
365
370
  wechat material_count # 获取永久素材总数
366
371
  wechat material_delete [MEDIA_ID] # 删除永久素材
367
372
  wechat material_list [TYPE, OFFSET, COUNT] # 获取永久素材列表
@@ -381,7 +386,7 @@ Wechat Public Account commands:
381
386
  wechat message_mass_preview [WX_NAME, MPNEWS_MEDIA_ID] # 预览图文消息素材
382
387
  wechat qrcode_create_limit_scene [SCENE_ID_OR_STR] # 请求永久二维码
383
388
  wechat qrcode_create_scene [SCENE_ID_OR_STR, EXPIRE_SECONDS] # 请求临时二维码
384
- wechat qrcode_download [TICKET, QR_CODE_PIC_PATH] # 通过ticket下载二维码
389
+ wechat qrcode_download [TICKET, QR_CODE_PIC_PATH] # 通过 ticket 下载二维码
385
390
  wechat queryrecoresultfortext [VOICE_ID] # AI开放接口-获取语音识别结果
386
391
  wechat shorturl [LONG_URL] # 长链接转短链接
387
392
  wechat tag [TAGID] # 获取标签下粉丝列表
@@ -413,10 +418,10 @@ Wechat Enterprise Account commands:
413
418
  wechat batch_replaceparty [BATCH_PARTY_CSV_MEDIA_ID] # 全量覆盖部门
414
419
  wechat batch_replaceuser [BATCH_USER_CSV_MEDIA_ID] # 全量覆盖成员
415
420
  wechat batch_syncuser [SYNC_USER_CSV_MEDIA_ID] # 增量更新成员
416
- wechat callbackip # 获取微信服务器IP地址
421
+ wechat callbackip # 获取微信服务器 iP 地址
417
422
  wechat clear_quota # 接口调用次数清零
418
- wechat convert_to_openid [USER_ID] # userid转换成openid
419
- wechat convert_to_userid [OPENID] # openid转换成userid
423
+ wechat convert_to_openid [USER_ID] # userid 转换成 openid
424
+ wechat convert_to_userid [OPENID] # openid 转换成 userid
420
425
  wechat custom_image [OPENID, IMAGE_PATH] # 发送图片客服消息
421
426
  wechat custom_music [OPENID, THUMBNAIL_PATH, MUSIC_URL] # 发送音乐客服消息
422
427
  wechat custom_news [OPENID, NEWS_YAML_PATH] # 发送图文客服消息
@@ -473,7 +478,7 @@ Wechat Enterprise Account commands:
473
478
  ### 使用场景
474
479
  以下是几种典型场景的使用方法
475
480
 
476
- #####获取所有用户的OPENID
481
+ ##### 获取所有用户的 openid
477
482
 
478
483
  ```
479
484
  $ wechat users
@@ -482,7 +487,7 @@ $ wechat users
482
487
 
483
488
  ```
484
489
 
485
- #####获取用户的信息
490
+ ##### 获取用户的信息
486
491
 
487
492
  ```
488
493
  $ wechat user "oCfEht9***********"
@@ -502,7 +507,7 @@ $ wechat menu
502
507
  ##### 创建菜单
503
508
 
504
509
 
505
- 通过运行`rails g wechat:menu`可以生成一个定义菜单内容的yaml文件,菜单可以包含下列内容:
510
+ 通过运行`rails g wechat:menu`可以生成一个定义菜单内容的 yaml 文件菜单可以包含下列内容:
506
511
 
507
512
  ```
508
513
  button:
@@ -546,17 +551,17 @@ button:
546
551
  $ wechat menu_create menu.yaml
547
552
  ```
548
553
 
549
- 需确保设置,权限管理中有对此应用的管理权限,否则会报[60011](http://qydev.weixin.qq.com/wiki/index.php?title=%E5%85%A8%E5%B1%80%E8%BF%94%E5%9B%9E%E7%A0%81%E8%AF%B4%E6%98%8E)错。
554
+ 需确保设置,权限管理中有对此应用的管理权限,否则会报 [60011](http://qydev.weixin.qq.com/wiki/index.php?title=%E5%85%A8%E5%B1%80%E8%BF%94%E5%9B%9E%E7%A0%81%E8%AF%B4%E6%98%8E) 错。
550
555
 
551
556
  ##### 发送客服图文消息
552
- 需定义一个图文消息内容的yaml文件,比如
557
+ 需定义一个图文消息内容的 yaml 文件,比如
553
558
  articles.yaml
554
559
 
555
560
  ```
556
561
  articles:
557
562
  -
558
563
  title: "习近平在布鲁日欧洲学院演讲"
559
- description: "新华网比利时布鲁日4月1日电 国家主席习近平1日在比利时布鲁日欧洲学院发表重要演讲"
564
+ description: "新华网比利时布鲁日 4 1 日电 国家主席习近平 1 日在比利时布鲁日欧洲学院发表重要演讲"
560
565
  url: "http://news.sina.com.cn/c/2014-04-01/232629843387.shtml"
561
566
  pic_url: "http://i3.sinaimg.cn/dy/c/2014-04-01/1396366518_bYays1.jpg"
562
567
  ```
@@ -569,7 +574,7 @@ $ wechat custom_news oCfEht9oM*********** articles.yml
569
574
  ```
570
575
 
571
576
  ##### 发送模板消息
572
- 需定义一个模板消息内容的yaml文件,比如
577
+ 需定义一个模板消息内容的 yaml 文件,比如
573
578
  template.yml
574
579
 
575
580
  ```
@@ -585,10 +590,10 @@ template:
585
590
  value: "XX活动"
586
591
  color: "#CCCCCC"
587
592
  keynote2:
588
- value: "2014年9月16日"
593
+ value: "2014 9 16 日"
589
594
  color: "#CCCCCC"
590
595
  keynote3:
591
- value: "上海徐家汇xxx城"
596
+ value: "上海徐家汇 xxx 城"
592
597
  color: "#CCCCCC"
593
598
  remark:
594
599
  value: "欢迎再次使用。"
@@ -609,7 +614,7 @@ template = YAML.load(File.read(template_yaml_path))
609
614
  Wechat.api.template_message_send Wechat::Message.to(openid).template(template['template'])
610
615
  ```
611
616
 
612
- 若在Controller中使用wechat_api或者wechat_responder,可以使用wechat:
617
+ 若在 Controller 中使用 wechat_api 或者 wechat_responder,可以使用 wechat:
613
618
 
614
619
  ```ruby
615
620
  template = YAML.load(File.read(template_yaml_path))
@@ -618,7 +623,7 @@ wechat.template_message_send Wechat::Message.to(openid).template(template['templ
618
623
 
619
624
  ## wechat_api - Rails Controller Wechat API
620
625
 
621
- 虽然用户可以随时通过`Wechat.api`在任意代码中访问wechat的API功能,但是更推荐的做法是仅在controller中,通过引入`wechat_api`,使用`wechat`调用API功能,不仅因为这样是支持多个微信公众平台账号的必然要求,而且也避免了在模型层内过多引入微信相关代码。
626
+ 虽然用户可以随时通过 `Wechat.api` 在任意代码中访问 Wechat API 功能,但是更推荐的做法是仅在 Controller 中,通过引入 `wechat_api`,使用 `wechat` 调用 API 功能,不仅因为这样是支持多个微信公众平台账号的必然要求,而且也避免了在模型层内过多引入微信相关代码。
622
627
 
623
628
  ```ruby
624
629
  class WechatReportsController < ApplicationController
@@ -631,11 +636,11 @@ class WechatReportsController < ApplicationController
631
636
  end
632
637
  ```
633
638
 
634
- ## 在ActiveJob/Rake tasks中调用有wechat api
639
+ ## 在 ActiveJob/Rake tasks 中调用有 wechat api
635
640
 
636
- 可以通过`Wechat.api`在任意地方使用wechat api的功能。
641
+ 可以通过 `Wechat.api` 在任意地方使用 Wechat Api 的功能。
637
642
 
638
- 下面以通过`rails console`调用微信AI开放接口的语音识别为例:
643
+ 下面以通过 `rails console` 调用微信 Ai 开放接口的语音识别为例:
639
644
 
640
645
  ```bash
641
646
  # Audio file with ID3 version 2.4.0, contains:MPEG ADTS, layer III, v2, 40 kbps, 16 kHz, Monaural
@@ -646,24 +651,24 @@ Wechat.api.queryrecoresultfortext 'test_voice_id'
646
651
 
647
652
  ## wechat_responder - Rails Responder Controller DSL
648
653
 
649
- 为了在Rails app中响应用户的消息,开发者需要创建一个wechat responder controller. 首先在router中定义
654
+ 为了在 Rails App 中响应用户的消息,开发者需要创建一个 wechat responder Controller 首先在 Router 中定义
650
655
 
651
656
  ```ruby
652
657
  resource :wechat, only:[:show, :create]
653
658
  ```
654
659
 
655
- 然后创建Controller class, 例如
660
+ 然后创建 Controller Class 例如
656
661
 
657
662
  ```ruby
658
663
  class WechatsController < ActionController::Base
659
664
  wechat_responder
660
665
 
661
- # 默认文字信息responder
666
+ # 默认文字信息 responder
662
667
  on :text do |request, content|
663
668
  request.reply.text "echo: #{content}" #Just echo
664
669
  end
665
670
 
666
- # 当请求的文字信息内容为'help'时, 使用这个responder处理
671
+ # 当请求的文字信息内容为 'help' 时, 使用这个 responder 处理
667
672
  on :text, with: 'help' do |request|
668
673
  request.reply.text 'help content' #回复帮助信息
669
674
  end
@@ -682,29 +687,29 @@ class WechatsController < ActionController::Base
682
687
  request.reply.text "User #{request[:FromUserName]} subscribe now"
683
688
  end
684
689
 
685
- # 公众平台收到未关注用户扫描qrscene_xxxxxx二维码时。注意此次扫描事件将不再引发上条的用户加关注事件
690
+ # 公众平台收到未关注用户扫描 qrscene_xxxxxx 二维码时。注意此次扫描事件将不再引发上条的用户加关注事件
686
691
  on :scan, with: 'qrscene_xxxxxx' do |request, ticket|
687
692
  request.reply.text "Unsubscribe user #{request[:FromUserName]} Ticket #{ticket}"
688
693
  end
689
694
 
690
- # 公众平台收到已关注用户扫描创建二维码的scene_id事件时
695
+ # 公众平台收到已关注用户扫描创建二维码的 scene_id 事件时
691
696
  on :scan, with: 'scene_id' do |request, ticket|
692
697
  request.reply.text "Subscribe user #{request[:FromUserName]} Ticket #{ticket}"
693
698
  end
694
699
 
695
- # 当没有任何on :scan事件处理已关注用户扫描的scene_id时
700
+ # 当没有任何 on :scan 事件处理已关注用户扫描的 scene_id
696
701
  on :event, with: 'scan' do |request|
697
702
  if request[:EventKey].present?
698
703
  request.reply.text "event scan got EventKey #{request[:EventKey]} Ticket #{request[:Ticket]}"
699
704
  end
700
705
  end
701
706
 
702
- # 企业微信收到EventKey 为二维码扫描结果事件时
707
+ # 企业微信收到 EventKey 为二维码扫描结果事件时
703
708
  on :scan, with: 'BINDING_QR_CODE' do |request, scan_result, scan_type|
704
709
  request.reply.text "User #{request[:FromUserName]} ScanResult #{scan_result} ScanType #{scan_type}"
705
710
  end
706
711
 
707
- # 企业微信收到EventKey 为CODE 39码扫描结果事件时
712
+ # 企业微信收到 EventKey 为 CODE 39 码扫描结果事件时
708
713
  on :scan, with: 'BINDING_BARCODE' do |message, scan_result|
709
714
  if scan_result.start_with? 'CODE_39,'
710
715
  message.reply.text "User: #{message[:FromUserName]} scan barcode, result is #{scan_result.split(',')[1]}"
@@ -732,14 +737,14 @@ class WechatsController < ActionController::Base
732
737
  # request.reply.voice(request[:MediaId])
733
738
 
734
739
  voice_id = request[:MediaId]
735
- # 开通语音识别后,用户每次发送语音给服务号时,微信会在推送的语音消息XML数据包中,增加一个Recognition字段
740
+ # 开通语音识别后,用户每次发送语音给服务号时,微信会在推送的语音消息XML数据包中,增加一个 Recognition 字段
736
741
  recognition = request[:Recognition]
737
742
  request.reply.text "#{voice_id} #{recognition}"
738
743
  end
739
744
 
740
745
  # 处理视频信息
741
746
  on :video do |request|
742
- nickname = wechat.user(request[:FromUserName])['nickname'] #调用 api 获得发送者的nickname
747
+ nickname = wechat.user(request[:FromUserName])['nickname'] #调用 api 获得发送者的 nickname
743
748
  request.reply.video(request[:MediaId], title: '回声', description: "#{nickname}发来的视频请求") #直接视频返回给用户
744
749
  end
745
750
 
@@ -789,12 +794,12 @@ class WechatsController < ActionController::Base
789
794
  request.reply.success # request is XML result hash.
790
795
  end
791
796
 
792
- # 当无任何responder处理用户信息时,使用这个responder处理
797
+ # 当无任何 responder 处理用户信息时,使用这个 responder 处理
793
798
  on :fallback, respond: 'fallback message'
794
799
  end
795
800
  ```
796
801
 
797
- 在controller中使用`wechat_responder`引入Responder DSL, 之后可以用
802
+ controller 中使用 `wechat_responder` 引入 Responder DSL, 之后可以用
798
803
 
799
804
  ```
800
805
  on <message_type> do |message|
@@ -804,18 +809,18 @@ end
804
809
 
805
810
  来响应用户信息。
806
811
 
807
- 目前支持的message_type有如下几种
812
+ 目前支持的 message_type 有如下几种
808
813
 
809
- - :text 响应文字消息,可以用`:with`参数来匹配文本内容 `on(:text, with:'help'){|message, content| ...}`
814
+ - :text 响应文字消息,可以用 `:with` 参数来匹配文本内容 `on(:text, with:'help'){|message, content| ...}`
810
815
  - :image 响应图片消息
811
816
  - :voice 响应语音消息
812
817
  - :shortvideo 响应短视频消息
813
818
  - :video 响应视频消息
814
819
  - :label_location 响应地理位置消息
815
820
  - :link 响应链接消息
816
- - :event 响应事件消息, 可以用`:with`参数来匹配事件类型,同文字消息类似,支持正则表达式匹配
817
- - :click 虚拟响应事件消息, 微信传入:event,但gem内部会单独处理
818
- - :view 虚拟响应事件消息, 微信传入:event,但gem内部会单独处理
821
+ - :event 响应事件消息, 可以用 `:with` 参数来匹配事件类型,同文字消息类似,支持正则表达式匹配
822
+ - :click 虚拟响应事件消息, 微信传入:event,但 gem 内部会单独处理
823
+ - :view 虚拟响应事件消息, 微信传入:event,但 gem 内部会单独处理
819
824
  - :scan 虚拟响应事件消息
820
825
  - :batch_job 虚拟响应事件消息
821
826
  - :location 虚拟响应上报地理位置事件消息
@@ -832,13 +837,13 @@ class WechatsController < ActionController::Base
832
837
  end
833
838
  ```
834
839
 
835
- 注意设置了[多客服消息转发](http://dkf.qq.com/)后,不能再添加`默认文字信息responder`,否则文字消息将得不到转发。
840
+ 注意设置了[多客服消息转发](http://dkf.qq.com/)后,不能再添加默认文字信息 `responder`,否则文字消息将得不到转发。
836
841
 
837
842
  ### 通知
838
843
 
839
844
  现支持以下通知:
840
845
 
841
- * `wechat.responder.after_create` data 包含 request<Wechat::Message> 和 response<Wechat::Message>
846
+ * `wechat.responder.after_create` data 包含 request <Wechat::Message> 和 response<Wechat::Message>
842
847
 
843
848
  使用示例:
844
849
 
@@ -850,6 +855,6 @@ end
850
855
 
851
856
  ## 已知问题
852
857
 
853
- * 企业微信接受菜单消息时,Wechat腾讯服务器无法解析部分域名,请使用IP绑定回调URL,用户的普通消息目前不受影响。
854
- * 企业微信全量覆盖成员使用的csv通讯录格式,直接将下载的模板导入[是不工作的](http://qydev.weixin.qq.com/qa/index.php?qa=13978),必须使用Excel打开,然后另存为csv格式才会变成合法格式。
855
- * 如果使用nginx+unicron部署方案,并且使用了https,必须设置`trusted_domain_fullname`为https,否则会导致JS-SDK签名失效。
858
+ * 企业微信接受菜单消息时,Wechat 腾讯服务器无法解析部分域名,请使用 iP 绑定回调 URL,用户的普通消息目前不受影响。
859
+ * 企业微信全量覆盖成员使用的 CSV 通讯录格式,直接将下载的模板导入[是不工作的](http://qydev.weixin.qq.com/qa/index.php?qa=13978),必须使用 Excel 打开,然后另存为 CSV 格式才会变成合法格式。
860
+ * 如果使用 Nginx + Unicron 部署方案,并且使用了 Https,必须设置 `trusted_domain_fullname` 为 Https,否则会导致 JS-SDK 签名失效。