diff --git a/lib/dingtalk/client.rb b/lib/dingtalk/client.rb index 0964f03..c454a17 100644 --- a/lib/dingtalk/client.rb +++ b/lib/dingtalk/client.rb @@ -7,12 +7,17 @@ module Dingtalk end def decrypt(echo_str) - aes_key = Base64.decode64(Dingtalk.suite_aes_key + '=') content, status = Dingtalk::Prpcrypt.decrypt(aes_key, echo_str, Dingtalk.suite_key) # TODO check status JSON.parse(content) end + def signature(return_str) + encrypt = Dingtalk::Prpcrypt.encrypt(aes_key, return_str, Dingtalk.suite_key) + sort_params = [suite.suite_access_token, timestamp, nonce, encrypt].sort.join + Digest::SHA1.hexdigest(sort_params) + end + def suite Api::Suite.new end @@ -20,5 +25,18 @@ module Dingtalk def department Api::Department.new(@corp_id) end + + private + def aes_key + Base64.decode64(Dingtalk.suite_aes_key + '=') + end + + def timestamp + Time.now.to_i.to_s + end + + def nonce + SecureRandom.hex + end end end -- libgit2 0.21.0