yol_qy_weixin 0.0.3 → 0.0.8
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 +4 -4
- data/.gitignore +3 -0
- data/Gemfile.lock +3 -3
- data/README.md +71 -70
- data/lib/yol_qy_weixin/client.rb +4 -2
- data/lib/yol_qy_weixin/connections/base.rb +16 -20
- data/lib/yol_qy_weixin/connections/department.rb +17 -0
- data/lib/yol_qy_weixin/connections/message.rb +15 -0
- data/lib/yol_qy_weixin/connections/user.rb +16 -0
- data/lib/yol_qy_weixin/version.rb +1 -1
- data/yol_qy_weixin.gemspec +3 -3
- metadata +7 -7
- data/.DS_Store +0 -0
- data/lib/.DS_Store +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c3296070570a8d242429f4760872498d01b4155403847934e10e406bf91bf17
|
4
|
+
data.tar.gz: d251b119311c4561e461b64048d224be817a20a51c9539bca0653be959853d3d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4401f01855e21bb4663085604a075b80d5e38be6844c1d3fe0cfee8f190a00858ce1d07de239bfd32566178cd3bb8d68eb6c088eeab74247185b4a54fa44e4b0
|
7
|
+
data.tar.gz: 5d5e0e83e5ba92d7c0375dc7327c77b7b0f6aec0914e69955a4434efa2232df1ee05cb80d689e95a2ad31fd7da0b47fe7ffbc80cb631ad70d3ccbe994bb4aa20
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
yol_qy_weixin (0.0.
|
4
|
+
yol_qy_weixin (0.0.8)
|
5
5
|
multi_xml
|
6
6
|
nokogiri
|
7
7
|
roxml
|
@@ -16,11 +16,11 @@ GEM
|
|
16
16
|
tzinfo (~> 1.1)
|
17
17
|
zeitwerk (~> 2.2, >= 2.2.2)
|
18
18
|
concurrent-ruby (1.1.8)
|
19
|
-
i18n (1.8.
|
19
|
+
i18n (1.8.10)
|
20
20
|
concurrent-ruby (~> 1.0)
|
21
21
|
minitest (5.14.4)
|
22
22
|
multi_xml (0.6.0)
|
23
|
-
nokogiri (1.11.
|
23
|
+
nokogiri (1.11.3-x86_64-darwin)
|
24
24
|
racc (~> 1.4)
|
25
25
|
racc (1.5.2)
|
26
26
|
rake (13.0.1)
|
data/README.md
CHANGED
@@ -6,120 +6,121 @@ https://rubygems.org/gems/yol_qy_weixin
|
|
6
6
|
|
7
7
|
[](http://badge.fury.io/rb/yol_qy_weixin)
|
8
8
|
|
9
|
-
**企业号对应多个管理组,请前往 `设置` => `权限管理` 任意创建一个管理组,在管理组最下角即可获取 CorpID Secret**
|
10
|
-
|
11
9
|
**有问题请及时提issue**
|
12
10
|
|
13
11
|
```ruby
|
14
|
-
gem "
|
12
|
+
gem "yol_qy_weixin", git: "https://github.com/luojie2019/yol_qy_weixin.git"
|
15
13
|
```
|
16
14
|
|
17
15
|
# 配置
|
18
16
|
|
19
|
-
##
|
20
|
-
|
17
|
+
## 安装依赖Installation
|
18
|
+
|
19
|
+
Add this line to your application's Gemfile:
|
20
|
+
|
21
21
|
```ruby
|
22
|
-
|
23
|
-
config.cache_store = YourCustomCacheStore
|
24
|
-
end
|
22
|
+
gem 'yol_qy_weixin'
|
25
23
|
```
|
26
|
-
|
24
|
+
## 配置 corpid secret
|
27
25
|
|
28
|
-
## 日志配置
|
29
|
-
如果你是在Rails框架下,默认情况下直接使用Rails.logger,如果你想独立cache,请配置如下:
|
30
26
|
```ruby
|
31
|
-
|
32
|
-
config.logger = YourCustomLogger
|
33
|
-
end
|
34
|
-
```
|
35
|
-
logger按照Rails.logger的接口实现,强烈建议使用ActiveSupport::Logger
|
27
|
+
# 目录
|
36
28
|
|
37
|
-
|
29
|
+
file: your_project/config/qy_weixin.yml
|
38
30
|
|
39
|
-
|
40
|
-
|
31
|
+
.your_project/
|
32
|
+
├── app
|
33
|
+
├── bin
|
34
|
+
├── config
|
35
|
+
│ ├── redis.yml
|
36
|
+
│ ├── database.yml
|
37
|
+
│ ├── qy_weixin.yml
|
38
|
+
```
|
41
39
|
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
```yml
|
41
|
+
defaults: &defaults
|
42
|
+
corpid: '1**'
|
43
|
+
secret: '2**'
|
44
|
+
|
45
|
+
development: &development
|
46
|
+
<<: *defaults
|
45
47
|
|
46
|
-
|
48
|
+
test:
|
49
|
+
<<: *defaults
|
47
50
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
+
production:
|
52
|
+
corpid: <%= ENV.fetch('QY_WEIXIN_CORPID') { '1**'' } %>
|
53
|
+
secret: <%= ENV.fetch('QY_WEIXIN_SECRET') { '2**'' } %>
|
54
|
+
```
|
51
55
|
|
52
|
-
|
56
|
+
**说明:考虑access_token需要缓存,redis配置请参考官方文档 https://github.com/redis/redis-rb/blob/master/README.md**
|
53
57
|
|
54
|
-
|
55
|
-
|
56
|
-
|
58
|
+
## 读取配置
|
59
|
+
```ruby
|
60
|
+
# 读取qy_weixin.yml配置
|
61
|
+
qy_weixin_config = YAML::load(ERB.new(File.read("#{Rails.root}/config/qy_weixin.yml")).result)[Rails.env]
|
57
62
|
```
|
63
|
+
如果你是在Rails框架下,也可以使用Settingslogic读取yml配置:
|
64
|
+
```ruby
|
65
|
+
# 引用gem
|
66
|
+
gem 'settingslogic', '2.0.9'
|
58
67
|
|
59
|
-
#
|
68
|
+
# your_project/app/settings/weixin_setting.rb
|
69
|
+
class WeixinSetting < Settingslogic
|
70
|
+
source "#{Rails.root}/config/weixin.yml"
|
71
|
+
namespace Rails.env
|
72
|
+
end
|
60
73
|
|
61
|
-
|
74
|
+
corpid = WeixinSetting.corpid
|
75
|
+
corp_secret = WeixinSetting.secret
|
76
|
+
```
|
62
77
|
|
63
|
-
##
|
78
|
+
## 实例对象
|
64
79
|
|
65
80
|
```ruby
|
66
|
-
|
81
|
+
# 目录 file: your_project/config/initializers/qy_weixin.rb
|
67
82
|
|
68
|
-
|
69
|
-
|
83
|
+
QyWexinClient = YolQyWeixin::Client.new(
|
84
|
+
corpid: qy_weixin_config["corpid"],
|
85
|
+
secret: qy_weixin_config["secret"],
|
86
|
+
redis: RedisClient
|
87
|
+
)
|
70
88
|
```
|
71
89
|
|
72
|
-
|
73
|
-
|
90
|
+
**说明:RedisClient为redis实例,如果没有配置可传nil,建议使用redis,考虑到access_token获取次数限制;**
|
91
|
+
|
92
|
+
# 基本用法
|
93
|
+
|
94
|
+
如果需要获取的 access_token
|
74
95
|
|
75
96
|
```ruby
|
76
|
-
|
77
|
-
#
|
78
|
-
group_client = QyWechatApi::Client.new(corpid, corpsecret, options)
|
97
|
+
access_token = QyWexinClient.get_access_token
|
98
|
+
# 返回参考企业微信官方文档:https://work.weixin.qq.com/api/doc/90000/90135/91039
|
79
99
|
```
|
80
100
|
|
81
101
|
## 部门
|
82
102
|
|
83
103
|
```ruby
|
84
|
-
|
85
|
-
group_client.department.update(id, name, parent_id, order=nil)
|
86
|
-
group_client.department.delete(id)
|
87
|
-
group_client.department.list
|
104
|
+
待补充,有需要可提issue到git:https://github.com/luojie2019/yol_qy_weixin.git
|
88
105
|
```
|
89
106
|
|
90
107
|
## 成员
|
91
108
|
|
92
109
|
```ruby
|
93
|
-
#
|
94
|
-
|
95
|
-
|
96
|
-
# 更新成员
|
97
|
-
group_client.user.update(user_id, options={})
|
110
|
+
# 获取成员信息
|
111
|
+
access_token = QyWexinClient.get_user_info(open_id)
|
112
|
+
# 返回参考企业微信官方文档:https://open.work.weixin.qq.com/api/doc/90000/90135/90196
|
98
113
|
|
99
|
-
#
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
group_client.user.batch_delete(user_ids)
|
104
|
-
|
105
|
-
# 获取成员
|
106
|
-
group_client.user.get(user_id)
|
107
|
-
|
108
|
-
# 获取部门成员
|
109
|
-
group_client.user.simple_list(department_id, fetch_child=nil, status=nil)
|
114
|
+
# 获取反问用户信息
|
115
|
+
access_token = QyWexinClient.get_user_id(code)
|
116
|
+
# 返回参考企业微信官方文档:https://open.work.weixin.qq.com/api/doc/90000/90135/91707
|
117
|
+
```
|
110
118
|
|
111
|
-
# 获取部门成员(详情)
|
112
|
-
group_client.user.full_list(department_id, fetch_child=nil, status=nil)
|
113
119
|
|
114
|
-
|
115
|
-
group_client.user.send_invitation(user_id, tips=nil)
|
120
|
+
---
|
116
121
|
|
117
|
-
# userid转换成openid接口(企业支付需要使用到)
|
118
|
-
group_client.covert_to_open_id(user_id, agent_id="")
|
119
122
|
|
120
|
-
|
121
|
-
group_client.covert_to_user_id(open_id)
|
122
|
-
```
|
123
|
+
后续功能实现还待优化,有需要可提issue到git:https://github.com/luojie2019/yol_qy_weixin.git
|
123
124
|
|
124
125
|
## 标签
|
125
126
|
|
data/lib/yol_qy_weixin/client.rb
CHANGED
@@ -8,7 +8,9 @@ module YolQyWeixin
|
|
8
8
|
include Connection::Qrcode
|
9
9
|
include Connection::Template
|
10
10
|
include Connection::User
|
11
|
-
|
11
|
+
include Connection::Department
|
12
|
+
include Connection::Message
|
13
|
+
|
12
14
|
attr_accessor :corpid, :secret, :redis
|
13
15
|
|
14
16
|
def initialize(options = {})
|
@@ -17,4 +19,4 @@ module YolQyWeixin
|
|
17
19
|
@redis = options[:redis] || YolQyWeixin.configuration.redis
|
18
20
|
end
|
19
21
|
end
|
20
|
-
end
|
22
|
+
end
|
@@ -18,26 +18,22 @@ module YolQyWeixin
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def get_access_token
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
# access_token
|
39
|
-
access_token_res = get_token(corpid, secret)
|
40
|
-
access_token = access_token_res["access_token"] rescue nil
|
21
|
+
if redis.nil?
|
22
|
+
access_token_res = get_token(corpid, secret)
|
23
|
+
access_token = access_token_res["access_token"] rescue nil
|
24
|
+
else
|
25
|
+
access_token = redis.get("qywx_access_token")
|
26
|
+
if access_token.nil?
|
27
|
+
access_token_res = get_token(corpid, secret)
|
28
|
+
access_token = access_token_res["access_token"] rescue nil
|
29
|
+
if access_token.nil?
|
30
|
+
raise Exception.new("QyWeixin access token authorize false, corpid: #{corpid}")
|
31
|
+
else
|
32
|
+
redis.set("qywx_access_token", access_token)
|
33
|
+
redis.expire("qywx_access_token", 7200)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
41
37
|
access_token
|
42
38
|
end
|
43
39
|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module YolQyWeixin
|
2
|
+
module Connection
|
3
|
+
module Department
|
4
|
+
def department_list(department_id=0)
|
5
|
+
http_get(department_list_url(department_id))
|
6
|
+
end
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def department_list_url(department_id)
|
13
|
+
"https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=#{get_access_token}&id=#{department_id}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module YolQyWeixin
|
2
|
+
module Connection
|
3
|
+
module Message
|
4
|
+
def send_message(body)
|
5
|
+
http_post(send_url, body)
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def send_url
|
11
|
+
"https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=#{get_access_token}&debug=1"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -1,12 +1,28 @@
|
|
1
1
|
module YolQyWeixin
|
2
2
|
module Connection
|
3
3
|
module User
|
4
|
+
def get_users_by_department(department_id, fetch_child=0)
|
5
|
+
http_get(get_users_by_department_url(department_id, fetch_child))
|
6
|
+
end
|
7
|
+
|
8
|
+
def get_user_id(code)
|
9
|
+
http_get(user_info_url(open_id))
|
10
|
+
end
|
11
|
+
|
4
12
|
def get_user_info(open_id)
|
5
13
|
http_get(user_info_url(open_id))
|
6
14
|
end
|
7
15
|
|
8
16
|
private
|
9
17
|
|
18
|
+
def get_users_by_department_url(department_id, fetch_child)
|
19
|
+
"https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token=#{get_access_token}&department_id=#{department_id}&fetch_child=#{fetch_child}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def user_id_url(code)
|
23
|
+
"https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?access_token=#{get_access_token}&code=#{code}"
|
24
|
+
end
|
25
|
+
|
10
26
|
def user_info_url(open_id)
|
11
27
|
"https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token=#{get_access_token}&userid=#{open_id}"
|
12
28
|
end
|
data/yol_qy_weixin.gemspec
CHANGED
@@ -6,11 +6,11 @@ require 'yol_qy_weixin/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "yol_qy_weixin"
|
8
8
|
spec.version = YolQyWeixin::VERSION
|
9
|
-
spec.authors = ["
|
10
|
-
spec.email = ["
|
9
|
+
spec.authors = ["luojie2019"]
|
10
|
+
spec.email = ["luojie@yolanda.hk"]
|
11
11
|
spec.summary = %q{Shop middleware for Weixin.}
|
12
12
|
spec.description = ""
|
13
|
-
spec.homepage = ""
|
13
|
+
spec.homepage = "https://github.com/luojie2019/yol_qy_weixin"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yol_qy_weixin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- luojie2019
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-05-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -82,23 +82,23 @@ dependencies:
|
|
82
82
|
version: '0'
|
83
83
|
description: ''
|
84
84
|
email:
|
85
|
-
-
|
85
|
+
- luojie@yolanda.hk
|
86
86
|
executables: []
|
87
87
|
extensions: []
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
|
-
- ".DS_Store"
|
91
90
|
- ".gitignore"
|
92
91
|
- Gemfile
|
93
92
|
- Gemfile.lock
|
94
93
|
- LICENSE.txt
|
95
94
|
- README.md
|
96
95
|
- Rakefile
|
97
|
-
- lib/.DS_Store
|
98
96
|
- lib/yol_qy_weixin.rb
|
99
97
|
- lib/yol_qy_weixin/client.rb
|
100
98
|
- lib/yol_qy_weixin/connection.rb
|
101
99
|
- lib/yol_qy_weixin/connections/base.rb
|
100
|
+
- lib/yol_qy_weixin/connections/department.rb
|
101
|
+
- lib/yol_qy_weixin/connections/message.rb
|
102
102
|
- lib/yol_qy_weixin/connections/qrcode.rb
|
103
103
|
- lib/yol_qy_weixin/connections/template.rb
|
104
104
|
- lib/yol_qy_weixin/connections/user.rb
|
@@ -109,7 +109,7 @@ files:
|
|
109
109
|
- lib/yol_qy_weixin/models/message.rb
|
110
110
|
- lib/yol_qy_weixin/version.rb
|
111
111
|
- yol_qy_weixin.gemspec
|
112
|
-
homepage:
|
112
|
+
homepage: https://github.com/luojie2019/yol_qy_weixin
|
113
113
|
licenses:
|
114
114
|
- MIT
|
115
115
|
metadata: {}
|
data/.DS_Store
DELETED
Binary file
|
data/lib/.DS_Store
DELETED
Binary file
|