qywechat-notifier 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +20 -0
- data/LICENSE.txt +21 -0
- data/README.md +106 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/exception_notifier/qy_wechat_notifier.rb +50 -0
- data/lib/qywechat/notifier/qy_api/api/message.rb +20 -0
- data/lib/qywechat/notifier/qy_api/api/token.rb +24 -0
- data/lib/qywechat/notifier/qy_api/client.rb +110 -0
- data/lib/qywechat/notifier/qy_api/errors.rb +21 -0
- data/lib/qywechat/notifier/qy_api.rb +20 -0
- data/lib/qywechat/notifier/version.rb +5 -0
- data/lib/qywechat/notifier.rb +12 -0
- data/lib/qywechat/railtie.rb +5 -0
- data/lib/qywechat-notifier.rb +3 -0
- data/lib/tasks/create_groupchat.rake +24 -0
- data/qywechat-notifier.gemspec +27 -0
- metadata +92 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 68563940ee548620b221f26b8aa537982418cf062a6271ed8cacccb06ba73f07
|
4
|
+
data.tar.gz: '024985d77aa5efe3a0d93e5a831662f0bcd08bad00dbf5d2981c7e9d0e9dbfb1'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3a13d0b05f11967f791a2aa013a7324871d0884e8d49cd3a1b230cdd89d7fbae6ec8f5e65f57fe91fc47462ed392b835cde7d35b79bc6ca50f259f1fde77a6be
|
7
|
+
data.tar.gz: fab808dd730c420445c5f96243fbd6e8575f944a265cd43ec9ee1c57100383b963e2e587329c476b6c03148a8c2725c9b8d0361bdd201fbbfa702ebf81613c69
|
data/.gitignore
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 chen1125he@163.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,20 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
qywechat-notifier (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
rake (10.5.0)
|
10
|
+
|
11
|
+
PLATFORMS
|
12
|
+
ruby
|
13
|
+
|
14
|
+
DEPENDENCIES
|
15
|
+
bundler (~> 2.0)
|
16
|
+
qywechat-notifier!
|
17
|
+
rake (~> 10.0)
|
18
|
+
|
19
|
+
BUNDLED WITH
|
20
|
+
2.0.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 yunyi
|
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,106 @@
|
|
1
|
+
# Qywechat::Notifier
|
2
|
+
|
3
|
+
为你的 Rails 应用添加企业微信异常监控。
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your Rails application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'qywechat-notifier', github: 'dao42/qywechat-notifier'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
### 创建群聊会话
|
20
|
+
|
21
|
+
系统提供了 Rake 命令,帮助快速创建一个会话
|
22
|
+
|
23
|
+
```bash
|
24
|
+
$ rails create_groupchat
|
25
|
+
```
|
26
|
+
|
27
|
+
请按照引导创建群聊,创建成功后系统会发送一条消息,初始至少需要一位群主和一位群员。后续可手动去企业微信APP中添加其他成员。
|
28
|
+
|
29
|
+
记录好 CHATID。
|
30
|
+
|
31
|
+
### 配置
|
32
|
+
|
33
|
+
创建配置文件,并修改配置项。
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
# config/initializers/qywechat_notifier.rb
|
37
|
+
Qywechat::Notifier.configure do |config|
|
38
|
+
config.corpid = 'yourcorpid'
|
39
|
+
config.corpsecret = 'yourcorpsecret'
|
40
|
+
config.chatid = 'yourchatid'
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
各参数配置的含义:
|
45
|
+
|
46
|
+
CORPID: 参见[说明](https://work.weixin.qq.com/api/doc#90000/90135/90665)
|
47
|
+
|
48
|
+
CORPSECRET: 参见[说明](https://work.weixin.qq.com/api/doc#90000/90135/90665)
|
49
|
+
|
50
|
+
CHATID: 上面用 Rake 命令创建的群聊ID,参见[说明](https://work.weixin.qq.com/api/doc#90000/90135/90245)
|
51
|
+
|
52
|
+
### 配置 exception_notification,启用插件
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
# config/initializers/exception_notification.rb
|
56
|
+
require 'exception_notification/rails'
|
57
|
+
require 'exception_notification/sidekiq'
|
58
|
+
|
59
|
+
ExceptionNotification.configure do |config|
|
60
|
+
...
|
61
|
+
...
|
62
|
+
config.add_notifier :qy_wechat, {}
|
63
|
+
end
|
64
|
+
```
|
65
|
+
|
66
|
+
### 完成
|
67
|
+
|
68
|
+
到此,所有 Rails 应用异常都可以发送到群聊之中了。
|
69
|
+
|
70
|
+
## 定制异常内容
|
71
|
+
|
72
|
+
额外异常内容,可写入 `request.env['exception_notifier.exception_data']` 中,如:
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
# app/controllers/application_controller.rb
|
76
|
+
class ApplicationController < ActionController::Base
|
77
|
+
|
78
|
+
# 增加以下内容
|
79
|
+
before_action :prepare_exception_notifier
|
80
|
+
|
81
|
+
private
|
82
|
+
def prepare_exception_notifier
|
83
|
+
request.env['exception_notifier.exception_data'] = {
|
84
|
+
current_user: current_user&.id
|
85
|
+
}
|
86
|
+
end
|
87
|
+
end
|
88
|
+
```
|
89
|
+
|
90
|
+
## Development
|
91
|
+
|
92
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
93
|
+
|
94
|
+
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).
|
95
|
+
|
96
|
+
## Contributing
|
97
|
+
|
98
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/qywechat-notifier. 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.
|
99
|
+
|
100
|
+
## License
|
101
|
+
|
102
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
103
|
+
|
104
|
+
## Code of Conduct
|
105
|
+
|
106
|
+
Everyone interacting in the Qywechat::Notifier project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/qywechat-notifier/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 "qywechat/notifier"
|
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,50 @@
|
|
1
|
+
require 'qywechat/notifier'
|
2
|
+
|
3
|
+
module ExceptionNotifier
|
4
|
+
class QyWechatNotifier < BaseNotifier
|
5
|
+
def initialize(options)
|
6
|
+
super
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(exception, options={})
|
10
|
+
env = options[:env]
|
11
|
+
|
12
|
+
if env.present?
|
13
|
+
# 这里是外部请求导致的异常
|
14
|
+
request = ActionDispatch::Request.new(env)
|
15
|
+
request_items = {
|
16
|
+
url: request.original_url,
|
17
|
+
http_method: request.method,
|
18
|
+
ip_address: request.remote_ip,
|
19
|
+
parameters: request.filtered_parameters,
|
20
|
+
timestamp: Time.current.strftime('%Y-%m-%d %H:%M:%S')
|
21
|
+
}
|
22
|
+
|
23
|
+
message = <<-EOF
|
24
|
+
Exception>>> #{exception.class.to_s}: #{exception.message.inspect}
|
25
|
+
URL>>> #{request_items[:http_method]}: #{request_items[:url]}( from: #{request_items[:ip_address]} )
|
26
|
+
PARAM>>> #{request_items[:parameters]}
|
27
|
+
Agent>>> #{request.filtered_env['HTTP_USER_AGENT']}
|
28
|
+
Data>>> #{env && env['exception_notifier.exception_data']}
|
29
|
+
------------
|
30
|
+
Backtrace( 5 below )>>>\n
|
31
|
+
#{exception.backtrace[0..4].join("\n")}
|
32
|
+
EOF
|
33
|
+
|
34
|
+
Qywechat::Notifier::QyAPI.api_message.send_groupchat(message)
|
35
|
+
else
|
36
|
+
# 内部异常, 例如 sidekiq 任务
|
37
|
+
message = <<-EOF
|
38
|
+
Exception>>> #{exception.class.to_s}: #{exception.message.inspect}
|
39
|
+
OPTIONS>>> \n
|
40
|
+
#{options.to_yaml}
|
41
|
+
------------
|
42
|
+
Backtrace( 5 below )>>>\n
|
43
|
+
#{exception.backtrace[0..4].join("\n")}
|
44
|
+
EOF
|
45
|
+
|
46
|
+
Qywechat::Notifier::QyAPI.api_message.send_groupchat(message)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Qywechat::Notifier::QyAPI
|
2
|
+
module API
|
3
|
+
class Message
|
4
|
+
attr_reader :client
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@client = Client.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def send_groupchat(message)
|
11
|
+
client.post('/cgi-bin/appchat/send', params: { access_token: Qywechat::Notifier::QyAPI.api_token.get_access_token }, json: {
|
12
|
+
chatid: Qywechat::Notifier::QyAPI.chatid,
|
13
|
+
msgtype: 'text',
|
14
|
+
text: { content: message },
|
15
|
+
safe: 0
|
16
|
+
})
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Qywechat::Notifier::QyAPI
|
2
|
+
module API
|
3
|
+
class Token
|
4
|
+
attr_reader :client
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@client = Client.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_access_token
|
11
|
+
Rails.cache.fetch('exception_notifier::qy_wechat_notifier', expires_in: 6800.seconds) do
|
12
|
+
refresh_access_token
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def refresh_access_token
|
19
|
+
res = client.get('/cgi-bin/gettoken', params: { corpid: Qywechat::Notifier::QyAPI.corpid, corpsecret: Qywechat::Notifier::QyAPI.corpsecret })
|
20
|
+
res["access_token"]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
module Qywechat
|
2
|
+
module Notifier
|
3
|
+
module QyAPI
|
4
|
+
class Client
|
5
|
+
SERVER_SCHEME = 'https'.freeze
|
6
|
+
SERVER_HOST = 'qyapi.weixin.qq.com'.freeze
|
7
|
+
|
8
|
+
def get(path, options = {})
|
9
|
+
request(:get, path, options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def post(path, options = {})
|
13
|
+
request(:post, path, options)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def request(verb, path, options = {})
|
19
|
+
uri = uri_for(path)
|
20
|
+
options = options.with_indifferent_access
|
21
|
+
|
22
|
+
options['headers'] ||= {}
|
23
|
+
if options['headers']['Content-Type'].blank?
|
24
|
+
options['headers']['Content-Type'] = 'application/json'
|
25
|
+
end
|
26
|
+
|
27
|
+
begin
|
28
|
+
response = HTTP.request(verb, uri, options)
|
29
|
+
rescue HTTP::Error => ex
|
30
|
+
raise Errors::HttpError, ex.message
|
31
|
+
end
|
32
|
+
|
33
|
+
unless response.status.success?
|
34
|
+
raise Errors::APIError.new(nil, response.to_s)
|
35
|
+
end
|
36
|
+
|
37
|
+
parse_response(response) do |parse_as, result|
|
38
|
+
case parse_as
|
39
|
+
when :json
|
40
|
+
break result if result[:errcode].blank? || result[:errcode].zero?
|
41
|
+
raise Errors::APIError.new(result[:errcode], result[:errmsg])
|
42
|
+
else
|
43
|
+
result
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def uri_for(path)
|
49
|
+
uri_options = {
|
50
|
+
scheme: SERVER_SCHEME,
|
51
|
+
host: SERVER_HOST,
|
52
|
+
path: path
|
53
|
+
}
|
54
|
+
Addressable::URI.new(uri_options)
|
55
|
+
end
|
56
|
+
|
57
|
+
def parse_response(response)
|
58
|
+
content_type = response.headers[:content_type]
|
59
|
+
parse_as = {
|
60
|
+
%r{^application\/json} => :json,
|
61
|
+
%r{^image\/.*} => :file,
|
62
|
+
%r{^text\/html} => :xml,
|
63
|
+
%r{^text\/plain} => :plain
|
64
|
+
}.each_with_object([]) { |match, memo| memo << match[1] if content_type =~ match[0] }.first || :plain
|
65
|
+
|
66
|
+
if parse_as == :plain
|
67
|
+
result = ActiveSupport::JSON.decode(response.body.to_s).with_indifferent_access rescue nil
|
68
|
+
if result
|
69
|
+
return yield(:json, result)
|
70
|
+
else
|
71
|
+
return yield(:plain, response.body)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
case parse_as
|
76
|
+
when :json
|
77
|
+
result = ActiveSupport::JSON.decode(response.body.to_s).with_indifferent_access
|
78
|
+
when :file
|
79
|
+
if %r{^image\/.*}.match?(response.headers[:content_type])
|
80
|
+
extension =
|
81
|
+
case response.headers['content-type']
|
82
|
+
when 'image/gif' then '.gif'
|
83
|
+
when 'image/jpeg' then '.jpg'
|
84
|
+
when 'image/png' then '.png'
|
85
|
+
end
|
86
|
+
else
|
87
|
+
extension = ''
|
88
|
+
end
|
89
|
+
|
90
|
+
begin
|
91
|
+
file = Tempfile.new(['wxapi-file-', extension])
|
92
|
+
file.binmode
|
93
|
+
file.write(response.body)
|
94
|
+
ensure
|
95
|
+
file&.close
|
96
|
+
end
|
97
|
+
|
98
|
+
result = file
|
99
|
+
when :xml
|
100
|
+
result = Hash.from_xml(response.body.to_s)
|
101
|
+
else
|
102
|
+
result = response.body
|
103
|
+
end
|
104
|
+
|
105
|
+
yield(parse_as, result)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Qywechat::Notifier::QyAPI
|
2
|
+
module Errors
|
3
|
+
# 通用异常
|
4
|
+
Error = Class.new(StandardError)
|
5
|
+
|
6
|
+
# HTTP 异常,比如请求超时等
|
7
|
+
HttpError = Class.new(Error)
|
8
|
+
|
9
|
+
# API 异常,比如返回失败状态码
|
10
|
+
class APIError < Error
|
11
|
+
attr_reader :errcode, :errmsg
|
12
|
+
|
13
|
+
def initialize(errcode, errmsg)
|
14
|
+
@errcode = errcode
|
15
|
+
@errmsg = errmsg
|
16
|
+
|
17
|
+
super(format('[%s]: %s', @errcode, @errmsg))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'qywechat/notifier/qy_api/client'
|
2
|
+
require 'qywechat/notifier/qy_api/errors'
|
3
|
+
require 'qywechat/notifier/qy_api/api/message'
|
4
|
+
require 'qywechat/notifier/qy_api/api/token'
|
5
|
+
|
6
|
+
module Qywechat
|
7
|
+
module Notifier
|
8
|
+
module QyAPI
|
9
|
+
def self.api_token
|
10
|
+
@api_token ||= QyAPI::API::Token.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.api_message
|
14
|
+
@api_message ||= QyAPI::API::Message.new
|
15
|
+
end
|
16
|
+
|
17
|
+
mattr_accessor :corpid, :chatid, :corpsecret
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'qywechat/notifier'
|
2
|
+
|
3
|
+
task create_groupchat: :environment do
|
4
|
+
raise '请先填写群 ID' unless Qywechat::Notifier::QyAPI.chatid.present?
|
5
|
+
puts('请输入群聊名:')
|
6
|
+
name = STDIN.gets().gsub(/\r\n|\n/, '')
|
7
|
+
raise '群聊名不能为空' unless name.present?
|
8
|
+
puts('请输入群主名:')
|
9
|
+
owner = STDIN.gets().gsub(/\r\n|\n/, '')
|
10
|
+
raise '群主名不能为空' unless owner.present?
|
11
|
+
puts('请输入一个群员名(额外的群员可在新创建的群内直接添加):')
|
12
|
+
username = STDIN.gets().gsub(/\r\n|\n/, '')
|
13
|
+
raise '群员名不能为空' unless username.present?
|
14
|
+
userlist = [owner, username]
|
15
|
+
|
16
|
+
client = Qywechat::Notifier::QyAPI::Client.new
|
17
|
+
client.post('/cgi-bin/appchat/create', params: { access_token: Qywechat::Notifier::QyAPI.api_token.get_access_token }, json: {
|
18
|
+
chatid: Qywechat::Notifier::QyAPI.chatid,
|
19
|
+
name: name,
|
20
|
+
owner: owner,
|
21
|
+
userlist: userlist
|
22
|
+
})
|
23
|
+
Qywechat::Notifier::QyAPI.api_message.send_groupchat('create groupchat ok')
|
24
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "qywechat/notifier/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "qywechat-notifier"
|
8
|
+
spec.version = Qywechat::Notifier::VERSION
|
9
|
+
spec.authors = ["yunyi"]
|
10
|
+
spec.email = ["chen1125he@163.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{qywechat exception notifier}
|
13
|
+
spec.homepage = "https://github.com/80percent/qywechat-notifier"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Specify which files should be added to the gem when it is released.
|
17
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
end
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: qywechat-notifier
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- yunyi
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-05-23 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: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
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
|
+
description:
|
42
|
+
email:
|
43
|
+
- chen1125he@163.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- CODE_OF_CONDUCT.md
|
50
|
+
- Gemfile
|
51
|
+
- Gemfile.lock
|
52
|
+
- LICENSE.txt
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- bin/console
|
56
|
+
- bin/setup
|
57
|
+
- lib/exception_notifier/qy_wechat_notifier.rb
|
58
|
+
- lib/qywechat-notifier.rb
|
59
|
+
- lib/qywechat/notifier.rb
|
60
|
+
- lib/qywechat/notifier/qy_api.rb
|
61
|
+
- lib/qywechat/notifier/qy_api/api/message.rb
|
62
|
+
- lib/qywechat/notifier/qy_api/api/token.rb
|
63
|
+
- lib/qywechat/notifier/qy_api/client.rb
|
64
|
+
- lib/qywechat/notifier/qy_api/errors.rb
|
65
|
+
- lib/qywechat/notifier/version.rb
|
66
|
+
- lib/qywechat/railtie.rb
|
67
|
+
- lib/tasks/create_groupchat.rake
|
68
|
+
- qywechat-notifier.gemspec
|
69
|
+
homepage: https://github.com/80percent/qywechat-notifier
|
70
|
+
licenses:
|
71
|
+
- MIT
|
72
|
+
metadata: {}
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubygems_version: 3.0.3
|
89
|
+
signing_key:
|
90
|
+
specification_version: 4
|
91
|
+
summary: qywechat exception notifier
|
92
|
+
test_files: []
|