wechat 0.12.4 → 0.13.0

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: 761a53485d1170176263ef051a032606c7ae1c5533c6ec9c3f4808a4aeb5cd66
4
- data.tar.gz: be822b26ee8bc46bcc548190d8f7082e0424d9214ed88a26e3846be39c7fcde2
3
+ metadata.gz: 983ca9ebf1007ad2f68e079d7ed625c59a10e78198992abf84a5b9718592ff26
4
+ data.tar.gz: 976751bb11aba9a0fa30674a39eaef432eb39c177a315b396d95c458c0afde45
5
5
  SHA512:
6
- metadata.gz: 261f379c71351cf41d93e4bc3953c66f62d11c2f136111f2642379e78cde736e2e2667817c71f3001fec80d4432f83dcde2f4ac5d6f380b67daa55d6477252e4
7
- data.tar.gz: b57190737963d214a9e644334ead4af99e68b774b3973f49ae652f6576b8aeb248407062e0ffc0fbb3ac86347b81b6b90942b632090eef6729ce6dc98504f4fe
6
+ metadata.gz: aeee17ba746530fbab18470172d83df90ff995ebdfa9ec92866361bbeacda03848e11a8ea278db6544ea57774513754b2dd914e7891154ca1344a03f8c5c4288
7
+ data.tar.gz: c22640b41f4d4d2d2cc01b7dd3568c76d6896f976d79f3d65c2ffb9dff975cb7ed6e0463b62b1f2991b6ec80494f96e263a3d330ee5661446dec7a075e063fc7
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGELOG.md CHANGED
@@ -1,405 +1,8 @@
1
1
  # Changelog
2
2
 
3
- ## v0.12.4 (released at 4/21/2021)
3
+ ## v0.13.0 (released at 3/3/2021)
4
4
 
5
- * New material_add_news API, by @zlei1 #300
6
- * Support open_tag, by @xiajian2019 #299
5
+ * Support zeitwerk only and Rails 6+ only.
6
+ * Support Ruby 2.6+ only.
7
7
 
8
- ## v0.12.3 (released at 3/15/2021)
9
-
10
- * Fix MpApi initialize bug, by @hardywu #296
11
-
12
- ## v0.12.2 (released at 3/3/2021)
13
-
14
- * New convert_to_userid API
15
-
16
- ## v0.12.1 (released at 28/12/2020)
17
-
18
- * Support Ruby 3.0.
19
- * Qcloud_token support.
20
- * CRUD of tencent cloud DB for miniapp
21
- * TCB storage API support.
22
- * Set default branch to *main*.
23
-
24
- ## v0.11.11 (released at 09/13/2020)
25
-
26
- * FIX: fix_load_controller_wechat not support MP type, by @Msms-NJ #281
27
-
28
- ## v0.11.10 (released at 09/02/2020)
29
-
30
- * ADD: Wechat::MpApi.wxa_msg_sec_check.
31
-
32
- ## v0.11.9 (released at 04/29/2020)
33
-
34
- * CHG: upgrade ssl_version to 1.2 by @paicha #276
35
-
36
- ## v0.11.8 (released at 03/09/2020)
37
-
38
- * ADD: Wechat::CorpApi.news_message_send
39
- * FIX: Wechat API Change material/get_material. reported by @0000sir #275
40
-
41
- ## v0.11.7 (released at 11/15/2019)
42
-
43
- * ADD: Wechat::MpApi.subscribe_message_send. by @paicha #271
44
- * FIX: FrozenError: can't modify frozen String. by @paicha #272
45
- * New translatecontent support.
46
-
47
- ## v0.11.6 (released at 09/02/2019)
48
-
49
- * Fix private method `next_migration_number` introduced at #267, by @zpdsky #270
50
- * Give more clear warning about missing Rails in console. by @emtfe #268
51
-
52
- ## v0.11.5 (released at 08/30/2019)
53
-
54
- * Add rubocop check in CI by @hophacker #267
55
- * Support Rails 6 and Windows at #266
56
-
57
- ## v0.11.4 (released at 08/15/2019)
58
-
59
- * rails 6 redirect_to use allow_other_host: true by @Chen-George-Zhen #263
60
-
61
- ## v0.11.3 (released at 07/02/2019)
62
-
63
- * New addvoicetorecofortext and queryrecoresultfortext support.
64
- * improve existing class detect by @3014zhangshuo #261
65
- * new wxa_get_wxacode_unlimit API for miniapp by @paicha #260
66
-
67
- ## v0.11.2 (released at 05/08/2019)
68
-
69
- * bugfix short_url to shorturl in wechat console tool by @yuanxinyu #259
70
- * allow a message to be sent to a party (department) by @hophacker #256
71
-
72
- ## v0.11.1 (released at 03/01/2019)
73
-
74
- * Let Message support markdown, text included; allow textcard btntxt to be omitted by @hophacker #251
75
- * Enterprise account add checkin api by @hophacker #254
76
- * Suggest use secret to differentiate different acces_tokens and tickets in Enterprise account by @hophacker #255
77
-
78
-
79
- ## v0.11.0 (released at 01/22/2019)
80
-
81
- * Support Ruby 2.6.0 official
82
- * Bump http gem to 4.0
83
- * New clear quota API by @3014zhangshuo #244
84
- * Wechat::Message support textcard by @hophacker #249
85
- * New getusersummary and getusercumulate API #247
86
-
87
- ## v0.10.3 (released at 10/07/2018)
88
-
89
- * Fix new share problem in iOS by @killernova #242
90
-
91
- ## v0.10.2 (released at 8/27/2018)
92
-
93
- * Fix incompatible with Rails 5.2.1 by @chloerei #239
94
-
95
- ## v0.10.1 (released at 7/1/2018)
96
-
97
- * Allow custom_message_send using Hash as message, previous only allow Wechat::Message. by @zuoliang0 and @fogisland #234
98
-
99
- ## v0.10.0 (released at 5/31/2018)
100
-
101
- * Support multi wechat account at wechat_responder. by @tuliren #223
102
- * Support wechat mini program apis & signature check. by @oiahoon #225
103
- * Support sent template message with miniprogram. by @falm #228
104
- * Fix request_content could be nil. by @paicha #229
105
-
106
- ## v0.9.0 (released at 4/15/2018)
107
-
108
- * Support multi wechat account dynamically loading from DB. by @tuliren #222
109
- * user_create API for enterprise account. #206
110
- * Will ignore template_message_send error 43004 by @insub #214
111
- * using template with version if the migration version available by @killernova #220
112
- * Remove Deprecation oauth2_url
113
- * Remove Ruby 2.2 support, add Rails 5.2 and http v3 support
114
-
115
- ## v0.8.12 (released at 9/13/2017)
116
-
117
- * Read oauth2_state from ticket store every time to avoid invalid oauth2_state by @xiewenwei #196
118
-
119
- ## v0.8.11 (released at 7/25/2017)
120
-
121
- * oauth2 state code not refresh at the same time of jsapi tickets refresh bug, many thanks @xiewenwei #192
122
- * Add string type scene support for qrcode_create_scene. by @libuchao #191
123
-
124
- ## v0.8.10 (released at 6/19/2017)
125
-
126
- * fix material_delete correctly.
127
-
128
- ## v0.8.9 (released at 6/18/2017)
129
-
130
- * wechat material_delete failed to work, thanks @Victorialice report #78
131
-
132
- ## v0.8.8 (released at 5/18/2017)
133
-
134
- * Better support multiple account. by @xiewenwei #187
135
- * Allow load figaro via RAILS_ENV. by @goofansu #186
136
-
137
- ## v0.8.7 (released at 4/23/2017)
138
-
139
- * Support new wxa_get_wxacode API for miniapp.
140
- * Add InvalidCredentialError, support audio/amr, voice/speex as file and text/plain as json. by @acenqiu #184
141
-
142
- ## v0.8.6 (released at 3/17/2017)
143
-
144
- * Support Rails 5.1 officially.
145
- * make sure the formfile can be created outside. by @mechiland #181
146
-
147
- ## v0.8.5 (released at 3/14/2017)
148
-
149
- * Support mass send API #176
150
- * Support new media_hq API
151
- * Support new createwxaqrcode API for miniapp
152
- * Fix wechat_responder not proper injected in rails 5 API #165
153
- * parse response support XML return, by @zhangbin #167
154
- * WeChat only allow 8 article per one news, by @kikyous #175
155
- * Store token at cookies, by @jstdoit #174
156
-
157
- ## v0.8.4 (released at 1/12/2017)
158
-
159
- * Support Ruby 2.4.0
160
- * Add support of Enterprise RedPacket API, by @zhangbin #169
161
-
162
- ## v0.8.3 (released at 11/26/2016)
163
-
164
- * Fix wechat template key has camelCase problem, by @RyanChenDji #159
165
- * Fix long time of oauth2_state bug for wechat_oauth2 methods, by @IvanChou #162
166
-
167
- ## v0.8.2 (released at 11/2/2016)
168
-
169
- * Bug which if not using multi-account but using web login.
170
-
171
- ## v0.8.1 (released at 11/2/2016)
172
-
173
- * After allow sub controller using wechat_api, it's possible not initialise at first time. by @IvanChou #155
174
- * Support web application login scope snsapi_login.
175
- * Add unionid support for public account.
176
- * Remove OpenId in Enterprise OAuth2 as it's not supported by Tecent.
177
-
178
- ## v0.8.0 (released at 10/24/2016)
179
-
180
- * Complete support multi-wechat public account. by @xiewenwei #150
181
- * Support loading configure value from Figaro if application.yml exist.
182
-
183
- ## v0.7.20 (released at 8/29/2016)
184
-
185
- * Apply opt and config together when loading controller_wechat, to simplify wechat_responder params. by @bzhang443 #147
186
-
187
- ## v0.7.19 (released at 8/25/2016)
188
-
189
- * Enterprise account now custom_image/voice/file works now. by @zymiboxpay #145
190
- * Fix timeout setting no effective since introduct HTTP. found by @hsluo #74
191
-
192
- ## v0.7.18 (released at 8/21/2016)
193
-
194
- * Support label_location message, similar to location event, but sent by user with Label. #144
195
- * Add gem signature as additional security methods.
196
-
197
- ## v0.7.17 (released at 8/18/2016)
198
-
199
- * Allow declare wechat_api at ApplicationController, but using wechat at sub controller. #104
200
-
201
- ## v0.7.16 (released at 7/27/2016)
202
-
203
- * FIX: consider '' in params as equal with nil, in ControllerApi#wechat_public_oauth2, by @snow #135
204
- * New tag API for public account, by @pynixwang #127
205
- * fix SSLv3 error by use TLSv1_client, by @IvanChou #133
206
-
207
- ## v0.7.15 (released at 7/03/2016)
208
-
209
- * RSpec testing case on Rails 5 now.
210
- * Resolve Rails 5 ActionController::Parameters issue.
211
-
212
- ## v0.7.14 (released at 5/29/2016)
213
-
214
- * Fix when access_token failed lead ticket can not refresh problem.
215
- * Default duration should be 1 hours instead of 0 seconds for wechat_oauth2.
216
- * New shorturl allowing convert from long URL to short.
217
-
218
- ## v0.7.13 (released at 5/14/2016)
219
-
220
- * Wechat.config.oauth2_cookie_duration need convert to secondes, found by @gabrieltong #111
221
-
222
- ## v0.7.12 (released at 5/12/2016)
223
-
224
- * Fix web_userinfo wrong URL, found by @gabrieltong #110
225
-
226
- ## v0.7.11 (released at 4/18/2016)
227
-
228
- * To cover wrong release 0.7.10, nothing change
229
-
230
- ## v0.7.10 (released at 4/18/2016) (yanked)
231
-
232
- ## v0.7.9 (released at 4/12/2016)
233
-
234
- * wechat_oauth2 support public account now.
235
- * Refresh and store state on jsapi ticket, using it on oauth2_url to more secure.
236
- * Remove extra sending payload in message template send json
237
- * Allow setting oauth2_cookie_duration in config
238
-
239
- ## v0.7.8 (released at 3/31/2016)
240
-
241
- * New wechat_api, similar to wechat_responder, but without messange handle DSL, support web page only wechat application
242
- * New media_uploadimg API.
243
- * New file type of Message.
244
- * Improved multi account support per different controller.
245
-
246
- ## v0.7.7 (released at 3/18/2016)
247
-
248
- * New wechat_oauth2, only support enterprise account still.
249
- * fix 'skip_before_action :verify_authenticity_token' bug for v5.0.0.beta3 by @vkill #97
250
- * Support Rails 3.2 again after support Rails 5.0, by @guange2015 #96
251
-
252
- ## v0.7.6 (released at 3/05/2016)
253
-
254
- * Support wechat public account conditional menu. #95
255
-
256
- ## v0.7.5 (released at 2/21/2016)
257
-
258
- * New wechat_config_js to simplify the Wechat jsapi config.
259
- * Support sent shortvideo.
260
-
261
- ## v0.7.4 (released at 1/23/2016)
262
-
263
- * Add Redis store token/ticket support, close #76, #60
264
- * Rails 5 support without deprecate warning or other not necessory call. #82
265
-
266
- ## v0.7.3 (released at 1/19/2016)
267
-
268
- * Allow transfer_customer_service to specific account.
269
- * New customservice_getonlinekflist API.
270
- * session support class WechatSession no need table_exists? methods exist.
271
-
272
- ## v0.7.2 (released at 1/18/2016)
273
-
274
- * Optional session support by @zfben #81, #88, #91
275
- * Replace after_wechat_response with Rails Nofications facility, by @zfben, original issue is #79
276
- * New user_batchget API. #89
277
- * Support Rails 3.2 again after support Rails 5.0. by @guange2015 #87
278
- * Fetch setting from RAILS_ENV first, then fetch default. by @kikyous #85
279
- * Warning not support on :scan with regular expression, reason see #84
280
-
281
- ## v0.7.1 (released at 1/11/2016)
282
-
283
- * Fix after using http, upload file function break. #78
284
- * Add callback function after_wechat_response support. by @zfben #79
285
- * Should using department_id instead of departmentid at enterprise api: user_simplelist/user_list.
286
-
287
- ## v0.7.0 (released at 1/1/2016)
288
-
289
- * Using [http](https://github.com/httprb/http) instead of rest-client for performance reason. (not support upload file yet)
290
-
291
- ## v0.6.10 (released at 1/17/2016)
292
-
293
- * Support Rails 3.2 again after support Rails 5.0. by @guange2015 #87
294
- * Fetch setting from RAILS_ENV first, then fetch default. by @kikyous #85
295
- * Warning not support on :scan with regular expression. by @kikyous #84
296
-
297
- ## v0.6.9 (released at 1/6/2016)
298
-
299
- * Fix token refresh bug on multi worker. #76
300
- * Rewrite the token relative code to add more storage support in future.
301
-
302
- ## v0.6.8 (released at 12/25/2015)
303
-
304
- * Support Rails 5.0.0.beta1.
305
- * English README available
306
- * Fix oauth2_url calling error, fix #75
307
-
308
- ## v0.6.7 (released at 12/18/2015)
309
-
310
- * Add timeout configuration option, close #74
311
- * New getuserinfo and oauth2_url to support getting FromUserName from web page.
312
-
313
- ## v0.6.6 (released at 12/15/2015)
314
-
315
- * Add jsapi_ticket support for Enterprise Account
316
- * 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.
317
- * New syntax `on :view, with: 'VIEW_URL'` support.
318
- * New command `upload_replaceparty` which combine three sub command to make uploading department easier.
319
- * New command `upload_replaceuser` which combine three sub command to make uploading user easier.
320
-
321
- ## v0.6.5 (released at 11/24/2015)
322
-
323
- * Handle 48001 error if token is expire/not valid, close #71
324
- * ApiLoader will do config reading and initialize the api instead of spreading the logic.
325
-
326
- ## v0.6.4 (released at 11/16/2015)
327
-
328
- * Command mode now display different command set based on enterprise/public account setting
329
- * Move config logic in command/wechat to ApiLoader class
330
- * Unsubscribe can only reply plain text 'success' #68
331
- * Fix 404 qrcode download problem, by @huangxiangdan #69
332
-
333
- ## v0.6.3 (released at 11/14/2015)
334
-
335
- * Official testing and support public encrypt mode, also fix one cipher bug, many thanks to @hlltc #67
336
- * hlltc report public account FILE_BASE no longer needs, clean code #67
337
- * Media command line reflect recent Tecent json schema change. #67
338
-
339
- ## v0.6.2 (released at 11/05/2015)
340
-
341
- * Tecent report location API changed, so change wechat gems also. #64
342
-
343
- ## v0.6.1 (released at 10/20/2015)
344
-
345
- * Handle 40001, invalid credential, access_token is invalid or not latest hint # 57
346
- * Support at Rails 4.2.1 wechat can not run #58
347
-
348
- ## v0.6.0 (released at 10/08/2015)
349
-
350
- ### Scan and Batch job are BREAK CHANGE!
351
-
352
- * Scan 2D barcode using new syntax `on :scan, with: 'BINDING_QR_CODE' ` instead of `on :event, with: 'BINDING_QR_CODE' ` in previous version #55
353
- Which will fix can not using `on :event, with: "scan" ` problem
354
- * Batch job using new syntax `on :batch_job, with: 'replace_user' `
355
- instead of previous `on :event, with: 'replace_user' `.
356
- * 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.
357
- * Wechat::Responder using Hash for new :client and :batch_job event, avoid time consuming Array match responder
358
- * Fix refresh token not working problem under ruby 2.0.0 #54
359
- * New department_update, user_batchdelete, convert_to_openid API
360
-
361
- ## v0.5.0 (released at 9/25/2015)
362
-
363
- * Only relay on activesupport on run time, so will greatly improve wechat cli startup time
364
- * Add rails generator support `rails g wechat:install`
365
- * Add batch job support for enterprise account like batch create user/department, both API, callback responder and CLI
366
- * Add material management API and CLI
367
- * Add tag API and CLI for enterprise account
368
- * Add QR code scene function for public account
369
-
370
- ## v0.4.2 (released at 9/7/2015)
371
-
372
- * Fix wrong number of arguments at Wechat::Responder.on by using arity #47
373
- * Fix can not access wechat method after using instance level context.
374
- * Fix skip_verify_ssl parameter error.
375
-
376
- ## v0.4.1 (released at 9/6/2015)
377
-
378
- * Limit news articles collection to 10, close #5
379
- * Resolve the conflict with gem "responders" by @seamon #45
380
-
381
- ## v0.4.0 (released at 9/5/2015)
382
-
383
- * Enable the verify SSL for enterprise mode by default, as security is more importent than speed, but still can switch off by configure
384
- * Support scancode_push/scancode_waitmsg event.
385
- * New API method can get wechat server IP list
386
- * New API to query/create department/media/material
387
- * Fix can not read token_file in mingw bug, which introduce at #43
388
-
389
- ## v0.3.0 (released at 8/30/2015)
390
-
391
- * New user group management API
392
- * Allow transfer to customer service on fallback. #42
393
- * Read and write access_token properly using file locking, #43
394
-
395
- ## v0.2.0 (released at 8/27/2015)
396
-
397
- * Add wechat enterprise account support
398
- * Make responder execute in action context, by @lazing #15
399
- * jsapi_ticket support, by @feitian124 #27
400
- * Rename gems to wechat and ambitious to being #1 gems about development wechat. thanks Xiaoning transfer this gem name.
401
- * Original gem `wechat-rails` author skinnyworm trasfer to Eric-Guo as maintainer
402
-
403
- ## v0.1.1
404
-
405
- * Initial release from [wechat-rails](https://github.com/skinnyworm/wechat-rails).
8
+ Previous changelog see https://github.com/Eric-Guo/wechat/blob/master/CHANGELOG_OLD.md
data/README-CN.md CHANGED
@@ -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
  运行下面这行代码来安装:
@@ -362,7 +366,6 @@ Wechat Public Account commands:
362
366
  wechat groups # 查询所有分组
363
367
  wechat material_get [MEDIA_ID, PATH] # 永久媒体下载
364
368
  wechat material_add [MEDIA_TYPE, PATH] # 永久媒体上传
365
- wechat material_add_news [MPNEWS_YAML_PATH] # 永久图文素材上传
366
369
  wechat material_count # 获取永久素材总数
367
370
  wechat material_delete [MEDIA_ID] # 删除永久素材
368
371
  wechat material_list [TYPE, OFFSET, COUNT] # 获取永久素材列表
data/README.md CHANGED
@@ -34,12 +34,16 @@ Use `gem install`
34
34
 
35
35
  ```
36
36
  gem install "wechat"
37
+ # If your ruby version < 2.6
38
+ # gem install wechat -v 0.12.2
37
39
  ```
38
40
 
39
41
  Or add it to your app's `Gemfile`:
40
42
 
41
43
  ```
42
44
  gem 'wechat'
45
+ # If your rails version < 6.0
46
+ # gem 'wechat', '~> 0.12.2'
43
47
  ```
44
48
 
45
49
  Run the following command to install it:
@@ -391,9 +395,8 @@ Wechat Public Account commands:
391
395
  wechat group_delete [GROUP_ID] # 删除分组
392
396
  wechat group_update [GROUP_ID, NEW_GROUP_NAME] # 修改分组名
393
397
  wechat groups # 查询所有分组
394
- wechat material_get [MEDIA_ID, PATH] # 永久媒体下载
398
+ wechat material_get [MEDIA_ID, PATH] # 永久媒体下载
395
399
  wechat material_add [MEDIA_TYPE, PATH] # 永久媒体上传
396
- wechat material_add_news [MPNEWS_YAML_PATH] # 永久图文素材上传
397
400
  wechat material_count # 获取永久素材总数
398
401
  wechat material_delete [MEDIA_ID] # 删除永久素材
399
402
  wechat material_list [TYPE, OFFSET, COUNT] # 获取永久素材列表
data/bin/wechat CHANGED
@@ -6,13 +6,10 @@ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
6
6
  require 'thor'
7
7
  require 'wechat'
8
8
  require 'json'
9
- require 'active_support' # To support Rails 4.2.1, see #17936
10
- require 'active_support/dependencies/autoload'
11
9
  require 'active_support/core_ext'
12
10
  require 'active_support/json'
13
11
  require 'fileutils'
14
12
  require 'yaml'
15
- require 'wechat/api_loader'
16
13
  require 'cgi'
17
14
 
18
15
  class App < Thor
@@ -411,12 +408,6 @@ class App < Thor
411
408
  puts wechat_api.material_add(type, path)
412
409
  end
413
410
 
414
- desc 'material_add_news [MPNEWS_YAML_PATH]', '永久图文素材上传'
415
- def material_add_news(mpnews_yaml_path)
416
- new = YAML.load(File.read(mpnews_yaml_path))
417
- puts wechat_api.material_add_news(Wechat::Message.new(MsgType: 'mpnews').mpnews(new['articles']))
418
- end
419
-
420
411
  desc 'material_delete [MEDIA_ID]', '删除永久素材'
421
412
  def material_delete(media_id)
422
413
  puts wechat_api.material_delete(media_id)
@@ -45,18 +45,17 @@ module ActionController
45
45
 
46
46
  access_token = opts[:access_token] || cfg.access_token
47
47
  jsapi_ticket = opts[:jsapi_ticket] || cfg.jsapi_ticket
48
- qcloud_env = opts[:qcloud_env] || cfg.qcloud_env
49
48
  qcloud_token = opts[:qcloud_token] || cfg.qcloud_token
50
49
 
51
50
  api_type = opts[:type] || cfg.type
52
51
  secret = corpid.present? ? opts[:corpsecret] || cfg.corpsecret : opts[:secret] || cfg.secret
53
52
 
54
- get_wechat_api(api_type, corpid, appid, secret, access_token, agentid, timeout, skip_verify_ssl, jsapi_ticket, qcloud_env, qcloud_token, qcloud_token_lifespan)
53
+ get_wechat_api(api_type, corpid, appid, secret, access_token, agentid, timeout, skip_verify_ssl, jsapi_ticket, qcloud_token, qcloud_token_lifespan)
55
54
  end
56
55
 
57
- def get_wechat_api(api_type, corpid, appid, secret, access_token, agentid, timeout, skip_verify_ssl, jsapi_ticket, qcloud_env, qcloud_token, qcloud_token_lifespan)
56
+ def get_wechat_api(api_type, corpid, appid, secret, access_token, agentid, timeout, skip_verify_ssl, jsapi_ticket, qcloud_token, qcloud_token_lifespan)
58
57
  if api_type && api_type.to_sym == :mp
59
- Wechat::MpApi.new(appid, secret, access_token, timeout, skip_verify_ssl, jsapi_ticket, qcloud_env, qcloud_token, qcloud_token_lifespan)
58
+ Wechat::MpApi.new(appid, secret, access_token, timeout, skip_verify_ssl, jsapi_ticket, qcloud_token, qcloud_token_lifespan)
60
59
  elsif corpid.present?
61
60
  Wechat::CorpApi.new(corpid, secret, access_token, agentid, timeout, skip_verify_ssl, jsapi_ticket)
62
61
  else
@@ -64,15 +63,4 @@ module ActionController
64
63
  end
65
64
  end
66
65
  end
67
-
68
- if defined? Base
69
- class << Base
70
- include WechatResponder
71
- end
72
- end
73
- if defined? API
74
- class << API
75
- include WechatResponder
76
- end
77
- end
78
66
  end
@@ -31,7 +31,7 @@ module Wechat
31
31
  private
32
32
 
33
33
  def migration_version
34
- "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]" if Rails.version >= '5.0.0'
34
+ "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
35
35
  end
36
36
  end
37
37
  end
@@ -31,7 +31,7 @@ module Wechat
31
31
  private
32
32
 
33
33
  def migration_version
34
- "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]" if Rails.version >= '5.0.0'
34
+ "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
35
35
  end
36
36
  end
37
37
  end
data/lib/wechat/api.rb CHANGED
@@ -1,11 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'wechat/api_base'
4
- require 'wechat/http_client'
5
- require 'wechat/token/public_access_token'
6
- require 'wechat/ticket/public_jsapi_ticket'
7
- require 'wechat/concern/common'
8
-
9
3
  module Wechat
10
4
  class Api < ApiBase
11
5
  def initialize(appid, secret, token_file, timeout, skip_verify_ssl, jsapi_ticket_file)
data/lib/wechat/cipher.rb CHANGED
@@ -43,7 +43,7 @@ module Wechat
43
43
  msg = decode_padding(msg)
44
44
  msg_len = msg[16, 4].reverse.unpack1('V')
45
45
  content = msg[20, msg_len]
46
- app_id = msg[(msg_len + 20)..-1]
46
+ app_id = msg[(msg_len + 20)..]
47
47
 
48
48
  [content, app_id]
49
49
  end
@@ -152,10 +152,6 @@ module Wechat
152
152
  post_file 'material/add_material', file, params: { type: type }
153
153
  end
154
154
 
155
- def material_add_news(mpnews_message)
156
- post 'material/add_news', mpnews_message.to_json
157
- end
158
-
159
155
  def material_delete(media_id)
160
156
  post 'material/del_material', JSON.generate(media_id: media_id)
161
157
  end
@@ -58,7 +58,7 @@ module Wechat
58
58
  cookies.signed_or_encrypted[:we_access_token] = { value: access_info['access_token'], expires: self.class.oauth2_cookie_duration.from_now }
59
59
  yield access_info['openid'], access_info
60
60
  else
61
- Rails::VERSION::MAJOR >= 6 ? (redirect_to generate_oauth2_url(oauth2_params), allow_other_host: true) : (redirect_to generate_oauth2_url(oauth2_params))
61
+ redirect_to generate_oauth2_url(oauth2_params), allow_other_host: true
62
62
  end
63
63
  end
64
64
 
@@ -73,7 +73,7 @@ module Wechat
73
73
  cookies.signed_or_encrypted[:we_deviceid] = { value: userinfo['DeviceId'], expires: self.class.oauth2_cookie_duration.from_now }
74
74
  yield userinfo['UserId'], userinfo
75
75
  else
76
- Rails::VERSION::MAJOR >= 6 ? (redirect_to generate_oauth2_url(oauth2_params), allow_other_host: true) : (redirect_to generate_oauth2_url(oauth2_params))
76
+ redirect_to generate_oauth2_url(oauth2_params), allow_other_host: true
77
77
  end
78
78
  end
79
79
 
@@ -1,10 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'wechat/api_base'
4
- require 'wechat/http_client'
5
- require 'wechat/token/corp_access_token'
6
- require 'wechat/ticket/corp_jsapi_ticket'
7
-
8
3
  module Wechat
9
4
  class CorpApi < ApiBase
10
5
  attr_reader :agentid
@@ -34,8 +34,7 @@ module Wechat
34
34
  timestamp: "#{js_hash[:timestamp]}",
35
35
  nonceStr: "#{js_hash[:noncestr]}",
36
36
  signature: "#{js_hash[:signature]}",
37
- jsApiList: ['#{config_options[:api]&.join("','")}'],
38
- openTagList: ['#{config_options[:open_tags]&.join("','")}']
37
+ jsApiList: ['#{config_options[:api].join("','")}']
39
38
  });
40
39
  WECHAT_CONFIG_JS
41
40
  javascript_tag config_js, type: 'application/javascript'
data/lib/wechat/mp_api.rb CHANGED
@@ -1,13 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'wechat/api_base'
4
- require 'wechat/http_client'
5
- require 'wechat/token/public_access_token'
6
- require 'wechat/ticket/public_jsapi_ticket'
7
- require 'wechat/qcloud/token'
8
- require 'wechat/concern/common'
9
- require 'wechat/concern/qcloud'
10
-
11
3
  module Wechat
12
4
  class MpApi < ApiBase
13
5
  def initialize(appid, secret, token_file, timeout, skip_verify_ssl, jsapi_ticket_file, qcloud_env, qcloud_token_file, qcloud_token_lifespan)
@@ -2,7 +2,6 @@
2
2
 
3
3
  require 'English'
4
4
  require 'rexml/document'
5
- require 'wechat/signature'
6
5
 
7
6
  module Wechat
8
7
  module Responder
@@ -11,24 +10,9 @@ module Wechat
11
10
  include Cipher
12
11
 
13
12
  included do
14
- # Rails 5 remove before_filter and skip_before_filter
15
- if respond_to?(:skip_before_action)
16
- if respond_to?(:verify_authenticity_token)
17
- skip_before_action :verify_authenticity_token
18
- else
19
- # Rails 5 API mode won't define verify_authenticity_token
20
- # https://github.com/rails/rails/blob/v5.0.0.beta3/actionpack/lib/abstract_controller/callbacks.rb#L66
21
- # https://github.com/rails/rails/blob/v5.0.0.beta3/activesupport/lib/active_support/callbacks.rb#L640
22
- skip_before_action :verify_authenticity_token, raise: false
23
- end
24
-
25
- before_action :config_account, only: %i[show create]
26
- before_action :verify_signature, only: %i[show create]
27
- else
28
- skip_before_filter :verify_authenticity_token
29
- before_filter :config_account, only: %i[show create]
30
- before_filter :verify_signature, only: %i[show create]
31
- end
13
+ skip_before_action :verify_authenticity_token, raise: false
14
+ before_action :config_account, only: %i[show create]
15
+ before_action :verify_signature, only: %i[show create]
32
16
  end
33
17
 
34
18
  module ClassMethods
@@ -180,15 +164,9 @@ module Wechat
180
164
  def show
181
165
  if @we_corpid.present?
182
166
  echostr, _corp_id = unpack(decrypt(Base64.decode64(params[:echostr]), @we_encoding_aes_key))
183
- if Rails::VERSION::MAJOR >= 4
184
- render plain: echostr
185
- else
186
- render text: echostr
187
- end
188
- elsif Rails::VERSION::MAJOR >= 4
189
- render plain: params[:echostr]
167
+ render plain: echostr
190
168
  else
191
- render text: params[:echostr]
169
+ render plain: params[:echostr]
192
170
  end
193
171
  end
194
172
 
@@ -197,11 +175,7 @@ module Wechat
197
175
  response_msg = run_responder(request_msg)
198
176
 
199
177
  if response_msg.respond_to? :to_xml
200
- if Rails::VERSION::MAJOR >= 4
201
- render plain: process_response(response_msg)
202
- else
203
- render text: process_response(response_msg)
204
- end
178
+ render plain: process_response(response_msg)
205
179
  else
206
180
  head :ok, content_type: 'text/html'
207
181
  end
@@ -248,15 +222,9 @@ module Wechat
248
222
  end
249
223
 
250
224
  data_hash = data.fetch('xml', {})
251
- if Rails::VERSION::MAJOR >= 5
252
- data_hash = data_hash.to_unsafe_hash if data_hash.instance_of?(ActionController::Parameters)
253
- HashWithIndifferentAccess.new(data_hash).tap do |msg|
254
- msg[:Event]&.downcase!
255
- end
256
- else
257
- HashWithIndifferentAccess.new_from_hash_copying_default(data_hash).tap do |msg|
258
- msg[:Event]&.downcase!
259
- end
225
+ data_hash = data_hash.to_unsafe_hash if data_hash.instance_of?(ActionController::Parameters)
226
+ HashWithIndifferentAccess.new(data_hash).tap do |msg|
227
+ msg[:Event]&.downcase!
260
228
  end
261
229
  end
262
230
 
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'wechat/ticket/jsapi_base'
4
-
5
3
  module Wechat
6
4
  module Ticket
7
5
  class CorpJsapiTicket < JsapiBase
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'wechat/ticket/jsapi_base'
4
-
5
3
  module Wechat
6
4
  module Ticket
7
5
  class PublicJsapiTicket < JsapiBase
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'wechat/token/access_token_base'
4
-
5
3
  module Wechat
6
4
  module Token
7
5
  class CorpAccessToken < AccessTokenBase
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'wechat/token/access_token_base'
4
-
5
3
  module Wechat
6
4
  module Token
7
5
  class PublicAccessToken < AccessTokenBase
data/lib/wechat.rb CHANGED
@@ -1,20 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'zeitwerk'
4
+ loader = Zeitwerk::Loader.for_gem
5
+ loader.ignore("#{__dir__}/generators/**/*.rb")
6
+ loader.setup
7
+
3
8
  require 'base64'
4
9
  require 'openssl/cipher'
5
- require 'wechat/api_loader'
6
- require 'wechat/api'
7
- require 'wechat/mp_api'
8
- require 'wechat/corp_api'
9
- require 'wechat/helpers'
10
- require 'action_controller/wechat_responder'
11
10
 
12
11
  module Wechat
13
- autoload :Message, 'wechat/message'
14
- autoload :Responder, 'wechat/responder'
15
- autoload :Cipher, 'wechat/cipher'
16
- autoload :ControllerApi, 'wechat/controller_api'
17
-
18
12
  class AccessTokenExpiredError < StandardError; end
19
13
 
20
14
  class InvalidCredentialError < StandardError; end
@@ -55,3 +49,21 @@ module Wechat
55
49
  end
56
50
 
57
51
  ActionView::Base.include Wechat::Helpers if defined? ActionView::Base
52
+ require 'action_controller/wechat_responder' # To make wechat_api and wechat_responder available
53
+
54
+ module ActionController
55
+ if defined? Base
56
+ ActiveSupport.on_load(:action_controller_base) do
57
+ class << Base
58
+ include WechatResponder
59
+ end
60
+ end
61
+ end
62
+ if defined? API
63
+ ActiveSupport.on_load(:action_controller_api) do
64
+ class << API
65
+ include WechatResponder
66
+ end
67
+ end
68
+ end
69
+ end
data.tar.gz.sig CHANGED
Binary file
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.12.4
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Skinnyworm
@@ -35,7 +35,7 @@ cert_chain:
35
35
  spvOK5/LPXWX6ZGc2SR8SH/s7ftYH2EkeM1VUbtemow08NdgCwJ4IG+fRQ9dcrJ+
36
36
  L9TbpLHvVrCe1w8duMqNeUmqj+M1iC/5Zst2vIe14QcOTuAh
37
37
  -----END CERTIFICATE-----
38
- date: 2021-04-21 00:00:00.000000000 Z
38
+ date: 2021-03-03 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: activesupport
@@ -43,7 +43,7 @@ dependencies:
43
43
  requirements:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
- version: '3.2'
46
+ version: '6.0'
47
47
  - - "<"
48
48
  - !ruby/object:Gem::Version
49
49
  version: '7'
@@ -53,7 +53,7 @@ dependencies:
53
53
  requirements:
54
54
  - - ">="
55
55
  - !ruby/object:Gem::Version
56
- version: '3.2'
56
+ version: '6.0'
57
57
  - - "<"
58
58
  - !ruby/object:Gem::Version
59
59
  version: '7'
@@ -119,48 +119,62 @@ dependencies:
119
119
  - - ">="
120
120
  - !ruby/object:Gem::Version
121
121
  version: '0'
122
+ - !ruby/object:Gem::Dependency
123
+ name: zeitwerk
124
+ requirement: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - "~>"
127
+ - !ruby/object:Gem::Version
128
+ version: '2.4'
129
+ type: :runtime
130
+ prerelease: false
131
+ version_requirements: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - "~>"
134
+ - !ruby/object:Gem::Version
135
+ version: '2.4'
122
136
  - !ruby/object:Gem::Dependency
123
137
  name: rubocop
124
138
  requirement: !ruby/object:Gem::Requirement
125
139
  requirements:
126
140
  - - "~>"
127
141
  - !ruby/object:Gem::Version
128
- version: '1.0'
142
+ version: '1.9'
129
143
  type: :development
130
144
  prerelease: false
131
145
  version_requirements: !ruby/object:Gem::Requirement
132
146
  requirements:
133
147
  - - "~>"
134
148
  - !ruby/object:Gem::Version
135
- version: '1.0'
149
+ version: '1.9'
136
150
  - !ruby/object:Gem::Dependency
137
151
  name: rails
138
152
  requirement: !ruby/object:Gem::Requirement
139
153
  requirements:
140
154
  - - ">="
141
155
  - !ruby/object:Gem::Version
142
- version: '5.1'
156
+ version: '6.0'
143
157
  type: :development
144
158
  prerelease: false
145
159
  version_requirements: !ruby/object:Gem::Requirement
146
160
  requirements:
147
161
  - - ">="
148
162
  - !ruby/object:Gem::Version
149
- version: '5.1'
163
+ version: '6.0'
150
164
  - !ruby/object:Gem::Dependency
151
165
  name: rspec-rails
152
166
  requirement: !ruby/object:Gem::Requirement
153
167
  requirements:
154
168
  - - "~>"
155
169
  - !ruby/object:Gem::Version
156
- version: '5.0'
170
+ version: '4.0'
157
171
  type: :development
158
172
  prerelease: false
159
173
  version_requirements: !ruby/object:Gem::Requirement
160
174
  requirements:
161
175
  - - "~>"
162
176
  - !ruby/object:Gem::Version
163
- version: '5.0'
177
+ version: '4.0'
164
178
  - !ruby/object:Gem::Dependency
165
179
  name: sqlite3
166
180
  requirement: !ruby/object:Gem::Requirement
@@ -237,14 +251,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
237
251
  requirements:
238
252
  - - ">="
239
253
  - !ruby/object:Gem::Version
240
- version: '2.4'
254
+ version: '2.6'
241
255
  required_rubygems_version: !ruby/object:Gem::Requirement
242
256
  requirements:
243
257
  - - ">="
244
258
  - !ruby/object:Gem::Version
245
259
  version: '0'
246
260
  requirements: []
247
- rubygems_version: 3.2.16
261
+ rubygems_version: 3.2.12
248
262
  signing_key:
249
263
  specification_version: 4
250
264
  summary: DSL for wechat message handling and API
metadata.gz.sig CHANGED
Binary file