Commit 6cf4eedc6056c11f8da1ea2b31c2de63b65f558f
1 parent
c9a22383
Exists in
master
添加client storage
Showing
2 changed files
with
23 additions
and
1 deletions
Show diff stats
lib/qy_wechat_api/client.rb
... | ... | @@ -3,11 +3,22 @@ |
3 | 3 | module QyWechatApi |
4 | 4 | class Client |
5 | 5 | attr_accessor :corp_id, :group_secret, :expired_at # Time.now + expires_in |
6 | - attr_accessor :access_token | |
6 | + attr_accessor :access_token, :redis_key, :storage | |
7 | 7 | |
8 | 8 | def initialize(corp_id, group_secret, redis_key=nil) |
9 | 9 | @corp_id = corp_id |
10 | 10 | @group_secret = group_secret |
11 | + @redis_key = security_redis_key((redis_key || "qy_" + group_secret)) | |
12 | + end | |
13 | + | |
14 | + # return token | |
15 | + def get_access_token | |
16 | + @storage.access_token | |
17 | + end | |
18 | + | |
19 | + # 检查appid和app_secret是否有效。 | |
20 | + def is_valid? | |
21 | + @storage.valid? | |
11 | 22 | end |
12 | 23 | |
13 | 24 | # 管理部门API |
... | ... | @@ -53,5 +64,9 @@ module QyWechatApi |
53 | 64 | QyWechatApi.http_get_without_token("/gettoken", params) |
54 | 65 | end |
55 | 66 | |
67 | + def security_redis_key(key) | |
68 | + Digest::MD5.hexdigest(key.to_s).upcase | |
69 | + end | |
70 | + | |
56 | 71 | end |
57 | 72 | end | ... | ... |