easy_wechat 0.1.1 → 0.1.2
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/Gemfile.lock +4 -2
- data/README.md +8 -0
- data/easy_wechat.gemspec +1 -0
- data/lib/easy_wechat/client.rb +50 -28
- data/lib/easy_wechat/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d8066f4397a6645cdae6c9bc9dc2ae40784fe181cfaaef40a6319ce5e78cac3
|
4
|
+
data.tar.gz: 64b7c2dbe69defa80b0b1cbb762d0a2cb6c0cb1ba579b2ffb3f738d31c05e08d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 695251db24a4baf01027b369165a8d6dbb18c054594f330c4ff8950c52b2330ac669a18c5ebf65068a13ee6a36c36f128508c990c399c990b5bf88032bd0b03c
|
7
|
+
data.tar.gz: e2297653663ddf218abbbf69ce0c13a5a9c95b13a4fcb4829ccd20dd8d650814da287078bc70242183d12671ae0fa9d29f120b5f9f85ed36c654ad16adaaf7a8
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
easy_wechat (0.1.
|
4
|
+
easy_wechat (0.1.2)
|
5
5
|
activesupport
|
6
|
+
http-form_data
|
6
7
|
httpx
|
7
8
|
|
8
9
|
GEM
|
@@ -18,7 +19,8 @@ GEM
|
|
18
19
|
concurrent-ruby (1.1.9)
|
19
20
|
diff-lcs (1.4.4)
|
20
21
|
http-2-next (0.4.3)
|
21
|
-
|
22
|
+
http-form_data (2.3.0)
|
23
|
+
httpx (0.15.3)
|
22
24
|
http-2-next (>= 0.4.1)
|
23
25
|
timers
|
24
26
|
i18n (1.8.10)
|
data/README.md
CHANGED
@@ -27,6 +27,14 @@ EasyWechat.configure do |config|
|
|
27
27
|
config.appid = ENV.fetch("APPID") || ""
|
28
28
|
config.app_secret = ENV.fetch("APP_SECRET") || ""
|
29
29
|
end
|
30
|
+
|
31
|
+
client = EasyWechat::Client.new
|
32
|
+
client.token
|
33
|
+
client.batchget_material
|
34
|
+
client.uploadimg(media)
|
35
|
+
client.add_news(articles)
|
36
|
+
client.get_user_summary(begin_date, end_date)
|
37
|
+
client.get_user_cumulate(begin_date, end_date)
|
30
38
|
```
|
31
39
|
|
32
40
|
## Development
|
data/easy_wechat.gemspec
CHANGED
data/lib/easy_wechat/client.rb
CHANGED
@@ -9,6 +9,8 @@ module EasyWechat
|
|
9
9
|
BATCHGET_MATERIAL_URL = "https://api.weixin.qq.com/cgi-bin/material/batchget_material"
|
10
10
|
UPLOADIMG_URL = "https://api.weixin.qq.com/cgi-bin/media/uploadimg"
|
11
11
|
ADD_NEWS_URL = "https://api.weixin.qq.com/cgi-bin/material/add_news"
|
12
|
+
GET_USER_SUMMARY_URL = "https://api.weixin.qq.com/datacube/getusersummary"
|
13
|
+
GET_USER_CUMULATE_URL = "https://api.weixin.qq.com/datacube/getusercumulate"
|
12
14
|
|
13
15
|
def initialize
|
14
16
|
end
|
@@ -17,6 +19,26 @@ module EasyWechat
|
|
17
19
|
@access_token ||= token["access_token"]
|
18
20
|
end
|
19
21
|
|
22
|
+
def get_user_summary(begin_date, end_date)
|
23
|
+
payload = { begin_date: begin_date, end_date: end_date }
|
24
|
+
|
25
|
+
resp = HTTPX.post(GET_USER_SUMMARY_URL, params: { access_token: access_token }, json: payload)
|
26
|
+
|
27
|
+
r = ::JSON.parse(resp.body, quirks_mode: true)
|
28
|
+
yield r if block_given?
|
29
|
+
r
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_user_cumulate(begin_date, end_date)
|
33
|
+
payload = { begin_date: begin_date, end_date: end_date }
|
34
|
+
|
35
|
+
resp = HTTPX.post(GET_USER_CUMULATE_URL, params: { access_token: access_token }, json: payload)
|
36
|
+
|
37
|
+
r = ::JSON.parse(resp.body, quirks_mode: true)
|
38
|
+
yield r if block_given?
|
39
|
+
r
|
40
|
+
end
|
41
|
+
|
20
42
|
# 获取access_token
|
21
43
|
# https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Get_access_token.html
|
22
44
|
def token
|
@@ -36,42 +58,42 @@ module EasyWechat
|
|
36
58
|
def uploadimg(media)
|
37
59
|
# https://honeyryderchuck.gitlab.io/httpx/wiki/Multipart-Uploads.html#notes
|
38
60
|
file = if media.is_a?(String) ? HTTP::FormData::File.new(media) : meida
|
61
|
+
resp = HTTPX.plugin(:multipart).post(UPLOADIMG_URL, params: { access_token: access_token }, form: { media: file })
|
39
62
|
|
40
|
-
|
63
|
+
r = ::JSON.parse(resp.body, quirks_mode: true)
|
64
|
+
yield r if block_given?
|
65
|
+
r
|
66
|
+
end
|
41
67
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
68
|
+
# 获取永久素材的列表
|
69
|
+
# https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Get_materials_list.html
|
70
|
+
def batchget_material(type = "image", offset = 0, count = 20)
|
71
|
+
# TODO: 检查参数完整性
|
72
|
+
# TODO: 检查参数合法性
|
73
|
+
payload = { type: type, offset: offset, count: count }
|
46
74
|
|
47
|
-
|
48
|
-
# https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Get_materials_list.html
|
49
|
-
def batchget_material(type = "image", offset = 0, count = 20)
|
50
|
-
# TODO: 检查参数完整性
|
51
|
-
# TODO: 检查参数合法性
|
52
|
-
payload = { type: type, offset: offset, count: count }
|
75
|
+
resp = HTTPX.post(BATCHGET_MATERIAL_URL, params: { access_token: access_token }, json: payload)
|
53
76
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
r
|
59
|
-
end
|
77
|
+
r = ::JSON.parse(resp.body, quirks_mode: true)
|
78
|
+
yield r if block_given?
|
79
|
+
r
|
80
|
+
end
|
60
81
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
82
|
+
# 新增永久图文素材
|
83
|
+
# https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Adding_Permanent_Assets.html
|
84
|
+
def add_news(articles)
|
85
|
+
payload = { articles: articles }
|
65
86
|
|
66
|
-
|
87
|
+
resp = HTTPX.post(ADD_NEWS_URL, params: { access_token: access_token }, json: payload)
|
67
88
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
89
|
+
r = ::JSON.parse(resp.body, quirks_mode: true)
|
90
|
+
yield r if block_given?
|
91
|
+
r
|
92
|
+
end
|
72
93
|
|
73
|
-
|
74
|
-
|
94
|
+
def menu_create
|
95
|
+
raise NotImplementedError
|
96
|
+
end
|
75
97
|
end
|
76
98
|
end
|
77
99
|
end
|
data/lib/easy_wechat/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy_wechat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 42up
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httpx
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: http-form_data
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: bundler
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|