sinatra-wechat 0.1.0 → 0.1.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/lib/sinatra/version.rb +1 -1
- data/lib/sinatra/wechat.rb +8 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f787f9d4d96d419501b7be1824a87ff1407b88d2
|
4
|
+
data.tar.gz: f6ce0d2d62d221861f1183814dbed8ad8016acb3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e97bbaa663a3fca6219aff350b4d45f968e8e8725d1c23ec065dc36907cee81e7ba3f826d609ba3cb2c02acddf30c53bc6d971288b6ba7d45539f434728aadb0
|
7
|
+
data.tar.gz: 5ee37aaef6d99d010fc506e77924d35310cfe0ac141f7a18b4e49ef373dc03620059a52ea126975ac6807cc984a19e850b814db7b65584ef10f68549b9026ccd
|
data/lib/sinatra/version.rb
CHANGED
data/lib/sinatra/wechat.rb
CHANGED
@@ -33,14 +33,18 @@ module Sinatra
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def wechat(endpoint = '/', wechat_token: '', validate_msg: true, &block)
|
36
|
-
before
|
36
|
+
# XXX: 'before' doesn't work in Padrino framework
|
37
|
+
# seems like Padrino has redefined before, and make it incompatible with original one
|
38
|
+
# use a proc instead.
|
39
|
+
validation = Proc.new {
|
37
40
|
if validate_msg then
|
38
41
|
raw = [wechat_token, params[:timestamp], params[:nonce]].compact.sort.join
|
39
42
|
halt 403 unless Digest::SHA1.hexdigest(raw) == params[:signature]
|
40
43
|
end
|
41
|
-
|
44
|
+
}
|
42
45
|
|
43
46
|
get endpoint do
|
47
|
+
instance_eval &validation
|
44
48
|
content_type 'text/plain'
|
45
49
|
params[:echostr]
|
46
50
|
end
|
@@ -48,6 +52,8 @@ module Sinatra
|
|
48
52
|
dispatcher = DispatcherBuilder.new(&block)
|
49
53
|
|
50
54
|
post endpoint do
|
55
|
+
instance_eval &validation
|
56
|
+
|
51
57
|
body = request.body.read || ""
|
52
58
|
halt 400 if body.empty? # bad request, cannot handle this kind of message
|
53
59
|
|