Commit 2fc068e688b13ff9e9cc729a3ff38be9a73b78d4
1 parent
e80aed8c
Exists in
master
ADD: corp secret integration
Showing
1 changed file
with
13 additions
and
1 deletions
Show diff stats
lib/dingtalk/api/base.rb
... | ... | @@ -14,7 +14,11 @@ module Dingtalk |
14 | 14 | end |
15 | 15 | |
16 | 16 | def set_access_token |
17 | - Suite.new.set_corp_access_token(@corp.corp_id, @corp.permanent_code) | |
17 | + if @corp.isv_mode? | |
18 | + Suite.new.set_corp_access_token(@corp.corp_id, @corp.permanent_code) | |
19 | + elsif !@corp.corp_secret.nil? | |
20 | + set_corp_access_token | |
21 | + end | |
18 | 22 | end |
19 | 23 | |
20 | 24 | def js_ticket |
... | ... | @@ -22,6 +26,14 @@ module Dingtalk |
22 | 26 | ticket.to_s.empty? ? set_js_ticket : ticket |
23 | 27 | end |
24 | 28 | |
29 | + def set_corp_access_token | |
30 | + res = http_get("gettoken?corpid=#{@corp.corp_id}&corpsecret=#{@corp.corp_secret}") | |
31 | + key = "#{@corp.corp_id}_#{ACCESS_TOKEN}" | |
32 | + redis.set(key, res['access_token']) | |
33 | + redis.expire(key, 6600) | |
34 | + redis.get(key) | |
35 | + end | |
36 | + | |
25 | 37 | def set_js_ticket |
26 | 38 | key = "#{@corp.corp_id}_#{JS_TICKET}" |
27 | 39 | res = http_get("get_jsapi_ticket?access_token=#{access_token}") | ... | ... |