wechat 0.12.3 → 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: 4f3b96f4a7e2cd18a4a2407f550cf0437fefa8766e26e1356692918932f6441a
4
- data.tar.gz: 024176770cbb290d9fa7039dbb395a6d60d0a64dd6ad20777928771be5feb93d
3
+ metadata.gz: 983ca9ebf1007ad2f68e079d7ed625c59a10e78198992abf84a5b9718592ff26
4
+ data.tar.gz: 976751bb11aba9a0fa30674a39eaef432eb39c177a315b396d95c458c0afde45
5
5
  SHA512:
6
- metadata.gz: 51d9e9ede2d8479c81e9b389e3bcfb3ffcf96a4daee330998d30fcde88cb35f7b36b2cf92754e537720781475105ac59e974047b81bc5c12b462b8a0cf156fa1
7
- data.tar.gz: '09fa4efec1ba2843ac564f1ef97b71728d91439849175767416abf67263916c1214b434ea542d85ccb9b1f45e3d3a9538f4555eebfe6acfd6ee85e77fb18c3a1'
6
+ metadata.gz: aeee17ba746530fbab18470172d83df90ff995ebdfa9ec92866361bbeacda03848e11a8ea278db6544ea57774513754b2dd914e7891154ca1344a03f8c5c4288
7
+ data.tar.gz: c22640b41f4d4d2d2cc01b7dd3568c76d6896f976d79f3d65c2ffb9dff975cb7ed6e0463b62b1f2991b6ec80494f96e263a3d330ee5661446dec7a075e063fc7
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/CHANGELOG.md CHANGED
@@ -1,400 +1,8 @@
1
1
  # Changelog
2
2
 
3
- ## v0.12.3 (released at 3/15/2021)
3
+ ## v0.13.0 (released at 3/3/2021)
4
4
 
5
- * Fix MpApi initialize bug, by @hardywu #296
5
+ * Support zeitwerk only and Rails 6+ only.
6
+ * Support Ruby 2.6+ only.
6
7
 
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)
183
-
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
186
-
187
- ## v0.7.18 (released at 8/21/2016)
188
-
189
- * Support label_location message, similar to location event, but sent by user with Label. #144
190
- * Add gem signature as additional security methods.
191
-
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)
391
-
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
397
-
398
- ## v0.1.1
399
-
400
- * 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
  运行下面这行代码来安装:
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:
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
@@ -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.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/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
@@ -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
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
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.3
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-03-15 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,34 +119,48 @@ 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
@@ -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.14
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