wechat 0.6.2 → 0.6.3

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: 458dae06ac4875c8cf283fbda7cb06fa8b2260bf
4
- data.tar.gz: cecda681714c670bb60f582fac2d3f4b25999a0a
3
+ metadata.gz: 9f57875f2dee753674602e98333ae19b6a29c4ed
4
+ data.tar.gz: e0c6882f86e379bfd8ad74d31a3c6241cd47f0ae
5
5
  SHA512:
6
- metadata.gz: d4c9ec8d9831c415a3d5a8557173e1f1c2cd37358f9b94191eafdf073b1158974954de842867d6e829150cdc95e904dcd2bc6c90c9bae877ad5dc1f50448a7b2
7
- data.tar.gz: 8c3f2f89ec9a36d1e92af1b2408fc2de5a5f23ee8f20f924f64cb216c242253b04627169b3870ca7b51bc033491048a55726fe8ca17fff224706db664208b808
6
+ metadata.gz: 375da3a164458340900ed8d1ab1b4c864ce3b2f645f18ef19be010a67954018ff5a34da7273e12169c1654673d91c237ea99a633ef63b5630d84f04561e887e9
7
+ data.tar.gz: 9dba3994255e0cff1de66e7f125f30b9a6f836f81f98a327fab1180fc940e7fc40ed5169c10ff939264a2e314ae9b3412afbb3a9a8b6bda2920237d43799fa0e
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.6.3 (released at 11/14/2015)
4
+
5
+ * Official testing and support public encrypt mode, also fix one cipher bug, many thanks to hlltc #67
6
+ * hlltc report public account FILE_BASE no longer needs, clean code #67
7
+ * Media command line reflect recent Tecent json schema change. #67
8
+
3
9
  ## v0.6.2 (released at 11/05/2015)
4
10
 
5
11
  * Tecent report location API changed, so change wechat gems also. #64
data/README.md CHANGED
@@ -88,6 +88,14 @@ test:
88
88
  <<: *default
89
89
  ```
90
90
 
91
+ 公众号可选安全模式(加密模式),通过添加如下配置可开启加密模式。
92
+
93
+ ```
94
+ default: &default
95
+ encrypt_mode: true
96
+ encoding_aes_key: "my_encoding_aes_key"
97
+ ```
98
+
91
99
  企业号配置下必须使用加密模式,其中token和encoding_aes_key可以从企业号管理界面的应用中心->某个应用->模式选择,选择回调模式后获得。
92
100
 
93
101
  ```
data/bin/wechat CHANGED
@@ -360,8 +360,8 @@ HELP
360
360
  r = Helper.with(options).material_list(type, offset, count)
361
361
  if %w(image voice video file).include?(type)
362
362
  puts "errcode: #{r['errcode']} errmsg: #{r['errmsg']} total_count: #{r['total_count']} item_count: #{r['item_count']}"
363
- r['itemlist'].each do |i|
364
- puts "#{i['media_id']} #{i['filename']} #{Time.at(i['update_time'].to_i)}"
363
+ r['item'].each do |i|
364
+ puts "#{i['media_id']} #{i['name']} #{Time.at(i['update_time'].to_i)}"
365
365
  end
366
366
  else
367
367
  puts r
@@ -5,9 +5,10 @@ default: &default
5
5
  # Or if using public account, only need above two line
6
6
  # appid: "my_appid"
7
7
  # secret: "my_secret"
8
- token: "token"
8
+ token: "my_token"
9
9
  access_token: "C:/Users/[username]/wechat_access_token"
10
- encoding_aes_key: "encoding_aes_key"
10
+ encrypt_mode: false # if true must fill encoding_aes_key
11
+ encoding_aes_key: "my_encoding_aes_key"
11
12
 
12
13
  production:
13
14
  corpid: <%%= ENV['WECHAT_CORPID'] %>
@@ -18,6 +19,7 @@ production:
18
19
  # secret: <%= ENV['WECHAT_APP_SECRET'] %>
19
20
  token: <%%= ENV['WECHAT_TOKEN'] %>
20
21
  access_token: <%%= ENV['WECHAT_ACCESS_TOKEN'] %>
22
+ encrypt_mode: false # if true must fill encoding_aes_key
21
23
  encoding_aes_key: <%%= ENV['WECHAT_ENCODING_AES_KEY'] %>
22
24
 
23
25
  development:
@@ -8,7 +8,6 @@ module Wechat
8
8
  attr_reader :jsapi_ticket
9
9
 
10
10
  API_BASE = 'https://api.weixin.qq.com/cgi-bin/'
11
- FILE_BASE = 'http://file.api.weixin.qq.com/cgi-bin/'
12
11
  OAUTH2_BASE = 'https://api.weixin.qq.com/sns/oauth2/'
13
12
 
14
13
  def initialize(appid, secret, token_file, skip_verify_ssl, jsapi_ticket_file = '/var/tmp/wechat_jsapi_ticket')
@@ -84,16 +83,8 @@ module Wechat
84
83
  post 'menu/create', JSON.generate(menu)
85
84
  end
86
85
 
87
- def media(media_id)
88
- get 'media/get', params: { media_id: media_id }, base: FILE_BASE, as: :file
89
- end
90
-
91
- def media_create(type, file)
92
- post 'media/upload', { upload: { media: file } }, params: { type: type }, base: FILE_BASE
93
- end
94
-
95
86
  def material(media_id)
96
- get 'material/get', params: { media_id: media_id }, base: FILE_BASE, as: :file
87
+ get 'material/get', params: { media_id: media_id }, as: :file
97
88
  end
98
89
 
99
90
  def material_count
@@ -105,7 +96,7 @@ module Wechat
105
96
  end
106
97
 
107
98
  def material_add(type, file)
108
- post 'material/add_material', { upload: { media: file } }, params: { type: type }, base: FILE_BASE
99
+ post 'material/add_material', { upload: { media: file } }, params: { type: type }
109
100
  end
110
101
 
111
102
  def material_delete(media_id)
@@ -14,6 +14,14 @@ module Wechat
14
14
  client.get 'showqrcode', ticket: CGI.escape(ticket), base: MP_BASE, as: :file
15
15
  end
16
16
 
17
+ def media(media_id)
18
+ get 'media/get', params: { media_id: media_id }, as: :file
19
+ end
20
+
21
+ def media_create(type, file)
22
+ post 'media/upload', { upload: { media: file } }, params: { type: type }
23
+ end
24
+
17
25
  protected
18
26
 
19
27
  def get(path, headers = {})
@@ -14,11 +14,11 @@ module Wechat
14
14
  cipher.encrypt
15
15
 
16
16
  cipher.padding = 0
17
- key_data = Base64.decode64(encoding_aes_key)
17
+ key_data = Base64.decode64(encoding_aes_key + '=')
18
18
  cipher.key = key_data
19
19
  cipher.iv = key_data[0..16]
20
20
 
21
- cipher.update(encode_padding(plain)) + cipher.final
21
+ cipher.update(plain) + cipher.final
22
22
  end
23
23
 
24
24
  def decrypt(msg, encoding_aes_key)
@@ -26,7 +26,7 @@ module Wechat
26
26
  cipher.decrypt
27
27
 
28
28
  cipher.padding = 0
29
- key_data = Base64.decode64(encoding_aes_key)
29
+ key_data = Base64.decode64(encoding_aes_key + '=')
30
30
  cipher.key = key_data
31
31
  cipher.iv = key_data[0..16]
32
32
 
@@ -136,10 +136,6 @@ module Wechat
136
136
  post 'menu/create', JSON.generate(menu), params: { agentid: agentid }
137
137
  end
138
138
 
139
- def media(media_id)
140
- get 'media/get', params: { media_id: media_id }, as: :file
141
- end
142
-
143
139
  def material_count
144
140
  get 'material/get_count', params: { agentid: agentid }
145
141
  end
@@ -148,10 +144,6 @@ module Wechat
148
144
  post 'material/batchget', JSON.generate(type: type, agentid: agentid, offset: offset, count: count)
149
145
  end
150
146
 
151
- def media_create(type, file)
152
- post 'media/upload', { upload: { media: file } }, params: { type: type }
153
- end
154
-
155
147
  def material(media_id)
156
148
  get 'material/get', params: { media_id: media_id, agentid: agentid }, as: :file
157
149
  end
@@ -153,10 +153,14 @@ module Wechat
153
153
  private
154
154
 
155
155
  def verify_signature
156
- signature = params[:signature] || params[:msg_signature]
156
+ if self.class.encrypt_mode
157
+ signature = params[:signature] || params[:msg_signature]
158
+ msg_encrypt = params[:echostr] || request_encrypt_content
159
+ else
160
+ signature = params[:signature]
161
+ end
157
162
 
158
- msg_encrypt = params[:echostr] if self.class.corpid.present?
159
- msg_encrypt ||= request_encrypt_content if self.class.encrypt_mode
163
+ msg_encrypt = nil unless self.class.corpid.present?
160
164
 
161
165
  render text: 'Forbidden', status: 403 if signature != Signature.hexdigest(self.class.token,
162
166
  params[:timestamp],
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.6.2
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Skinnyworm
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-11-05 00:00:00.000000000 Z
12
+ date: 2015-11-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport