wechat-callback 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: 784516913f2dc266d36ec588705804048e54c8be
4
- data.tar.gz: 8a0650c2c3945c8360b0c343f1c24730a06b4de8
3
+ metadata.gz: a6d866c6ff02037f220c42b497664f852ecde60f
4
+ data.tar.gz: 41a81672c3920de6822ccb57554d97d6c77c16f1
5
5
  SHA512:
6
- metadata.gz: 86ddcd1d24b0ba83ec596af16bbd1333816c2a771db1f5ea092165fe8bd4659861f938afc49253e14850354581800ad247df0b12fd2cead96c5ca91065208026
7
- data.tar.gz: 79c2656dd8a789c2c7495247e1ef36591f012bffc40fbcb9ba15e0ef82cb8c50a228bc01c16683e539f3c2c7815df3ecc3d3a1d11c06d33ec786859aa5672317
6
+ metadata.gz: 5128379e8b0edbbed039f7947c6ed4cb4450be89f4fffefae80d33b231e3fadc35ee582a81fc93ef93d1655264c3d1b285334f2230cc4394d584a0adf3a4589e
7
+ data.tar.gz: 08a025cd499b20325cdb42ae0159180ba83d35ae1ee2955a891aa1b15f688aaa281ff23a2569f514bcbf88d460ccfe590bc02b36d53169851543f5f6e83acf84
data/CHANGELOG.md CHANGED
@@ -1 +1,10 @@
1
1
  # Wechat Callback Change Log 微信回调库变更日志
2
+
3
+ ## v0.1
4
+ 1. Signature class
5
+ 2. Message Signature class
6
+ 3. XML Document class
7
+
8
+ ## v0.2
9
+ 1. Message Encryption class
10
+ 2. Message Decryption class
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Wechat::Callback
1
+ # Wechat Callback 微信回调库
2
2
 
3
3
  [![License](https://img.shields.io/badge/license-MIT-green.svg)](http://opensource.org/licenses/MIT)
4
4
  [![Gem Version](https://badge.fury.io/rb/wechat-callback.svg)](https://badge.fury.io/rb/wechat-callback)
@@ -24,7 +24,13 @@ Or install it yourself as:
24
24
 
25
25
  ## Usage
26
26
 
27
- TODO: Write usage instructions here
27
+ ```ruby
28
+ signature = Wechat::Callback::Signature.create token, timestamp, nonce, text_1, text_2, text_3
29
+ message_signature = Wechat::Callback::MessageSignature.create encoded_message, token, timestamp, nonce
30
+
31
+ xml_document = Wechat::Callback::XmlDocument.load '<xml><FromUserID>FUID</FromUserID></xml>'
32
+ xml_text = Wechat::Callback::XmlDocument.create FromUserID: 'FUID', ToUserID: 'TUID' # <xml><FromUserID>FUID</FromUserID><ToUserID>TUID</ToUserID></xml>
33
+ ```
28
34
 
29
35
  ## Development
30
36
 
data/ROADMAP.md CHANGED
@@ -1,14 +1,14 @@
1
1
  # Wechat Callback Road Map 微信回调库路线图
2
2
 
3
3
  ## v0.1
4
- - Signature class
5
- - Message Signature class
6
- - XML Document class
4
+ 1. Signature class
5
+ 2. Message Signature class
6
+ 3. XML Document class
7
7
 
8
8
  ## v0.2
9
- - Message Encryption class
10
- - Message Decryption class
9
+ 1. Message Encryption class
10
+ 2. Message Decryption class
11
11
 
12
12
  ## v0.3
13
- - Random Byte Array class
14
- - Secure Message class
13
+ 1. Random Byte Array class
14
+ 2. Secure Message class
@@ -4,6 +4,9 @@ require 'wechat/callback/message_signature'
4
4
  require 'wechat/callback/signature'
5
5
  require 'wechat/callback/xml_document'
6
6
 
7
+ require 'wechat/callback/message_decryption'
8
+ require 'wechat/callback/message_encryption'
9
+
7
10
  module Wechat
8
11
  module Callback
9
12
  # Your code goes here...
@@ -0,0 +1,24 @@
1
+ class Wechat::Callback::MessageDecryption
2
+
3
+ # 消息加解密
4
+ # http://mp.weixin.qq.com/wiki/6/90f7259c0d0739bbb41d9f4c4c8e59a2.html
5
+ #
6
+ # 解密方式如下:
7
+ # 1. aes_msg = Base64_Decode(msg_encrypt)
8
+ # 2. rand_msg = AES_Decrypt(aes_msg)
9
+ #
10
+ def self.create(encoded_message, encoded_aes_keys)
11
+
12
+ encrypted_message = Base64.decode64(encoded_message).bytes.inject('') do |buffer, byte| buffer += [ byte ].pack 'C' end
13
+ aes_keys = encoded_aes_keys.map { |encoded_aes_key| Base64.decode64 "#{encoded_aes_key}=" }
14
+
15
+ cipher = OpenSSL::Cipher::AES.new(256, 'CBC')
16
+ cipher.decrypt
17
+ cipher.padding = 0
18
+ cipher.key = aes_keys.first
19
+
20
+ cipher.update(encrypted_message)+cipher.final
21
+
22
+ end
23
+
24
+ end
@@ -0,0 +1,19 @@
1
+ class Wechat::Callback::MessageEncryption
2
+
3
+ # 消息加解密
4
+ # http://mp.weixin.qq.com/wiki/6/90f7259c0d0739bbb41d9f4c4c8e59a2.html
5
+ #
6
+ # AES密钥:AESKey=Base64_Decode(EncodingAESKey + “=”),EncodingAESKey尾部填充一个字符的“=”, 用Base64_Decode生成32个字节的AESKey
7
+ # msg_encrypt=Base64_Encode(AES_Encrypt [random(16B)+ msg_len(4B) + msg + $AppId])
8
+ def self.create(plain_text, encoded_aes_keys)
9
+
10
+ cipher = OpenSSL::Cipher::AES.new(256, 'CBC')
11
+ cipher.encrypt
12
+ cipher.padding = 0
13
+ cipher.key = Base64.decode64 "#{encoded_aes_keys.first}="
14
+
15
+ Base64.encode64 cipher.update(plain_text)+cipher.final
16
+
17
+ end
18
+
19
+ end
@@ -1,5 +1,5 @@
1
1
  module Wechat
2
2
  module Callback
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-callback
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: exe
10
10
  cert_chain: []
11
- date: 2016-02-15 00:00:00.000000000 Z
11
+ date: 2016-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -87,6 +87,8 @@ files:
87
87
  - bin/console
88
88
  - bin/setup
89
89
  - lib/wechat/callback.rb
90
+ - lib/wechat/callback/message_decryption.rb
91
+ - lib/wechat/callback/message_encryption.rb
90
92
  - lib/wechat/callback/message_signature.rb
91
93
  - lib/wechat/callback/signature.rb
92
94
  - lib/wechat/callback/version.rb