easy_wechat 0.1.2 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +7 -0
- data/lib/easy_wechat/client.rb +45 -37
- data/lib/easy_wechat/version.rb +1 -1
- data/lib/generators/easy_wechat/install_generator.rb +20 -0
- data/lib/generators/templates/initializer.rb +4 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48872ad0294d2609473c5b7481f600d9fa254ce2ecae297ff46199a3c70b96ef
|
4
|
+
data.tar.gz: 5aed6510ce796d43370a23e3be8fbcd051c0c23b4ba3c2d2d43af2c21442367a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84edf00b30e5af1c4dd9b697b98b9f40d84e26a33ba2b3941448e2576e9423d9670aaa1efe073e1e401a76c54b95a5f0ac3e9cd1662674d8db77498d73d1d8cc
|
7
|
+
data.tar.gz: 3813a75d9e4d8a5c4bf5847f68dce1ed701714831cad1a0b2408acfdd80d7ccd2fc894de101f0965ecf943a91b787336349afd1a00497aadfcb811060fe0bf20
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -23,6 +23,8 @@ Or install it yourself as:
|
|
23
23
|
## Usage
|
24
24
|
|
25
25
|
```
|
26
|
+
rails g easy_wechat:install
|
27
|
+
|
26
28
|
EasyWechat.configure do |config|
|
27
29
|
config.appid = ENV.fetch("APPID") || ""
|
28
30
|
config.app_secret = ENV.fetch("APP_SECRET") || ""
|
@@ -37,6 +39,11 @@ client.get_user_summary(begin_date, end_date)
|
|
37
39
|
client.get_user_cumulate(begin_date, end_date)
|
38
40
|
```
|
39
41
|
|
42
|
+
## FAQ
|
43
|
+
1. 微信api,请求方式有问题,也会报错,所以要注意请求方式
|
44
|
+
2. 先搞清楚你的appid对应的公众号是什么,并且搞清楚你是什么类型的,查看接口权限是否获得,否则有可能会有类似48001的权限未开通错误
|
45
|
+
3. 调用api之前,请确保ip已经加入到服务器白名单
|
46
|
+
|
40
47
|
## Development
|
41
48
|
|
42
49
|
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.
|
data/lib/easy_wechat/client.rb
CHANGED
@@ -11,6 +11,7 @@ module EasyWechat
|
|
11
11
|
ADD_NEWS_URL = "https://api.weixin.qq.com/cgi-bin/material/add_news"
|
12
12
|
GET_USER_SUMMARY_URL = "https://api.weixin.qq.com/datacube/getusersummary"
|
13
13
|
GET_USER_CUMULATE_URL = "https://api.weixin.qq.com/datacube/getusercumulate"
|
14
|
+
GET_TICKET_URL = "https://api.weixin.qq.com/cgi-bin/ticket/getticket"
|
14
15
|
|
15
16
|
def initialize
|
16
17
|
end
|
@@ -53,47 +54,54 @@ module EasyWechat
|
|
53
54
|
r
|
54
55
|
end
|
55
56
|
|
57
|
+
# 新增永久图文素材
|
58
|
+
# https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Adding_Permanent_Assets.html
|
59
|
+
def add_news(articles)
|
60
|
+
payload = { articles: articles }
|
61
|
+
|
62
|
+
resp = HTTPX.post(ADD_NEWS_URL, params: { access_token: access_token }, json: payload)
|
63
|
+
|
64
|
+
r = ::JSON.parse(resp.body, quirks_mode: true)
|
65
|
+
yield r if block_given?
|
66
|
+
r
|
67
|
+
end
|
68
|
+
|
69
|
+
def get_ticket(type)
|
70
|
+
resp = HTTPX.get(GET_TICKET_URL, params: { access_token: access_token, type: type })
|
71
|
+
|
72
|
+
r = ::JSON.parse(resp.body, quirks_mode: true)
|
73
|
+
yield r if block_given?
|
74
|
+
r
|
75
|
+
end
|
76
|
+
|
77
|
+
# 获取永久素材的列表
|
78
|
+
# https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Get_materials_list.html
|
79
|
+
def batchget_material(type = "image", offset = 0, count = 20)
|
80
|
+
# TODO: 检查参数完整性
|
81
|
+
# TODO: 检查参数合法性
|
82
|
+
payload = { type: type, offset: offset, count: count }
|
83
|
+
|
84
|
+
resp = HTTPX.post(BATCHGET_MATERIAL_URL, params: { access_token: access_token }, json: payload)
|
85
|
+
|
86
|
+
r = ::JSON.parse(resp.body, quirks_mode: true)
|
87
|
+
yield r if block_given?
|
88
|
+
r
|
89
|
+
end
|
90
|
+
|
56
91
|
# 上传图文消息内的图片获取URL
|
57
92
|
# https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Adding_Permanent_Assets.html
|
58
93
|
def uploadimg(media)
|
59
94
|
# https://honeyryderchuck.gitlab.io/httpx/wiki/Multipart-Uploads.html#notes
|
60
|
-
file =
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
def batchget_material(type = "image", offset = 0, count = 20)
|
71
|
-
# TODO: 检查参数完整性
|
72
|
-
# TODO: 检查参数合法性
|
73
|
-
payload = { type: type, offset: offset, count: count }
|
74
|
-
|
75
|
-
resp = HTTPX.post(BATCHGET_MATERIAL_URL, params: { access_token: access_token }, json: payload)
|
76
|
-
|
77
|
-
r = ::JSON.parse(resp.body, quirks_mode: true)
|
78
|
-
yield r if block_given?
|
79
|
-
r
|
80
|
-
end
|
81
|
-
|
82
|
-
# 新增永久图文素材
|
83
|
-
# https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Adding_Permanent_Assets.html
|
84
|
-
def add_news(articles)
|
85
|
-
payload = { articles: articles }
|
86
|
-
|
87
|
-
resp = HTTPX.post(ADD_NEWS_URL, params: { access_token: access_token }, json: payload)
|
88
|
-
|
89
|
-
r = ::JSON.parse(resp.body, quirks_mode: true)
|
90
|
-
yield r if block_given?
|
91
|
-
r
|
92
|
-
end
|
93
|
-
|
94
|
-
def menu_create
|
95
|
-
raise NotImplementedError
|
96
|
-
end
|
95
|
+
file = media.is_a?(String) ? HTTP::FormData::File.new(media) : media
|
96
|
+
resp = HTTPX.plugin(:multipart).post(UPLOADIMG_URL, params: { access_token: access_token }, form: { media: file })
|
97
|
+
|
98
|
+
r = ::JSON.parse(resp.body, quirks_mode: true)
|
99
|
+
yield r if block_given?
|
100
|
+
r
|
101
|
+
end
|
102
|
+
|
103
|
+
def menu_create
|
104
|
+
raise NotImplementedError
|
97
105
|
end
|
98
106
|
end
|
99
107
|
end
|
data/lib/easy_wechat/version.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
module EasyWechat
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
desc "EasyWechat installation: initializer"
|
5
|
+
source_root File.expand_path("../../templates", __FILE__)
|
6
|
+
|
7
|
+
def install
|
8
|
+
puts "==> generate initializer file ..."
|
9
|
+
copy_initializer
|
10
|
+
puts "Done!"
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def copy_initializer
|
16
|
+
template "initializer.rb", "config/initializers/easy_wechat.rb"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
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.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 42up
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-07-
|
11
|
+
date: 2021-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httpx
|
@@ -130,6 +130,8 @@ files:
|
|
130
130
|
- lib/easy_wechat/client.rb
|
131
131
|
- lib/easy_wechat/configuration.rb
|
132
132
|
- lib/easy_wechat/version.rb
|
133
|
+
- lib/generators/easy_wechat/install_generator.rb
|
134
|
+
- lib/generators/templates/initializer.rb
|
133
135
|
homepage: https://github.com/42up/easy_wechat
|
134
136
|
licenses:
|
135
137
|
- MIT
|