dingtalktool 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +59 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/dingtalktool.gemspec +39 -0
- data/filecache.yml +1 -0
- data/lib/dingtalktool.rb +34 -0
- data/lib/dingtalktool/attendance_service.rb +30 -0
- data/lib/dingtalktool/auth_service.rb +60 -0
- data/lib/dingtalktool/cache_service.rb +76 -0
- data/lib/dingtalktool/chat_service.rb +20 -0
- data/lib/dingtalktool/configuration.rb +15 -0
- data/lib/dingtalktool/department_service.rb +30 -0
- data/lib/dingtalktool/http_service.rb +40 -0
- data/lib/dingtalktool/log_service.rb +19 -0
- data/lib/dingtalktool/message_service.rb +18 -0
- data/lib/dingtalktool/user_service.rb +23 -0
- data/lib/dingtalktool/version.rb +3 -0
- data/my.log +1 -0
- metadata +140 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bab772daeafd5d6452b208713111534c455fd08381b6a216af9d706c6ab648e7
|
4
|
+
data.tar.gz: 32bf9ac444875ad818d039ea698dd8719c1ae4019cfb3b3a678a8d6894d0a4e1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 235db52a704fbe09fea9429c253773dabfa23df12ad226344d32b56551fd8240dde9f3071166f5e79df18bf186db5e958bfc2e43f9e9f9b8cb9cbb637cd75db4
|
7
|
+
data.tar.gz: 3f1a583e062a743539795e553a23f9997831f3b8de1714eec4d5876dcd86e5322a9bdaa83ea7365c2931134373519112424b48924d211ef536f7bd36e3b57e70
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at Chunliang.Liu@abcam.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
dingtalktool (1.0.0)
|
5
|
+
rest-client
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
coderay (1.1.2)
|
11
|
+
diff-lcs (1.3)
|
12
|
+
domain_name (0.5.20190701)
|
13
|
+
unf (>= 0.0.5, < 1.0.0)
|
14
|
+
http-accept (1.7.0)
|
15
|
+
http-cookie (1.0.3)
|
16
|
+
domain_name (~> 0.5)
|
17
|
+
method_source (0.9.2)
|
18
|
+
mime-types (3.3)
|
19
|
+
mime-types-data (~> 3.2015)
|
20
|
+
mime-types-data (3.2019.1009)
|
21
|
+
netrc (0.11.0)
|
22
|
+
pry (0.11.3)
|
23
|
+
coderay (~> 1.1.0)
|
24
|
+
method_source (~> 0.9.0)
|
25
|
+
rake (10.5.0)
|
26
|
+
rest-client (2.1.0)
|
27
|
+
http-accept (>= 1.7.0, < 2.0)
|
28
|
+
http-cookie (>= 1.0.2, < 2.0)
|
29
|
+
mime-types (>= 1.16, < 4.0)
|
30
|
+
netrc (~> 0.8)
|
31
|
+
rspec (3.7.0)
|
32
|
+
rspec-core (~> 3.7.0)
|
33
|
+
rspec-expectations (~> 3.7.0)
|
34
|
+
rspec-mocks (~> 3.7.0)
|
35
|
+
rspec-core (3.7.1)
|
36
|
+
rspec-support (~> 3.7.0)
|
37
|
+
rspec-expectations (3.7.0)
|
38
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
39
|
+
rspec-support (~> 3.7.0)
|
40
|
+
rspec-mocks (3.7.0)
|
41
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
+
rspec-support (~> 3.7.0)
|
43
|
+
rspec-support (3.7.1)
|
44
|
+
unf (0.1.4)
|
45
|
+
unf_ext
|
46
|
+
unf_ext (0.0.7.6)
|
47
|
+
|
48
|
+
PLATFORMS
|
49
|
+
ruby
|
50
|
+
|
51
|
+
DEPENDENCIES
|
52
|
+
bundler (~> 1.16)
|
53
|
+
dingtalktool!
|
54
|
+
pry
|
55
|
+
rake (~> 10.0)
|
56
|
+
rspec (~> 3.0)
|
57
|
+
|
58
|
+
BUNDLED WITH
|
59
|
+
1.17.3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 liuchunliang
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Dingtalktool
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/dingtalktool`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'dingtalktool'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install dingtalktool
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/dingtalktool. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
|
+
|
41
|
+
## Code of Conduct
|
42
|
+
|
43
|
+
Everyone interacting in the Dingtalktool project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/dingtalktool/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "dingtalktool"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "dingtalktool/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "dingtalktool"
|
8
|
+
spec.version = Dingtalktool::VERSION
|
9
|
+
spec.authors = ["liuchunliang"]
|
10
|
+
spec.email = ["Chunliang.Liu@abcam.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Ding API.}
|
13
|
+
spec.description = %q{提供钉钉开发服务端API.}
|
14
|
+
spec.homepage = "http://www.liuxiaodao.top"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
36
|
+
spec.add_development_dependency "pry"
|
37
|
+
|
38
|
+
spec.add_dependency "rest-client"
|
39
|
+
end
|
data/filecache.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"corp_access_token":{"corp_access_token":"8190da179494368db97e76265852856b","expire_time":1571198008,"create_time":1571191008}}
|
data/lib/dingtalktool.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require "dingtalktool/version"
|
2
|
+
require "dingtalktool/configuration"
|
3
|
+
require "dingtalktool/http_service"
|
4
|
+
require "dingtalktool/log_service"
|
5
|
+
require "dingtalktool/cache_service"
|
6
|
+
require "dingtalktool/auth_service"
|
7
|
+
require "dingtalktool/chat_service"
|
8
|
+
require "dingtalktool/department_service"
|
9
|
+
require "dingtalktool/message_service"
|
10
|
+
require "dingtalktool/user_service"
|
11
|
+
require "dingtalktool/attendance_service"
|
12
|
+
|
13
|
+
begin
|
14
|
+
require "pry"
|
15
|
+
rescue LoadError
|
16
|
+
end
|
17
|
+
|
18
|
+
module Dingtalktool
|
19
|
+
class << self
|
20
|
+
attr_writer :configuration
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.configuration
|
24
|
+
@configuration ||= Dingtalktool::Configuration.new
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.reset
|
28
|
+
@configuration = Dingtalktool::Configuration.new
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.configure
|
32
|
+
yield(configuration)
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Dingtalktool
|
2
|
+
class AttendanceService
|
3
|
+
# data = {
|
4
|
+
# "userIds": [1, 2, 3],
|
5
|
+
# "checkDateFrom": "2019-10-11 00:00:00",
|
6
|
+
# "checkDateTo": "2019-10-12 00:00:00",
|
7
|
+
# "isI18n": "false"
|
8
|
+
# }
|
9
|
+
# listRecord(accessToken,data)
|
10
|
+
# 获取打卡详情
|
11
|
+
def self.listRecord(accessToken, opt)
|
12
|
+
response = HttpService.post("/attendance/listRecord",{access_token: accessToken}, opt.to_json)
|
13
|
+
return response
|
14
|
+
end
|
15
|
+
|
16
|
+
# data = {
|
17
|
+
# "workDateFrom": "2019-10-11 00:00:00",
|
18
|
+
# "workDateTo": "2019-10-11 00:00:00",
|
19
|
+
# "userIdList": [1, 2, 3],
|
20
|
+
# "offset": 0,
|
21
|
+
# "limit": 1
|
22
|
+
# }
|
23
|
+
# listRecord(accessToken,data)
|
24
|
+
# 获取打卡结果
|
25
|
+
def self.list(accessToken, opt)
|
26
|
+
response = HttpService.post("/attendance/list",{access_token: accessToken}, opt.to_json)
|
27
|
+
return response
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Dingtalktool
|
2
|
+
class AuthService
|
3
|
+
def self.configuration
|
4
|
+
Dingtalktool::configuration
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.getAccessToken
|
8
|
+
# 缓存accessToken。accessToken有效期为两小时,需要在失效前请求新的accessToken(注意:以下代码没有在失效前刷新缓存的accessToken)。
|
9
|
+
accessToken = CacheService::getCorpAccessToken() #nil, false, "token"
|
10
|
+
if accessToken.nil? || !accessToken
|
11
|
+
response = HttpService.get('/gettoken?', {corpid: configuration.corpid, corpsecret: configuration.secret})
|
12
|
+
check(response)
|
13
|
+
accessToken = response['access_token']
|
14
|
+
CacheService::setCorpAccessToken(accessToken)
|
15
|
+
end
|
16
|
+
return accessToken
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
def self.getTicket(accessToken)
|
21
|
+
jsticket = CacheService::getJsTicket()
|
22
|
+
if jsticket.nil? || !jsticket
|
23
|
+
response = HttpService.get('/get_jsapi_ticket?', {type: 'jsapi', access_token: accessToken})
|
24
|
+
check(response)
|
25
|
+
jsticket = response['ticket']
|
26
|
+
CacheService::setJsTicket(jsticket)
|
27
|
+
end
|
28
|
+
return jsticket
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.getConfig(href)
|
32
|
+
corpId = configuration.corpid
|
33
|
+
agentId = configuration.agentid
|
34
|
+
nonceStr = 'abcdefg'
|
35
|
+
timeStamp = Time.now.to_i
|
36
|
+
url = href
|
37
|
+
corpAccessToken = getAccessToken()
|
38
|
+
if corpAccessToken.nil? || !corpAccessToken
|
39
|
+
LogService.e("[getConfig] ERR: no corp access token")
|
40
|
+
end
|
41
|
+
ticket = getTicket(corpAccessToken)
|
42
|
+
signature = sign(ticket, nonceStr, timeStamp, url)
|
43
|
+
|
44
|
+
config = {'url' => url,'nonceStr' => nonceStr,'agentId' => agentId, 'timeStamp' => timeStamp, 'corpId' => corpId, 'signature' => signature}
|
45
|
+
return config
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.sign(ticket, nonceStr, timeStamp, url)
|
49
|
+
plain = "jsapi_ticket=#{ticket}&noncestr=#{nonceStr}×tamp=#{timeStamp}&url=#{url}"
|
50
|
+
return Digest::SHA1.hexdigest(plain);
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.check(res)
|
54
|
+
if res["errcode"] != 0
|
55
|
+
LogService.e("FAIL: #{res.to_json}")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
module Dingtalktool
|
3
|
+
class CacheService
|
4
|
+
|
5
|
+
def self.setJsTicket(ticket)
|
6
|
+
set("js_ticket", ticket, ex: 7000); # js ticket有效期为7200秒,这里设置为7000秒
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.getJsTicket()
|
10
|
+
return get("js_ticket")
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.setCorpAccessToken(accessToken)
|
14
|
+
set("corp_access_token", accessToken, ex: 7000) # corp access token有效期为7200秒,这里设置为7000秒
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.getCorpAccessToken
|
18
|
+
return get("corp_access_token")
|
19
|
+
end
|
20
|
+
|
21
|
+
# 保存变量
|
22
|
+
def self.set_value(name,value)
|
23
|
+
set(name, value)
|
24
|
+
end
|
25
|
+
# 使用变量
|
26
|
+
def self.get_value(name)
|
27
|
+
get(name)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.set(key,value,options = {})
|
31
|
+
ex = options[:ex] ? Time.now.to_i + options[:ex] : 0
|
32
|
+
if key && value
|
33
|
+
data = get_file("./filecache.yml")
|
34
|
+
|
35
|
+
item = {}
|
36
|
+
item["#{key}"] = value
|
37
|
+
item['expire_time'] = ex
|
38
|
+
item['create_time'] = Time.now.to_i
|
39
|
+
data["#{key}"] = item
|
40
|
+
set_file("./filecache.yml",data.to_json)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.get(key)
|
45
|
+
if key && key.is_a?(String)
|
46
|
+
data = get_file("./filecache.yml")
|
47
|
+
if !data.empty? && data.has_key?(key)
|
48
|
+
item = data["#{key}"]
|
49
|
+
return false if !item
|
50
|
+
if item['expire_time']>0 && item['expire_time'] < Time.now.to_i
|
51
|
+
return false;
|
52
|
+
end
|
53
|
+
return item["#{key}"]
|
54
|
+
else
|
55
|
+
return false;
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.get_file(filename)
|
61
|
+
if !File.exist?(filename)
|
62
|
+
file = File.open(filename, "w")
|
63
|
+
file.write("{}")
|
64
|
+
file.close
|
65
|
+
end
|
66
|
+
return YAML.load(File.read(filename))
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.set_file(filename, content)
|
70
|
+
file = File.open(filename, "w")
|
71
|
+
file.write(content)
|
72
|
+
file.close unless file.nil?
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Dingtalktool
|
2
|
+
class ChatService
|
3
|
+
|
4
|
+
def self.createChat(accessToken, chatOpt)
|
5
|
+
response = HttpService.post("/chat/create?", {access_token: accessToken}, chatOpt.to_json)
|
6
|
+
return response
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.bindChat(accessToken, chatid,agentid)
|
10
|
+
response = HttpService.get("/chat/bind?",{access_token: accessToken,chatid: chatid,agentid: agentid})
|
11
|
+
return response
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.sendmsg(accessToken, opt)
|
15
|
+
response = HttpService.post("/chat/send?", {access_token: accessToken}, opt.to_json)
|
16
|
+
return response
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Dingtalktool
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :oapi_host, :corpid, :secret, :agentid, :encoding_aes_key, :token
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@oapi_host = "https://oapi.dingtalk.com"
|
7
|
+
@corpid = ""
|
8
|
+
@secret = ""
|
9
|
+
|
10
|
+
@agentid = "" #必填,在创建微应用的时候会分配
|
11
|
+
@encoding_aes_key = "123456" #加解密需要用到的token,普通企业可以随机填写,例如:123456
|
12
|
+
@token = "111111111111111111111111111111111" #数据加密密钥。用于回调数据的加密,长度固定为43个字符,从a-z, A-Z, 0-9共62个字符中选取,您可以随机生成
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Dingtalktool
|
2
|
+
class DepartmentService
|
3
|
+
|
4
|
+
def self.createDept(accessToken, dept)
|
5
|
+
response = HttpService.post("/department/create?", {access_token: accessToken}, dept.to_json)
|
6
|
+
return response
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.listDept(accessToken)
|
10
|
+
response = HttpService.get("/department/list?", {access_token: accessToken})
|
11
|
+
return response
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.list_ids(accessToken)
|
15
|
+
response = HttpService.get("/department/list_ids?", {access_token: accessToken})
|
16
|
+
return response
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.department_info(accessToken)
|
20
|
+
response = HttpService.get("/department/get?", {access_token: accessToken,id: 66950253})
|
21
|
+
return response
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.deleteDept(accessToken, id)
|
25
|
+
response = HttpService.get("/department/delete?",{access_token: accessToken, id: id})
|
26
|
+
return response
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Dingtalktool
|
2
|
+
class HttpService
|
3
|
+
require 'net/https'
|
4
|
+
require 'uri'
|
5
|
+
require 'rest-client'
|
6
|
+
require 'json'
|
7
|
+
|
8
|
+
@@oapi_host = 'https://oapi.dingtalk.com'
|
9
|
+
|
10
|
+
def self.get(url,params)
|
11
|
+
uri = URI.parse("#{@@oapi_host}/#{url}?")
|
12
|
+
uri.query = URI.encode_www_form(params)
|
13
|
+
res = Net::HTTP.get_response(uri)
|
14
|
+
if res.code == "200"
|
15
|
+
return resbody = JSON.parse(res.body)
|
16
|
+
end
|
17
|
+
return nil
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.post(url, params, data)
|
21
|
+
res = RestClient.post joinParams(url, params), data, :content_type => :json, :accept => :json
|
22
|
+
if res.code == 200
|
23
|
+
return resbody = JSON.parse(res.body)
|
24
|
+
end
|
25
|
+
return nil
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.joinParams(path,params)
|
29
|
+
url = "#{@@oapi_host}#{path}"
|
30
|
+
if params.count > 0
|
31
|
+
url = url + "?"
|
32
|
+
params.each do |key,value|
|
33
|
+
url = url + key.to_s + "=" + value.to_s + "&";
|
34
|
+
end
|
35
|
+
url[-1] == "&" && url.chop!
|
36
|
+
end
|
37
|
+
return url
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Dingtalktool
|
2
|
+
class LogService
|
3
|
+
def self.i(msg)
|
4
|
+
write("I",msg)
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.e(msg)
|
8
|
+
write("E",msg)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.write(level,msg)
|
12
|
+
# TODO: 日志保存位置要修改
|
13
|
+
filename = "./my.log"
|
14
|
+
file = File.open(filename, "a")
|
15
|
+
file.write("#{level}/#{Time.now} #{msg}\n")
|
16
|
+
file.close
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Dingtalktool
|
2
|
+
class MessageService
|
3
|
+
def self.sendToConversation(accessToken, opt)
|
4
|
+
response = HttpService.post("/message/send_to_conversation?", {access_token: accessToken}, opt.to_json)
|
5
|
+
return response
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.send(accessToken, opt)
|
9
|
+
response = HttpService.post("/message/send",{access_token: accessToken}, opt.to_json)
|
10
|
+
return response
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.send_chat(accessToken, opt)
|
14
|
+
response = HttpService.post("/chat/send",{access_token: accessToken}, opt.to_json)
|
15
|
+
return response
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Dingtalktool
|
2
|
+
class UserService
|
3
|
+
def self.getUserInfo(accessToken, code)
|
4
|
+
response = HttpService.get("/user/getuserinfo", {access_token: accessToken, code: code});
|
5
|
+
return response;
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.get(accessToken, userId)
|
9
|
+
response = HttpService.get("/user/get", {access_token: accessToken, userid: userId});
|
10
|
+
return response;
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.simplelist(accessToken,deptId)
|
14
|
+
response = HttpService.get("/user/simplelist", {access_token: accessToken,department_id: deptId});
|
15
|
+
return response;
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.list(accessToken,deptId)
|
19
|
+
response = HttpService.get("/user/list", {access_token: accessToken,department_id: deptId})
|
20
|
+
return response
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/my.log
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
E/2019-10-15 12:43:17 +0800 FAIL: {"errcode":40035,"errmsg":"缺少参数 corpid or appkey"}
|
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dingtalktool
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- liuchunliang
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-10-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rest-client
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: 提供钉钉开发服务端API.
|
84
|
+
email:
|
85
|
+
- Chunliang.Liu@abcam.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- CODE_OF_CONDUCT.md
|
94
|
+
- Gemfile
|
95
|
+
- Gemfile.lock
|
96
|
+
- LICENSE.txt
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- bin/console
|
100
|
+
- bin/setup
|
101
|
+
- dingtalktool.gemspec
|
102
|
+
- filecache.yml
|
103
|
+
- lib/dingtalktool.rb
|
104
|
+
- lib/dingtalktool/attendance_service.rb
|
105
|
+
- lib/dingtalktool/auth_service.rb
|
106
|
+
- lib/dingtalktool/cache_service.rb
|
107
|
+
- lib/dingtalktool/chat_service.rb
|
108
|
+
- lib/dingtalktool/configuration.rb
|
109
|
+
- lib/dingtalktool/department_service.rb
|
110
|
+
- lib/dingtalktool/http_service.rb
|
111
|
+
- lib/dingtalktool/log_service.rb
|
112
|
+
- lib/dingtalktool/message_service.rb
|
113
|
+
- lib/dingtalktool/user_service.rb
|
114
|
+
- lib/dingtalktool/version.rb
|
115
|
+
- my.log
|
116
|
+
homepage: http://www.liuxiaodao.top
|
117
|
+
licenses:
|
118
|
+
- MIT
|
119
|
+
metadata:
|
120
|
+
allowed_push_host: https://rubygems.org
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
requirements: []
|
136
|
+
rubygems_version: 3.0.6
|
137
|
+
signing_key:
|
138
|
+
specification_version: 4
|
139
|
+
summary: Ding API.
|
140
|
+
test_files: []
|