wechat-validator 0.1 → 0.2

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: 2eb8f8ca2d42d8cde005149dd05c7d4ee67b9083
4
- data.tar.gz: 32681763ef68e00239747c16c083e755ecb288ba
3
+ metadata.gz: 52c70d489e2f730f37e5156c281389eefdd482b3
4
+ data.tar.gz: 07faf1150db584263433821e3e2165cd310027dd
5
5
  SHA512:
6
- metadata.gz: 65de9d152cd21a28ce08c0ea2c11f0d08f9bb2d5fbc7bd7932c1fc6c6f28ba0c51965ec807141dfd836b83778a76833743e51260312b59d2a6de4e75ae554504
7
- data.tar.gz: 324f69a6cee1f88ca6c01152bdc118fc40e112c531fce36f97b8b1b4ee8fd1b32d4d9cdb620a42e36edddea170b72faf5ec5a6ea8b7041390d60cdeb7391fd03
6
+ metadata.gz: e9c4b0d7f70157b86b2b5b368d9127078cc61446e5573f3ab78c5d79f69ce82e2528fba2465ebafce166f643fa2098a0fc03f062439744018e1b878091f1efaf
7
+ data.tar.gz: 61208f0bca87d65209c8a68f5b42e1536d3c9ae2f846db89f4040a3fa2f360a064b2bf73fce9b789404e43d0266a1d1805e805505058cce9baf0c4c7b3226512
data/README.md CHANGED
@@ -1,4 +1,21 @@
1
1
  # Wechat Validator 微信服务器验证器引擎
2
2
 
3
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](http://opensource.org/licenses/MIT)
4
+ [![Gem Version](https://badge.fury.io/rb/wechat-validator.svg)](https://badge.fury.io/rb/wechat-validator)
5
+
3
6
  The Wechat Server Validator Engine is an engine which handles the Wechat server validation requests.
4
- 微信服务器验证引擎是一个处理微信服务器验证请求的引擎。
7
+ 微信服务器验证引擎是一个处理[微信服务器验证](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
+
9
+ ## Usage
10
+ In the application's /config/routes.rb file, add the following line:
11
+ ```ruby
12
+ mount Wechat::Validator::Engine, at: '/wechat-validator'
13
+ ```
14
+
15
+ In the application's /config/secrets.yml file, add the following line for the development, test, and production categories. The wechat_validation_token should be identical with the [token configured](http://mp.weixin.qq.com/wiki/8/f9a0b8382e0b77d87b3bcc1ce6fbc104.html#.E7.AC.AC.E4.B8.80.E6.AD.A5.EF.BC.9A.E5.A1.AB.E5.86.99.E6.9C.8D.E5.8A.A1.E5.99.A8.E9.85.8D.E7.BD.AE).
16
+ ```yaml
17
+ wechat_validation_token: {Your Wechat Validation Token}
18
+ ```
19
+
20
+ Configure the following URL in the [Wechat](http://mp.weixin.qq.com/wiki/8/f9a0b8382e0b77d87b3bcc1ce6fbc104.html#.E7.AC.AC.E4.B8.80.E6.AD.A5.EF.BC.9A.E5.A1.AB.E5.86.99.E6.9C.8D.E5.8A.A1.E5.99.A8.E9.85.8D.E7.BD.AE):
21
+ http://{your.domain.name}/wechat-validator/server_validations
@@ -12,7 +12,7 @@ module Wechat
12
12
 
13
13
  if token.blank?
14
14
  Rails.logger.warn 'Token is required to validate URL by Wechat.'
15
- render status: :forbidden, text: ''
15
+ render status: :forbidden, text: 'The token parameter is required.'
16
16
  return
17
17
  end
18
18
 
@@ -26,16 +26,22 @@ module Wechat
26
26
  return unless check_parameter 'signature', signature
27
27
  return unless check_parameter 'echo', echo
28
28
 
29
- actual_signature = ::Wechat::Validation.sign nonce, timestamp, token
30
- Rails.logger.warn "Actual signature is #{actual_signature}, which #{signature==actual_signature ? 'equals' : 'does not equal'} to the given signature #{signature}."
31
- render text: (signature==actual_signature ? echo : '')
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: :forbidden, text: "The signature parameter '#{signature}' and the generated parameter '#{actual_signature}' is not matched."
37
+ end
32
38
 
33
39
  end
34
40
 
35
41
  def check_parameter(name, value)
36
42
  if value.blank?
37
43
  Rails.logger.warn "The #{name} parameter is blank. Failed to validate URL by Wechat."
38
- render status: :bad_request, text: ''
44
+ render status: :bad_request, text: "The #{name} parameter is required."
39
45
  end
40
46
  value.present?
41
47
  end
@@ -9,4 +9,8 @@ class Wechat::Validator::ServerValidationsController < ::Wechat::Validator::Appl
9
9
 
10
10
  end
11
11
 
12
+ def create
13
+ render text: ''
14
+ end
15
+
12
16
  end
data/config/routes.rb CHANGED
@@ -1,9 +1,5 @@
1
1
  Wechat::Validator::Engine.routes.draw do
2
2
 
3
- #scope module: 'wechat/validator' do
4
- # resources :server_validations, only: :index
5
- #end
6
-
7
- resources :server_validations, only: :index
3
+ resources :server_validations, only: [ :index, :create ]
8
4
 
9
5
  end
@@ -1,5 +1,5 @@
1
1
  module Wechat
2
2
  module Validator
3
- VERSION = '0.1'.freeze
3
+ VERSION = '0.2'.freeze
4
4
  end
5
5
  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.1'
4
+ version: '0.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: 2016-02-15 00:00:00.000000000 Z
11
+ date: 2016-02-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -30,15 +30,16 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.1'
33
+ version: '0.2'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.1'
40
+ version: '0.2'
41
41
  description: The Wechat Validator engine handles the Wechat server validation requests.
42
+ 微信验证器引擎处理微信服务器的验证请求。
42
43
  email:
43
44
  - topbit.du@gmail.com
44
45
  executables: []
@@ -83,6 +84,5 @@ rubyforge_project:
83
84
  rubygems_version: 2.4.5.1
84
85
  signing_key:
85
86
  specification_version: 4
86
- summary: The Wechat Validator engine includes a concern and a controller to handle
87
- the Wechat server validation request.
87
+ summary: Wechat Validator Engine 微信验证器引擎
88
88
  test_files: []