wechat-handler 0.1.1 → 0.1.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 +4 -4
- data/README.md +6 -0
- data/Rakefile +2 -2
- data/app/assets/config/wechat-handler_manifest.js +2 -0
- data/app/assets/javascripts/wechat/handler/application.js +1 -1
- data/app/assets/stylesheets/wechat/handler/application.css +3 -3
- data/app/controllers/wechat/handler/application_controller.rb +4 -0
- data/app/controllers/wechat/handler/concerns/dispatcher.rb +18 -15
- data/app/jobs/wechat/handler/application_job.rb +5 -0
- data/app/mailers/wechat/handler/application_mailer.rb +7 -0
- data/app/models/wechat/handler/application_record.rb +6 -0
- data/app/views/layouts/wechat/handler/application.html.erb +2 -2
- data/lib/wechat/handler/version.rb +1 -1
- metadata +6 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03e9e87d39249ad23c59ced49203f4e496988312
|
4
|
+
data.tar.gz: f08549b67f63f3b0f0166b8352c7d34a7c4926eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35a59ad8dbdc65d41fe4cecedd5a9ca7fc1df4309764a09e165f4570c7c0af26a986cfbf0d2d3c46ad4368b0ed5be552761d02e4683e5f3e245b8e6dafd32461
|
7
|
+
data.tar.gz: 54323309fd7ff1f30af8f7d227ae80fcbe0a65807f0402b61bbfd84180ce240ce0b040d6b6a3f77d2abb179ef43bf805f6c37837f0f1ad094d5c3535596f4fa6
|
data/README.md
CHANGED
@@ -1,19 +1,24 @@
|
|
1
1
|
# Wechat Handler 微信回调处理引擎
|
2
2
|
|
3
|
+
[](http://www.rubydoc.info/gems/wechat-handler/frames)
|
3
4
|
[](http://opensource.org/licenses/MIT)
|
5
|
+
|
4
6
|
[](https://badge.fury.io/rb/wechat-handler)
|
7
|
+
[](https://gemnasium.com/github.com/topbitdu/wechat-handler)
|
5
8
|
|
6
9
|
The Wechat Handler engine handles the Wechat event & message notifications. 微信回调处理引擎处理微信服务器发出的事件通知和消息通知。
|
7
10
|
|
8
11
|
|
9
12
|
|
10
13
|
## Recent Update
|
14
|
+
|
11
15
|
Check out the [Road Map](ROADMAP.md) to find out what's the next.
|
12
16
|
Check out the [Change Log](CHANGELOG.md) to find out what's new.
|
13
17
|
|
14
18
|
|
15
19
|
|
16
20
|
## Usage in Gemfile
|
21
|
+
|
17
22
|
```ruby
|
18
23
|
gem 'wechat-handler'
|
19
24
|
```
|
@@ -21,6 +26,7 @@ gem 'wechat-handler'
|
|
21
26
|
|
22
27
|
|
23
28
|
## Include the controller concern
|
29
|
+
|
24
30
|
```ruby
|
25
31
|
include Wechat::Handler::Concerns::Dispatcher
|
26
32
|
|
data/Rakefile
CHANGED
@@ -10,7 +10,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
10
10
|
rdoc.rdoc_dir = 'rdoc'
|
11
11
|
rdoc.title = 'Wecaht Handler'
|
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
|
+
# Dispatcher 是分发微信回调消息的关注点。
|
3
|
+
|
1
4
|
module Wechat::Handler::Concerns::Dispatcher
|
2
5
|
|
3
6
|
extend ActiveSupport::Concern
|
4
7
|
|
5
|
-
|
8
|
+
included do |includer|
|
6
9
|
|
7
10
|
skip_before_filter :verify_authenticity_token
|
8
11
|
|
@@ -33,8 +36,8 @@ module Wechat::Handler::Concerns::Dispatcher
|
|
33
36
|
Rails.logger.info "The encoded_message is #{encoded_message.inspect}."
|
34
37
|
render status: :bad_request, text: 'msg_sign_error' and return unless check_message_signature(message_signature, encoded_message, nonce, timestamp)
|
35
38
|
|
36
|
-
message =
|
37
|
-
random_bytes, xml_size, xml_text, app_id, padding_bytes =
|
39
|
+
message = Wechat::Callback::MessageDecryption.create encoded_message, Rails.application.secrets.wechat_encoding_aes_keys
|
40
|
+
random_bytes, xml_size, xml_text, app_id, padding_bytes = Wechat::Callback::SecureMessage.load message
|
38
41
|
Rails.logger.warn " >> Wechat Callback >> Message Controller >> App ID of the Secure Message = #{app_id}."
|
39
42
|
Rails.logger.warn ' >> Wechat Callback >> Message Controller >> XML Text of the Secure Message ='
|
40
43
|
Rails.logger.warn xml_text
|
@@ -47,7 +50,7 @@ module Wechat::Handler::Concerns::Dispatcher
|
|
47
50
|
|
48
51
|
end
|
49
52
|
|
50
|
-
pairs =
|
53
|
+
pairs = Wechat::Callback::XmlDocument.load xml_text
|
51
54
|
replying_pairs = { 'ToUserName' => pairs['FromUserName'], 'FromUserName' => pairs['ToUserName'], 'CreateTime' => Time.now.to_i }
|
52
55
|
|
53
56
|
if respond_to? :on_event
|
@@ -57,30 +60,30 @@ module Wechat::Handler::Concerns::Dispatcher
|
|
57
60
|
Rails.logger.warn "The #{includer} does not have the #on_event method."
|
58
61
|
end
|
59
62
|
|
60
|
-
replying_xml_text =
|
63
|
+
replying_xml_text = Wechat::Callback::XmlDocument.create replying_pairs
|
61
64
|
|
62
65
|
if 'aes'==replying_encryption
|
63
|
-
random_bytes =
|
64
|
-
plain_text =
|
65
|
-
encrypted =
|
66
|
-
replying_singature =
|
66
|
+
random_bytes = Wechat::Callback::RandomByteArray.create #16
|
67
|
+
plain_text = Wechat::Callback::SecureMessage.create random_bytes, replying_xml_text, wechat_app_id
|
68
|
+
encrypted = Wechat::Callback::MessageEncryption.create plain_text, wechat_encoding_aes_keys
|
69
|
+
replying_singature = Wechat::Callback::Signature.create wechat_token, timestamp, nonce, encrypted
|
67
70
|
encrypted_replying_pairs = {
|
68
71
|
'Encrypt' => encrypted,
|
69
72
|
'MsgSignature' => replying_singature,
|
70
73
|
'TimeStamp' => timestamp,
|
71
74
|
'Nonce' => nonce
|
72
75
|
}
|
73
|
-
replying_xml_text =
|
76
|
+
replying_xml_text = Wechat::Callback::XmlDocument.create encrypted_replying_pairs
|
74
77
|
|
75
78
|
# debugging
|
76
|
-
debugging_pairs =
|
79
|
+
debugging_pairs = Wechat::Callback::XmlDocument.load replying_xml_text
|
77
80
|
Rails.logger.warn ' >> Wechat Callback >> Message Controller >> Debugging Pairs ='
|
78
81
|
Rails.logger.warn debugging_pairs.inspect
|
79
82
|
debugging_encrypted_message = debugging_pairs['Encrypt']
|
80
|
-
debugging_decrypted_message =
|
83
|
+
debugging_decrypted_message = Wechat::Callback::MessageDecryption.create debugging_encrypted_message, wechat_encoding_aes_keys
|
81
84
|
Rails.logger.warn ' >> Wechat Callback >> Message Controller >> Debugging Decrypted Message ='
|
82
85
|
Rails.logger.warn debugging_decrypted_message
|
83
|
-
debugging_random_bytes, debugging_xml_size, debugging_xml_text, debugging_app_id, debugging_padding_bytes =
|
86
|
+
debugging_random_bytes, debugging_xml_size, debugging_xml_text, debugging_app_id, debugging_padding_bytes = Wechat::Callback::SecureMessage.load debugging_decrypted_message
|
84
87
|
Rails.logger.warn " >> Wechat Callback >> Message Controller >> Debugging App ID of the Secure Message = #{debugging_app_id}."
|
85
88
|
Rails.logger.warn ' >> Wechat Callback >> Message Controller >> Debugging XML Text of the Secure Message ='
|
86
89
|
Rails.logger.warn debugging_xml_text
|
@@ -102,14 +105,14 @@ module Wechat::Handler::Concerns::Dispatcher
|
|
102
105
|
end
|
103
106
|
|
104
107
|
def check_signature(signature, nonce, timestamp)
|
105
|
-
actual =
|
108
|
+
actual = Wechat::Callback::Signature.create wechat_token, timestamp, nonce
|
106
109
|
matched = signature==actual
|
107
110
|
Rails.logger.warn "Actual signature is #{actual}, which does not equal to the given signature #{signature}." unless matched
|
108
111
|
matched
|
109
112
|
end
|
110
113
|
|
111
114
|
def check_message_signature(message_signature, encoded_message, nonce, timestamp)
|
112
|
-
actual =
|
115
|
+
actual = Wechat::Callback::MessageSignature.create encoded_message, wechat_token, timestamp, nonce
|
113
116
|
matched = message_signature==actual
|
114
117
|
Rails.logger.warn "Actual message signature is #{actual}, which does not equal to the given message signature #{message_signature}." unless matched
|
115
118
|
matched
|
@@ -2,14 +2,14 @@
|
|
2
2
|
<html>
|
3
3
|
<head>
|
4
4
|
<title>Wechat Handler</title>
|
5
|
-
<%= stylesheet_link_tag
|
5
|
+
<%= stylesheet_link_tag 'wechat/handler/application', media: "all" %>
|
6
6
|
<%= csrf_meta_tags %>
|
7
7
|
</head>
|
8
8
|
<body>
|
9
9
|
|
10
10
|
<%= yield %>
|
11
11
|
|
12
|
-
<%= javascript_include_tag 'handler/application' %>
|
12
|
+
<%= javascript_include_tag 'wechat/handler/application' %>
|
13
13
|
|
14
14
|
</body>
|
15
15
|
</html>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wechat-handler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.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
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '4.2'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: wechat-validation
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0.2'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0.2'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: wechat-validator
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -77,11 +63,15 @@ files:
|
|
77
63
|
- MIT-LICENSE
|
78
64
|
- README.md
|
79
65
|
- Rakefile
|
66
|
+
- app/assets/config/wechat-handler_manifest.js
|
80
67
|
- app/assets/javascripts/wechat/handler/application.js
|
81
68
|
- app/assets/stylesheets/wechat/handler/application.css
|
82
69
|
- app/controllers/wechat/handler/application_controller.rb
|
83
70
|
- app/controllers/wechat/handler/concerns/dispatcher.rb
|
84
71
|
- app/helpers/wechat/handler/application_helper.rb
|
72
|
+
- app/jobs/wechat/handler/application_job.rb
|
73
|
+
- app/mailers/wechat/handler/application_mailer.rb
|
74
|
+
- app/models/wechat/handler/application_record.rb
|
85
75
|
- app/views/layouts/wechat/handler/application.html.erb
|
86
76
|
- config/routes.rb
|
87
77
|
- lib/tasks/handler_tasks.rake
|