wechat 0.4.0 → 0.4.1
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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +6 -3
- data/bin/wechat +10 -0
- data/lib/wechat.rb +1 -1
- data/lib/wechat/api.rb +8 -0
- data/lib/wechat/corp_api.rb +8 -0
- data/lib/wechat/message.rb +1 -1
- data/lib/{action_controller → wechat}/responder.rb +11 -18
- data/lib/wechat/signature.rb +10 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15c91eb2d65ed9645ca79ace9245f8b37951dd04
|
4
|
+
data.tar.gz: ce52424a06ecbd344c18f4a2113dbf7af9507a9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d7c44d220b7467482271b757dddc50e71f19df8a2d2bde28d6e2d3a3c8f9eaf2cebb70adaa6df73ad9b86c34314f013c0803d3def5cd47dd933e82d1d86408b
|
7
|
+
data.tar.gz: 988540c451e81e64e44c2959d46197e420bfe1ed32756e4a15b33b68ad523abf9a32afb50fd9ddeb3e117c98fd6bf16c83eb77b750161976fec40b0dec0f309a
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v0.4.1 (released at 9/6/2015)
|
4
|
+
|
5
|
+
* Limit news articles collection to 10, close #5
|
6
|
+
* Resolve the conflict with gem "responders" by @seamon #45
|
7
|
+
|
3
8
|
## v0.4.0 (released at 9/5/2015)
|
4
9
|
|
5
10
|
* Enable the verify SSL for enterprise mode by default, as security is more importent than speed, but still can switch off by configure
|
data/README.md
CHANGED
@@ -154,6 +154,8 @@ Wechat commands:
|
|
154
154
|
wechat invite_user [USER_ID] # 邀请成员关注
|
155
155
|
wechat material [MEDIA_ID, PATH] # 永久媒体下载
|
156
156
|
wechat material_add [MEDIA_TYPE, PATH] # 永久媒体上传
|
157
|
+
wechat material_count # 获取素材总数
|
158
|
+
wechat material_delete [MEDIA_ID] # 删除永久素材
|
157
159
|
wechat media [MEDIA_ID, PATH] # 媒体下载
|
158
160
|
wechat media_create [MEDIA_TYPE, PATH] # 媒体上传
|
159
161
|
wechat menu # 当前菜单
|
@@ -343,9 +345,10 @@ class WechatsController < ApplicationController
|
|
343
345
|
|
344
346
|
# 当请求的文字信息内容为'<n>条新闻'时, 使用这个responder处理, 并将n作为第二个参数
|
345
347
|
on :text, with: /^(\d+)条新闻$/ do |request, count|
|
346
|
-
|
347
|
-
|
348
|
-
|
348
|
+
# 微信最多显示10条新闻,大于10条将只取前10条
|
349
|
+
news = (1..count.to_i).each_with_object([]) { |n, memo| memo << {title: "新闻标题", content: "第#{n}条新闻的内容#{n.hash}"} }
|
350
|
+
request.reply.news(news) do |article, n, index| # 回复"articles"
|
351
|
+
article.item title: "#{index} #{n[:title]}", description: n[:content], pic_url: "http://www.baidu.com/img/bdlogo.gif", url:"http://www.baidu.com/"
|
349
352
|
end
|
350
353
|
end
|
351
354
|
|
data/bin/wechat
CHANGED
@@ -165,6 +165,16 @@ HELP
|
|
165
165
|
puts Helper.with(options).material_add(type, file)
|
166
166
|
end
|
167
167
|
|
168
|
+
desc 'material_delete [MEDIA_ID]', '删除永久素材'
|
169
|
+
def material_delete(media_id)
|
170
|
+
puts Helper.with(options).material_delete(media_id)
|
171
|
+
end
|
172
|
+
|
173
|
+
desc 'material_count', '获取素材总数'
|
174
|
+
def material_count
|
175
|
+
puts Helper.with(options).material_count
|
176
|
+
end
|
177
|
+
|
168
178
|
desc 'message_send [OPENID, TEXT_MESSAGE]', '发送文字消息(仅企业号)'
|
169
179
|
def message_send(openid, text_message)
|
170
180
|
puts Helper.with(options).message_send openid, text_message
|
data/lib/wechat.rb
CHANGED
@@ -4,7 +4,7 @@ require 'action_controller/wechat_responder'
|
|
4
4
|
|
5
5
|
module Wechat
|
6
6
|
autoload :Message, 'wechat/message'
|
7
|
-
autoload :Responder, '
|
7
|
+
autoload :Responder, 'wechat/responder'
|
8
8
|
autoload :Cipher, 'wechat/cipher'
|
9
9
|
|
10
10
|
class AccessTokenExpiredError < StandardError; end
|
data/lib/wechat/api.rb
CHANGED
@@ -75,10 +75,18 @@ module Wechat
|
|
75
75
|
get 'material/get', params: { media_id: media_id }, base: FILE_BASE, as: :file
|
76
76
|
end
|
77
77
|
|
78
|
+
def material_count
|
79
|
+
get 'material/get_materialcount'
|
80
|
+
end
|
81
|
+
|
78
82
|
def material_add(type, file)
|
79
83
|
post 'material/add_material', { upload: { media: file } }, params: { type: type }, base: FILE_BASE
|
80
84
|
end
|
81
85
|
|
86
|
+
def material_delete(media_id)
|
87
|
+
post 'material/del_material', media_id: media_id
|
88
|
+
end
|
89
|
+
|
82
90
|
def custom_message_send(message)
|
83
91
|
post 'message/custom/send', message.to_json, content_type: :json
|
84
92
|
end
|
data/lib/wechat/corp_api.rb
CHANGED
@@ -60,6 +60,10 @@ module Wechat
|
|
60
60
|
get 'media/get', params: { media_id: media_id }, as: :file
|
61
61
|
end
|
62
62
|
|
63
|
+
def material_count
|
64
|
+
get 'material/get_count', params: { agentid: agentid }
|
65
|
+
end
|
66
|
+
|
63
67
|
def media_create(type, file)
|
64
68
|
post 'media/upload', { upload: { media: file } }, params: { type: type }
|
65
69
|
end
|
@@ -72,6 +76,10 @@ module Wechat
|
|
72
76
|
post 'material/add_material', { upload: { media: file } }, params: { type: type, agentid: agentid }
|
73
77
|
end
|
74
78
|
|
79
|
+
def material_delete(media_id)
|
80
|
+
get 'material/del', params: { media_id: media_id, agentid: agentid }
|
81
|
+
end
|
82
|
+
|
75
83
|
def message_send(openid, message)
|
76
84
|
post 'message/send', Message.to(openid).text(message).agent_id(agentid).to_json, content_type: :json
|
77
85
|
end
|
data/lib/wechat/message.rb
CHANGED
@@ -94,7 +94,7 @@ module Wechat
|
|
94
94
|
def news(collection, &block)
|
95
95
|
if block_given?
|
96
96
|
article = ArticleBuilder.new
|
97
|
-
collection.
|
97
|
+
collection.take(10).each_with_index { |item, index| yield(article, item, index) }
|
98
98
|
items = article.items
|
99
99
|
else
|
100
100
|
items = collection.collect do |item|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'English'
|
2
|
+
require 'wechat/signature'
|
2
3
|
|
3
4
|
module Wechat
|
4
5
|
module Responder
|
@@ -14,11 +15,11 @@ module Wechat
|
|
14
15
|
attr_accessor :wechat, :token, :corpid, :agentid, :encrypt_mode, :skip_verify_ssl, :encoding_aes_key
|
15
16
|
|
16
17
|
def on(message_type, with: nil, respond: nil, &block)
|
17
|
-
fail 'Unknow message type' unless
|
18
|
+
fail 'Unknow message type' unless [:text, :image, :voice, :video, :location, :link, :event, :fallback].include?(message_type)
|
18
19
|
config = respond.nil? ? {} : { respond: respond }
|
19
20
|
config.merge!(proc: block) if block_given?
|
20
21
|
|
21
|
-
if with.present? && !
|
22
|
+
if with.present? && ![:text, :event].include?(message_type)
|
22
23
|
fail 'Only text and event message can take :with parameters'
|
23
24
|
else
|
24
25
|
config.merge!(with: with) if with.present?
|
@@ -104,22 +105,14 @@ module Wechat
|
|
104
105
|
def verify_signature
|
105
106
|
signature = params[:signature] || params[:msg_signature]
|
106
107
|
|
107
|
-
|
108
|
-
end
|
109
|
-
|
110
|
-
def content_to_verify
|
111
|
-
array = [self.class.token, params[:timestamp], params[:nonce]]
|
108
|
+
msg_encrypt = params[:echostr] if self.class.corpid.present?
|
112
109
|
|
113
|
-
|
114
|
-
if params[:signature].blank? && params[:msg_signature]
|
115
|
-
if params[:echostr].present?
|
116
|
-
array << params[:echostr]
|
117
|
-
else
|
118
|
-
array << request_encrypt_content
|
119
|
-
end
|
120
|
-
end
|
110
|
+
msg_encrypt ||= request_encrypt_content if self.class.encrypt_mode
|
121
111
|
|
122
|
-
|
112
|
+
render text: 'Forbidden', status: 403 if signature != Signature.hexdigest(self.class.token,
|
113
|
+
params[:timestamp],
|
114
|
+
params[:nonce],
|
115
|
+
msg_encrypt)
|
123
116
|
end
|
124
117
|
|
125
118
|
def post_xml
|
@@ -155,7 +148,7 @@ module Wechat
|
|
155
148
|
def process_response(response)
|
156
149
|
msg = response.to_xml
|
157
150
|
|
158
|
-
if self.class.encrypt_mode
|
151
|
+
if self.class.encrypt_mode
|
159
152
|
encrypt = Base64.strict_encode64(encrypt(pack(msg, @app_id), self.class.encoding_aes_key))
|
160
153
|
msg = gen_msg(encrypt, params[:timestamp], params[:nonce])
|
161
154
|
end
|
@@ -164,7 +157,7 @@ module Wechat
|
|
164
157
|
end
|
165
158
|
|
166
159
|
def gen_msg(encrypt, timestamp, nonce)
|
167
|
-
msg_sign =
|
160
|
+
msg_sign = Signature.hexdigest(self.class.token, timestamp, nonce, encrypt)
|
168
161
|
|
169
162
|
{ Encrypt: encrypt,
|
170
163
|
MsgSignature: msg_sign,
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module Wechat
|
2
|
+
module Signature
|
3
|
+
def self.hexdigest(token, timestamp, nonce, msg_encrypt)
|
4
|
+
array = [token, timestamp, nonce]
|
5
|
+
array << msg_encrypt unless msg_encrypt.nil?
|
6
|
+
dev_msg_signature = array.compact.collect(&:to_s).sort.join
|
7
|
+
Digest::SHA1.hexdigest(dev_msg_signature)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
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.4.
|
4
|
+
version: 0.4.1
|
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-09-
|
12
|
+
date: 2015-09-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -79,7 +79,6 @@ files:
|
|
79
79
|
- README.md
|
80
80
|
- Rakefile
|
81
81
|
- bin/wechat
|
82
|
-
- lib/action_controller/responder.rb
|
83
82
|
- lib/action_controller/wechat_responder.rb
|
84
83
|
- lib/wechat.rb
|
85
84
|
- lib/wechat/access_token.rb
|
@@ -90,6 +89,8 @@ files:
|
|
90
89
|
- lib/wechat/corp_api.rb
|
91
90
|
- lib/wechat/jsapi_ticket.rb
|
92
91
|
- lib/wechat/message.rb
|
92
|
+
- lib/wechat/responder.rb
|
93
|
+
- lib/wechat/signature.rb
|
93
94
|
homepage: https://github.com/Eric-Guo/wechat
|
94
95
|
licenses:
|
95
96
|
- MIT
|