Commit 32dd5f4b63413e3533029861f50c632ecbdbfae9

Authored by Jeff Lai
1 parent 9c6b3253
Exists in master

Add aes_key to config & client shortcut

Showing 2 changed files with 29 additions and 1 deletions   Show diff stats
lib/dingtalk/client.rb 0 → 100644
@@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
  1 +module Dingtalk
  2 + class Client
  3 + attr_accessor :corp_id
  4 +
  5 + def initialize(corp_id)
  6 + @corp_id = corp_id
  7 + end
  8 +
  9 + def decrypt(echo_str)
  10 + aes_key = Base64.decode64(Dingtalk.suite_aes_key + '=')
  11 + content, status = Dingtalk::Prpcrypt.decrypt(aes_key, echo_str, Dingtalk.suite_key)
  12 + # TODO check status
  13 + JSON.parse(content)
  14 + end
  15 +
  16 + def suite
  17 + Api::Suite.new
  18 + end
  19 +
  20 + def department
  21 + Api::Department.new(@corp_id)
  22 + end
  23 + end
  24 +end
lib/dingtalk/config.rb
@@ -18,9 +18,13 @@ module Dingtalk @@ -18,9 +18,13 @@ module Dingtalk
18 def suite_secret 18 def suite_secret
19 @suite_secret ||= config.suite_secret 19 @suite_secret ||= config.suite_secret
20 end 20 end
  21 +
  22 + def suite_aes_key
  23 + @suite_aes_key ||= config.suite_aes_key
  24 + end
21 end 25 end
22 26
23 class Config 27 class Config
24 - attr_accessor :redis, :redis_options, :suite_key, :suite_secret 28 + attr_accessor :redis, :redis_options, :suite_key, :suite_secret, :suite_aes_key
25 end 29 end
26 end 30 end