wechat-validator 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -0
- data/Rakefile +2 -2
- data/app/assets/config/wechat-validator_manifest.js +2 -0
- data/app/assets/javascripts/wechat/validator/application.js +1 -1
- data/app/assets/stylesheets/wechat/validator/application.css +3 -3
- data/app/controllers/wechat/validator/application_controller.rb +4 -0
- data/app/controllers/wechat/validator/concerns/signature_validator.rb +5 -3
- data/app/controllers/wechat/validator/server_validations_controller.rb +3 -3
- data/app/jobs/wechat/validator/application_job.rb +5 -0
- data/app/mailers/wechat/validator/application_mailer.rb +7 -0
- data/app/models/wechat/validator/application_record.rb +6 -0
- data/app/views/layouts/wechat/validator/application.html.erb +2 -2
- data/lib/wechat/validator/engine.rb +0 -10
- data/lib/wechat/validator/version.rb +1 -1
- metadata +14 -5
- data/app/controllers/wechat/validator/concerns/signature_checker.rb +0 -62
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e9283ec864182a64ebcfdb830e867177d1544f1
|
4
|
+
data.tar.gz: 4189ecacf67257f45c2b4622fef9515800bdb408
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58119aca68cebfdc5c9e1ef7ab238c05a59b40caccfa18bb1daaa3c99e2179143957c437c82700e80a5b33a392bf27c7616e8ab398dbf40f22b0626dad14ea8a
|
7
|
+
data.tar.gz: 044a8aa4563581fee9227e1ae2ad5cadb0a319143c38bb9ccffb35f8c32bc947ad833ddbcdb65f12df814acb6a7c72fd1c54379518283dd54f1886f982ef1087
|
data/README.md
CHANGED
@@ -1,16 +1,25 @@
|
|
1
1
|
# Wechat Validator 微信服务器验证器引擎
|
2
2
|
|
3
|
+
[![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](http://www.rubydoc.info/gems/wechat-validator/frames)
|
3
4
|
[![License](https://img.shields.io/badge/license-MIT-green.svg)](http://opensource.org/licenses/MIT)
|
5
|
+
|
4
6
|
[![Gem Version](https://badge.fury.io/rb/wechat-validator.svg)](https://badge.fury.io/rb/wechat-validator)
|
7
|
+
[![Dependency Status](https://gemnasium.com/badges/github.com/topbitdu/wechat-validator.svg)](https://gemnasium.com/github.com/topbitdu/wechat-validator)
|
5
8
|
|
6
9
|
The Wechat Server Validator Engine is an engine which handles the Wechat server validation requests.
|
7
10
|
微信服务器验证引擎是一个处理[微信服务器验证](http://mp.weixin.qq.com/wiki/8/f9a0b8382e0b77d87b3bcc1ce6fbc104.html#.E7.AC.AC.E4.BA.8C.E6.AD.A5.EF.BC.9A.E9.AA.8C.E8.AF.81.E6.9C.8D.E5.8A.A1.E5.99.A8.E5.9C.B0.E5.9D.80.E7.9A.84.E6.9C.89.E6.95.88.E6.80.A7)请求的引擎。
|
8
11
|
|
12
|
+
|
13
|
+
|
9
14
|
## Recent Update
|
15
|
+
|
10
16
|
Check out the [Road Map](ROADMAP.md) to find out what's the next.
|
11
17
|
Check out the [Change Log](CHANGELOG.md) to find out what's new.
|
12
18
|
|
19
|
+
|
20
|
+
|
13
21
|
## Usage
|
22
|
+
|
14
23
|
In the application's /config/routes.rb file, add the following line:
|
15
24
|
```ruby
|
16
25
|
mount Wechat::Validator::Engine, at: '/wechat-validator'
|
data/Rakefile
CHANGED
@@ -10,7 +10,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
10
10
|
rdoc.rdoc_dir = 'rdoc'
|
11
11
|
rdoc.title = 'Validator'
|
12
12
|
rdoc.options << '--line-numbers'
|
13
|
-
rdoc.rdoc_files.include('README.
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
14
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
15
|
end
|
16
16
|
|
@@ -20,5 +20,5 @@ load 'rails/tasks/statistics.rake'
|
|
20
20
|
|
21
21
|
|
22
22
|
|
23
|
-
|
23
|
+
require 'bundler/gem_tasks'
|
24
24
|
|
@@ -5,7 +5,7 @@
|
|
5
5
|
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
6
|
//
|
7
7
|
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
-
// compiled file.
|
8
|
+
// compiled file. JavaScript code in this file should be added after the last require_* statement.
|
9
9
|
//
|
10
10
|
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
11
|
// about supported directives.
|
@@ -6,9 +6,9 @@
|
|
6
6
|
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
7
|
*
|
8
8
|
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
-
* compiled file so the styles you add here take precedence over styles defined in any
|
10
|
-
*
|
11
|
-
* file per style scope.
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
11
|
+
* It is generally better to create a new file per style scope.
|
12
12
|
*
|
13
13
|
*= require_self
|
14
14
|
*/
|
@@ -1,8 +1,11 @@
|
|
1
|
+
##
|
2
|
+
# Signature Validator 是微信签名验证的领域逻辑关注点。
|
3
|
+
|
1
4
|
module Wechat::Validator::Concerns::SignatureValidator
|
2
5
|
|
3
6
|
extend ActiveSupport::Concern
|
4
7
|
|
5
|
-
|
8
|
+
included do |includer|
|
6
9
|
|
7
10
|
def validate_signature(token)
|
8
11
|
|
@@ -22,7 +25,7 @@ module Wechat::Validator::Concerns::SignatureValidator
|
|
22
25
|
return unless validate_parameter 'signature', signature
|
23
26
|
return unless validate_parameter 'echo', echo
|
24
27
|
|
25
|
-
actual_signature = Wechat::Validation::Signature.create nonce, timestamp, token
|
28
|
+
actual_signature = Wechat::Validation::Signature.create nonce, timestamp, token
|
26
29
|
signature_matched = signature==actual_signature
|
27
30
|
Rails.logger.warn "Actual signature is #{actual_signature}, which #{signature_matched ? 'equals' : 'does not equal'} to the given signature #{signature}."
|
28
31
|
|
@@ -45,7 +48,6 @@ module Wechat::Validator::Concerns::SignatureValidator
|
|
45
48
|
end
|
46
49
|
|
47
50
|
module ClassMethods
|
48
|
-
# def method_name do end
|
49
51
|
end
|
50
52
|
|
51
53
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
class Wechat::Validator::ServerValidationsController < ::Wechat::Validator::ApplicationController
|
2
2
|
|
3
|
-
include ::Wechat::Validator::Concerns::
|
3
|
+
include ::Wechat::Validator::Concerns::SignatureValidator
|
4
4
|
|
5
5
|
def index
|
6
6
|
|
7
7
|
token = Rails.application.secrets.wechat_validation_token
|
8
|
-
|
8
|
+
validate_signature token
|
9
9
|
|
10
10
|
end
|
11
11
|
|
@@ -13,4 +13,4 @@ class Wechat::Validator::ServerValidationsController < ::Wechat::Validator::Appl
|
|
13
13
|
render text: ''
|
14
14
|
end
|
15
15
|
|
16
|
-
end
|
16
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
<!DOCTYPE html>
|
2
2
|
<html>
|
3
3
|
<head>
|
4
|
-
<title>Validator</title>
|
5
|
-
<%= stylesheet_link_tag
|
4
|
+
<title>Wechat Validator</title>
|
5
|
+
<%= stylesheet_link_tag "wechat/validator/application", media: "all" %>
|
6
6
|
<%= csrf_meta_tags %>
|
7
7
|
</head>
|
8
8
|
<body>
|
@@ -3,16 +3,6 @@ module Wechat
|
|
3
3
|
|
4
4
|
class Engine < ::Rails::Engine
|
5
5
|
|
6
|
-
config.autoload_paths += %W(
|
7
|
-
#{config.root}/lib
|
8
|
-
#{config.root}/app/controllers/wechat/validator/concerns
|
9
|
-
)
|
10
|
-
|
11
|
-
config.eager_load_paths += %W(
|
12
|
-
#{config.root}/lib
|
13
|
-
#{config.root}/app/controllers/wechat/validator/concerns
|
14
|
-
)
|
15
|
-
|
16
6
|
isolate_namespace Wechat::Validator
|
17
7
|
|
18
8
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wechat-validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Topbit Du
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -28,16 +28,22 @@ dependencies:
|
|
28
28
|
name: wechat-validation
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0.2'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 0.2.1
|
34
37
|
type: :runtime
|
35
38
|
prerelease: false
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
37
40
|
requirements:
|
38
|
-
- - "
|
41
|
+
- - "~>"
|
39
42
|
- !ruby/object:Gem::Version
|
40
43
|
version: '0.2'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.2.1
|
41
47
|
description: The Wechat Validator engine handles the Wechat server validation requests.
|
42
48
|
微信验证器引擎处理微信服务器的验证请求。
|
43
49
|
email:
|
@@ -49,13 +55,16 @@ files:
|
|
49
55
|
- MIT-LICENSE
|
50
56
|
- README.md
|
51
57
|
- Rakefile
|
58
|
+
- app/assets/config/wechat-validator_manifest.js
|
52
59
|
- app/assets/javascripts/wechat/validator/application.js
|
53
60
|
- app/assets/stylesheets/wechat/validator/application.css
|
54
61
|
- app/controllers/wechat/validator/application_controller.rb
|
55
|
-
- app/controllers/wechat/validator/concerns/signature_checker.rb
|
56
62
|
- app/controllers/wechat/validator/concerns/signature_validator.rb
|
57
63
|
- app/controllers/wechat/validator/server_validations_controller.rb
|
58
64
|
- app/helpers/wechat/validator/application_helper.rb
|
65
|
+
- app/jobs/wechat/validator/application_job.rb
|
66
|
+
- app/mailers/wechat/validator/application_mailer.rb
|
67
|
+
- app/models/wechat/validator/application_record.rb
|
59
68
|
- app/views/layouts/wechat/validator/application.html.erb
|
60
69
|
- config/routes.rb
|
61
70
|
- lib/tasks/validator_tasks.rake
|
@@ -1,62 +0,0 @@
|
|
1
|
-
module Wechat
|
2
|
-
module Validator
|
3
|
-
module Concerns
|
4
|
-
|
5
|
-
module SignatureChecker
|
6
|
-
|
7
|
-
extend ActiveSupport::Concern
|
8
|
-
|
9
|
-
self.included do |includer|
|
10
|
-
|
11
|
-
def check_signature(token)
|
12
|
-
|
13
|
-
if token.blank?
|
14
|
-
Rails.logger.warn 'Token is required to validate URL by Wechat.'
|
15
|
-
render status: :bad_request, text: 'The token parameter is required.'
|
16
|
-
return
|
17
|
-
end
|
18
|
-
|
19
|
-
timestamp = params[:timestamp]
|
20
|
-
nonce = params[:nonce]
|
21
|
-
signature = params[:signature]
|
22
|
-
echo = params[:echostr]
|
23
|
-
|
24
|
-
return unless check_parameter 'timestamp', timestamp
|
25
|
-
return unless check_parameter 'nonce', nonce
|
26
|
-
return unless check_parameter 'signature', signature
|
27
|
-
return unless check_parameter 'echo', echo
|
28
|
-
|
29
|
-
actual_signature = ::Wechat::Validation::Signature.create nonce, timestamp, token # ::Wechat::Validation.sign nonce, timestamp, token
|
30
|
-
signature_matched = signature==actual_signature
|
31
|
-
Rails.logger.warn "Actual signature is #{actual_signature}, which #{signature_matched ? 'equals' : 'does not equal'} to the given signature #{signature}."
|
32
|
-
|
33
|
-
if signature_matched
|
34
|
-
render text: echo
|
35
|
-
else
|
36
|
-
render status: :bad_request, text: "The signature parameter '#{signature}' and the generated parameter '#{actual_signature}' is not matched."
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
def check_parameter(name, value)
|
42
|
-
if value.blank?
|
43
|
-
Rails.logger.warn "The #{name} parameter is blank. Failed to validate URL by Wechat."
|
44
|
-
render status: :bad_request, text: "The #{name} parameter is required."
|
45
|
-
end
|
46
|
-
value.present?
|
47
|
-
end
|
48
|
-
|
49
|
-
deprecate check_signature: :'Wechat::Validator::Concerns::SignatureValidator.validate_signature', deprecator: ActiveSupport::Deprecation.new('1.0', 'wechat-validator')
|
50
|
-
deprecate check_parameter: :'Wechat::Validator::Concerns::SignatureValidator.validate_parameter', deprecator: ActiveSupport::Deprecation.new('1.0', 'wechat-validator')
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
module ClassMethods
|
55
|
-
# def method_name do end
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|