wework 1.1.7 → 1.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -3
- data/lib/wework/api/provider.rb +9 -0
- data/lib/wework/api/suite.rb +2 -26
- data/lib/wework/cipher.rb +24 -0
- data/lib/wework/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57af16b2481bed88541d3f155b87adf4dd26a8b28999bce6c5b20a3c2d2fcc23
|
4
|
+
data.tar.gz: 39176c04e1e0daf24538dd046d81b0b66e7b9da8d09c374cda4023122dbcb465
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2d714537b289270b8195517e14de67ba332f501c2082764de8f5e59f9663bbd26b87d737199116f827632d93b7bcd2f6c2cbd2b9bf77ce44d1b55bc1013acb1
|
7
|
+
data.tar.gz: 5d2ad8d2925e1b679b07823c90e056f43ef3c191b8417970af1b15880281ec58ad5973befc8d30d0ecaa4eddc0ee0a4db106feeeeef0a407109d25fe126c24a3
|
data/README.md
CHANGED
@@ -108,17 +108,22 @@ $contact_api = Wework::Api::Contact.new(
|
|
108
108
|
)
|
109
109
|
```
|
110
110
|
|
111
|
-
### 应用服务商接口
|
111
|
+
### 应用服务商接口
|
112
112
|
|
113
113
|
初始化
|
114
114
|
|
115
115
|
``` ruby
|
116
116
|
$provider_api = Wework::Api::Provider.new(
|
117
|
-
corp_id: ENV['WEWORK_PROVIDER_CORPID'],
|
118
|
-
secret: ENV['WEWORK_PROVIDER_SECRET']
|
117
|
+
corp_id: ENV['WEWORK_PROVIDER_CORPID'], # 应用服务商 CorpID
|
118
|
+
secret: ENV['WEWORK_PROVIDER_SECRET'], # Secret
|
119
|
+
token: ENV['WEWORK_PROVIDER_TOKEN'],
|
120
|
+
encoding_aes_key: ENV['WEWORK_PROVIDER_ENCODING_AES_KEY']
|
119
121
|
)
|
120
122
|
```
|
121
123
|
|
124
|
+
回调接口消息加解密参考「第三方应用回调协议」
|
125
|
+
|
126
|
+
|
122
127
|
### 小程序 encryptedData 解密
|
123
128
|
|
124
129
|
```ruby
|
data/lib/wework/api/provider.rb
CHANGED
@@ -2,6 +2,15 @@ module Wework
|
|
2
2
|
module Api
|
3
3
|
class Provider < Base
|
4
4
|
include Methods::Provider
|
5
|
+
include Wework::Cipher
|
6
|
+
|
7
|
+
attr_reader :encoding_aes_key, :token
|
8
|
+
|
9
|
+
def initialize(options={})
|
10
|
+
@token = options.delete(:token)
|
11
|
+
@encoding_aes_key = options.delete(:encoding_aes_key)
|
12
|
+
super(options)
|
13
|
+
end
|
5
14
|
|
6
15
|
private
|
7
16
|
|
data/lib/wework/api/suite.rb
CHANGED
@@ -7,40 +7,16 @@ module Wework
|
|
7
7
|
include Wework::Cipher
|
8
8
|
include Methods::Service
|
9
9
|
|
10
|
-
attr_reader :encoding_aes_key, :suite_id, :suite_secret, :suite_token
|
10
|
+
attr_reader :encoding_aes_key, :suite_id, :suite_secret, :suite_token, :token
|
11
11
|
|
12
12
|
def initialize(options={})
|
13
13
|
@suite_id = options.delete(:suite_id)
|
14
14
|
@suite_secret = options.delete(:suite_secret)
|
15
|
-
@suite_token = options.delete(:suite_token)
|
15
|
+
@token = @suite_token = options.delete(:suite_token)
|
16
16
|
@encoding_aes_key = options.delete(:encoding_aes_key)
|
17
17
|
super(options)
|
18
18
|
end
|
19
19
|
|
20
|
-
def msg_decrypt message
|
21
|
-
unpack(decrypt(Base64.decode64(message), encoding_aes_key))[0]
|
22
|
-
end
|
23
|
-
|
24
|
-
def msg_encrypt message
|
25
|
-
Base64.strict_encode64(encrypt(pack(message, corp_id), encoding_aes_key))
|
26
|
-
end
|
27
|
-
|
28
|
-
def signature(timestamp, nonce, encrypt)
|
29
|
-
array = [suite_token, timestamp, nonce]
|
30
|
-
array << encrypt unless encrypt.nil?
|
31
|
-
Digest::SHA1.hexdigest array.compact.collect(&:to_s).sort.join
|
32
|
-
end
|
33
|
-
|
34
|
-
def generate_xml(msg, timestamp, nonce)
|
35
|
-
encrypt = msg_encrypt(msg)
|
36
|
-
{
|
37
|
-
Encrypt: encrypt,
|
38
|
-
MsgSignature: signature(timestamp, nonce, encrypt),
|
39
|
-
TimeStamp: timestamp,
|
40
|
-
Nonce: nonce
|
41
|
-
}.to_xml(root: 'xml', children: 'item', skip_instruct: true, skip_types: true)
|
42
|
-
end
|
43
|
-
|
44
20
|
def suite_ticket= ticket
|
45
21
|
Wework.redis.set ticket_key, ticket
|
46
22
|
end
|
data/lib/wework/cipher.rb
CHANGED
@@ -54,6 +54,30 @@ module Wework
|
|
54
54
|
[content, app_id]
|
55
55
|
end
|
56
56
|
|
57
|
+
def msg_decrypt message
|
58
|
+
unpack(decrypt(Base64.decode64(message), encoding_aes_key))[0]
|
59
|
+
end
|
60
|
+
|
61
|
+
def msg_encrypt message
|
62
|
+
Base64.strict_encode64(encrypt(pack(message, corp_id), encoding_aes_key))
|
63
|
+
end
|
64
|
+
|
65
|
+
def signature(timestamp, nonce, encrypt)
|
66
|
+
array = [token, timestamp, nonce]
|
67
|
+
array << encrypt unless encrypt.nil?
|
68
|
+
Digest::SHA1.hexdigest array.compact.collect(&:to_s).sort.join
|
69
|
+
end
|
70
|
+
|
71
|
+
def generate_xml(msg, timestamp, nonce)
|
72
|
+
encrypt = msg_encrypt(msg)
|
73
|
+
{
|
74
|
+
Encrypt: encrypt,
|
75
|
+
MsgSignature: signature(timestamp, nonce, encrypt),
|
76
|
+
TimeStamp: timestamp,
|
77
|
+
Nonce: nonce
|
78
|
+
}.to_xml(root: 'xml', children: 'item', skip_instruct: true, skip_types: true)
|
79
|
+
end
|
80
|
+
|
57
81
|
private
|
58
82
|
|
59
83
|
def encode_padding(data)
|
data/lib/wework/version.rb
CHANGED