wechat 0.8.6 → 0.8.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 62ec874b95597f2ea1e8678e2903b591dae48c60
4
- data.tar.gz: 35725116ed22adb68f8002bc670d5d450daa4d69
3
+ metadata.gz: d7ee715ed77e318662731915d4b04d1a3ddf57fd
4
+ data.tar.gz: 5fba117fd1a11174d5453b16e7bfb800d6ce1fad
5
5
  SHA512:
6
- metadata.gz: 25b8b447ff7bdd05a2269a2c830b880074ec11d84ffeac07b46e797213e8d26f170531da2e859384876556f9c88255829a54d163441cc220eb5a88c45119bc6b
7
- data.tar.gz: 80300468b803ca0b035177a88df2b7f9cd06adad810bed9e721c48326aa7f72bc2c0452e0863e3d3be544d59ec5af1002f5611909fc67bc2959fd7b070905aab
6
+ metadata.gz: 465dcca90573b199673602e8797ab078d27ff285b6639db1a923b377fafca9d98cf8244b78b33f07c07699d821c45639869fe97956943de38096779b8c215701
7
+ data.tar.gz: 5efd883e21fc35ed05a225b30a08f83af1927f3989c302fce72432ec4e8a4a93a09c64a703171c26885cc6dd74dd318f4824a6e2531fbe7b372f0adf02d6d68a
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.8.7 (released at 4/23/2017)
4
+
5
+ * Support new wxa_get_wxacode API for miniapp.
6
+ * Add InvalidCredentialError, support audio/amr, voice/speex as file and text/plain as json. by @acenqiu #184
7
+
3
8
  ## v0.8.6 (released at 3/17/2017)
4
9
 
5
10
  * Support Rails 5.1 officially.
@@ -17,17 +22,17 @@
17
22
 
18
23
  ## v0.8.4 (released at 1/12/2017)
19
24
 
20
- # Support Ruby 2.4.0
21
- # Add support of Enterprise RedPacket API, by @zhangbin #169
25
+ * Support Ruby 2.4.0
26
+ * Add support of Enterprise RedPacket API, by @zhangbin #169
22
27
 
23
28
  ## v0.8.3 (released at 11/26/2016)
24
29
 
25
- # Fix wechat template key has camelCase problem, by @RyanChenDji #159
26
- # Fix long time of oauth2_state bug for wechat_oauth2 methods, by @IvanChou #162
30
+ * Fix wechat template key has camelCase problem, by @RyanChenDji #159
31
+ * Fix long time of oauth2_state bug for wechat_oauth2 methods, by @IvanChou #162
27
32
 
28
33
  ## v0.8.2 (released at 11/2/2016)
29
34
 
30
- # Bug which if not using multi-account but using web login.
35
+ * Bug which if not using multi-account but using web login.
31
36
 
32
37
  ## v0.8.1 (released at 11/2/2016)
33
38
 
@@ -57,7 +62,7 @@
57
62
 
58
63
  ## v0.7.17 (released at 8/18/2016)
59
64
 
60
- * Allow declare wechat_api at ApplicationController, but using wechat at sub controller. #104
65
+ * Allow declare wechat_api at ApplicationController, but using wechat at sub controller. #104
61
66
 
62
67
  ## v0.7.16 (released at 7/27/2016)
63
68
 
@@ -135,9 +140,9 @@
135
140
  * Optional session support by @zfben #81, #88, #91
136
141
  * Replace after_wechat_response with Rails Nofications facility, by @zfben, original issue is #79
137
142
  * New user_batchget API. #89
138
- * Support Rails 3.2 again after support Rails 5.0. by @guange2015 #87
143
+ * Support Rails 3.2 again after support Rails 5.0. by @guange2015 #87
139
144
  * Fetch setting from RAILS_ENV first, then fetch default. by @kikyous #85
140
- * Warning not support on :scan with regular expression, reason see #84
145
+ * Warning not support on :scan with regular expression, reason see #84
141
146
 
142
147
  ## v0.7.1 (released at 1/11/2016)
143
148
 
@@ -151,9 +156,9 @@
151
156
 
152
157
  ## v0.6.10 (released at 1/17/2016)
153
158
 
154
- * Support Rails 3.2 again after support Rails 5.0. by @guange2015 #87
159
+ * Support Rails 3.2 again after support Rails 5.0. by @guange2015 #87
155
160
  * Fetch setting from RAILS_ENV first, then fetch default. by @kikyous #85
156
- * Warning not support on :scan with regular expression. by @kikyous #84
161
+ * Warning not support on :scan with regular expression. by @kikyous #84
157
162
 
158
163
  ## v0.6.9 (released at 1/6/2016)
159
164
 
@@ -213,7 +218,7 @@
213
218
  * Scan 2D barcode using new syntax `on :scan, with: 'BINDING_QR_CODE' ` instead of `on :event, with: 'BINDING_QR_CODE' ` in previous version #55
214
219
  Which will fix can not using `on :event, with: "scan" ` problem
215
220
  * Batch job using new syntax `on :batch_job, with: 'replace_user' `
216
- instead of previous `on :event, with: 'replace_user' `.
221
+ instead of previous `on :event, with: 'replace_user' `.
217
222
  * 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.
218
223
  * Wechat::Responder using Hash for new :client and :batch_job event, avoid time consuming Array match responder
219
224
  * Fix refresh token not working problem under ruby 2.0.0 #54
@@ -232,7 +237,7 @@ instead of previous `on :event, with: 'replace_user' `.
232
237
 
233
238
  * Fix wrong number of arguments at Wechat::Responder.on by using arity #47
234
239
  * Fix can not access wechat method after using instance level context.
235
- * Fix skip_verify_ssl parameter error.
240
+ * Fix skip_verify_ssl parameter error.
236
241
 
237
242
  ## v0.4.1 (released at 9/6/2015)
238
243
 
@@ -339,6 +339,7 @@ Wechat Public Account commands:
339
339
  wechat user_group [OPEN_ID] # 查询用户所在分组
340
340
  wechat user_update_remark [OPEN_ID, REMARK] # 设置备注名
341
341
  wechat users # 关注者列表
342
+ wechat wxacode_download [WXA_CODE_PIC_PATH, PATH, WIDTH] # 下载小程序码
342
343
  ```
343
344
 
344
345
  #### 企业号命令行
data/README.md CHANGED
@@ -354,6 +354,7 @@ Wechat Public Account commands:
354
354
  wechat user_group [OPEN_ID] # 查询用户所在分组
355
355
  wechat user_update_remark [OPEN_ID, REMARK] # 设置备注名
356
356
  wechat users # 关注者列表
357
+ wechat wxacode_download [WXA_CODE_PIC_PATH, PATH, WIDTH] # 下载小程序码
357
358
  ```
358
359
 
359
360
  #### Enterprise account command line
data/bin/wechat CHANGED
@@ -199,6 +199,13 @@ class App < Thor
199
199
  end
200
200
  else
201
201
  package_name 'Wechat Public Account'
202
+ desc 'wxacode_download [WXA_CODE_PIC_PATH, PATH, WIDTH]', '下载小程序码'
203
+ def wxacode_download(wxa_code_pic_path, path = 'pages/index/index', width = 430)
204
+ tmp_file = wechat_api.wxa_get_wxacode(path, width)
205
+ FileUtils.mv(tmp_file.path, wxa_code_pic_path)
206
+ puts 'WXA Code File downloaded'
207
+ end
208
+
202
209
  desc 'media_uploadnews [MPNEWS_YAML_PATH]', '上传图文消息素材'
203
210
  def media_uploadnews(mpnews_yaml_path)
204
211
  mpnew = YAML.load(File.read(mpnews_yaml_path))
@@ -3,7 +3,7 @@ class WechatsController < ApplicationController
3
3
  <% else -%>
4
4
  class WechatsController < ActionController::Base
5
5
  <% end -%>
6
- # For details on the DSL available within this file, see https://github.com/Eric-Guo/wechat#rails-responder-controller-dsl
6
+ # For details on the DSL available within this file, see https://github.com/Eric-Guo/wechat#wechat_responder---rails-responder-controller-dsl
7
7
  wechat_responder
8
8
 
9
9
  on :text do |request, content|
@@ -11,6 +11,7 @@ module Wechat
11
11
  autoload :ControllerApi, 'wechat/controller_api'
12
12
 
13
13
  class AccessTokenExpiredError < StandardError; end
14
+ class InvalidCredentialError < StandardError; end
14
15
  class ResponseError < StandardError
15
16
  attr_reader :error_code
16
17
  def initialize(errcode, errmsg)
@@ -6,6 +6,7 @@ require 'wechat/ticket/public_jsapi_ticket'
6
6
  module Wechat
7
7
  class Api < ApiBase
8
8
  API_BASE = 'https://api.weixin.qq.com/cgi-bin/'.freeze
9
+ WXA_BASE = 'https://api.weixin.qq.com/wxa/'.freeze
9
10
 
10
11
  def initialize(appid, secret, token_file, timeout, skip_verify_ssl, jsapi_ticket_file)
11
12
  @client = HttpClient.new(API_BASE, timeout, skip_verify_ssl)
@@ -91,6 +92,10 @@ module Wechat
91
92
  post 'message/mass/get', JSON.generate(msg_id: msg_id)
92
93
  end
93
94
 
95
+ def wxa_get_wxacode(path, width = 430)
96
+ post 'getwxacode', JSON.generate(path: path, width: width), base: WXA_BASE
97
+ end
98
+
94
99
  def wxa_create_qrcode(path, width = 430)
95
100
  post 'wxaapp/createwxaqrcode', JSON.generate(path: path, width: width)
96
101
  end
@@ -70,9 +70,22 @@ module Wechat
70
70
  parse_as = {
71
71
  %r{^application\/json} => :json,
72
72
  %r{^image\/.*} => :file,
73
- %r{^text\/html} => :xml
73
+ %r{^audio\/.*} => :file,
74
+ %r{^voice\/.*} => :file,
75
+ %r{^text\/html} => :xml,
76
+ %r{^text\/plain} => :probably_json
74
77
  }.each_with_object([]) { |match, memo| memo << match[1] if content_type =~ match[0] }.first || as || :text
75
78
 
79
+ # try to parse response as json, fallback to user-specified format or text if failed
80
+ if parse_as == :probably_json
81
+ data = JSON.parse response.body.to_s.gsub(/[\u0000-\u001f]+/, '') rescue nil
82
+ if data
83
+ return yield(:json, data)
84
+ else
85
+ parse_as = as || :text
86
+ end
87
+ end
88
+
76
89
  case parse_as
77
90
  when :file
78
91
  file = Tempfile.new('tmp')
@@ -30,6 +30,8 @@ module Wechat
30
30
  end
31
31
 
32
32
  def write_token_to_store(token_hash)
33
+ raise InvalidCredentialError unless token_hash.is_a?(Hash) && token_hash['access_token']
34
+
33
35
  token_hash['got_token_at'.freeze] = Time.now.to_i
34
36
  token_hash['token_expires_in'.freeze] = token_hash.delete('expires_in')
35
37
  write_token(token_hash)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wechat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.6
4
+ version: 0.8.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Skinnyworm
@@ -31,7 +31,7 @@ cert_chain:
31
31
  R5k6Ma92sW8jupX4cqbSu9rntdVQkNRpoHIrfU0MZT0cKsg/D1zMteylxrO3KMsz
32
32
  SPQRv+nrI1J0zevFqb8010heoR8SDyUA0Mm3+Q==
33
33
  -----END CERTIFICATE-----
34
- date: 2017-03-17 00:00:00.000000000 Z
34
+ date: 2017-04-23 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: activesupport
@@ -206,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
206
206
  version: '0'
207
207
  requirements: []
208
208
  rubyforge_project:
209
- rubygems_version: 2.6.10
209
+ rubygems_version: 2.6.11
210
210
  signing_key:
211
211
  specification_version: 4
212
212
  summary: DSL for wechat message handling and API
metadata.gz.sig CHANGED
Binary file