easy_wechat 0.1.0 → 0.1.1
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 +1 -1
- data/README.md +6 -1
- data/easy_wechat.gemspec +2 -2
- data/lib/easy_wechat.rb +27 -2
- data/lib/easy_wechat/client.rb +77 -0
- data/lib/easy_wechat/configuration.rb +10 -0
- data/lib/easy_wechat/version.rb +1 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0003f928b22948ff59d5f02c2bd5cacd621a74e29d5de77475b367da5e18a56e
|
4
|
+
data.tar.gz: de689a155969d77a44a368e58f0df45043cef9c4e1482d409afbdc9890e8b478
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c98054b4db81e4b8081a64d05d6cd65983332779a02b7d653011ea5079589ccf0d30bc11062511e78d7ce7c693cdbac5ffd9ea133a0ae057fb89736dd8675af
|
7
|
+
data.tar.gz: 680a7b40a98a414b1191f4ceb50d5301511ae30672c0f396a3ef0e18b00f994fa8e38ce58599258c5aa377e8abac458fcb37c7ec33404aad6504366484f93b13
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -22,7 +22,12 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
```
|
26
|
+
EasyWechat.configure do |config|
|
27
|
+
config.appid = ENV.fetch("APPID") || ""
|
28
|
+
config.app_secret = ENV.fetch("APP_SECRET") || ""
|
29
|
+
end
|
30
|
+
```
|
26
31
|
|
27
32
|
## Development
|
28
33
|
|
data/easy_wechat.gemspec
CHANGED
@@ -6,8 +6,8 @@ Gem::Specification.new do |spec|
|
|
6
6
|
spec.authors = ["42up"]
|
7
7
|
spec.email = ["foobar@v2up.com"]
|
8
8
|
|
9
|
-
spec.summary = "easy wechat sdk"
|
10
|
-
spec.description = "easy wechat sdk"
|
9
|
+
spec.summary = "An unofficial easy wechat sdk"
|
10
|
+
spec.description = "An unofficial easy wechat sdk"
|
11
11
|
spec.homepage = "https://github.com/42up/easy_wechat"
|
12
12
|
spec.license = "MIT"
|
13
13
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
data/lib/easy_wechat.rb
CHANGED
@@ -1,7 +1,32 @@
|
|
1
1
|
require "easy_wechat/version"
|
2
|
+
require "easy_wechat/client"
|
3
|
+
require "easy_wechat/configuration"
|
4
|
+
|
5
|
+
require "httpx"
|
2
6
|
|
3
7
|
module EasyWechat
|
4
8
|
class Error < StandardError; end
|
5
|
-
|
6
|
-
|
9
|
+
def self.configuration
|
10
|
+
@configuration ||= Configuration.new
|
11
|
+
end
|
12
|
+
|
13
|
+
class << self
|
14
|
+
attr_writer :configuration
|
15
|
+
|
16
|
+
def configuration
|
17
|
+
@configuration ||= Configuration.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def configure
|
21
|
+
yield(configuration)
|
22
|
+
end
|
23
|
+
|
24
|
+
def app_id
|
25
|
+
configuration.app_id
|
26
|
+
end
|
27
|
+
|
28
|
+
def app_secret
|
29
|
+
configuration.app_secret
|
30
|
+
end
|
31
|
+
end
|
7
32
|
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require "httpx"
|
2
|
+
require "http/form_data"
|
3
|
+
require "json"
|
4
|
+
require "active_support"
|
5
|
+
|
6
|
+
module EasyWechat
|
7
|
+
class Client
|
8
|
+
TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token"
|
9
|
+
BATCHGET_MATERIAL_URL = "https://api.weixin.qq.com/cgi-bin/material/batchget_material"
|
10
|
+
UPLOADIMG_URL = "https://api.weixin.qq.com/cgi-bin/media/uploadimg"
|
11
|
+
ADD_NEWS_URL = "https://api.weixin.qq.com/cgi-bin/material/add_news"
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
end
|
15
|
+
|
16
|
+
def access_token
|
17
|
+
@access_token ||= token["access_token"]
|
18
|
+
end
|
19
|
+
|
20
|
+
# 获取access_token
|
21
|
+
# https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Get_access_token.html
|
22
|
+
def token
|
23
|
+
resp = HTTPX.get(TOKEN_URL, params: {
|
24
|
+
appid: EasyWechat.app_id,
|
25
|
+
secret: EasyWechat.app_secret,
|
26
|
+
grant_type: "client_credential",
|
27
|
+
})
|
28
|
+
|
29
|
+
r = ::JSON.parse(resp.body, quirks_mode: true)
|
30
|
+
yield r if block_given?
|
31
|
+
r
|
32
|
+
end
|
33
|
+
|
34
|
+
# 上传图文消息内的图片获取URL
|
35
|
+
# https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Adding_Permanent_Assets.html
|
36
|
+
def uploadimg(media)
|
37
|
+
# https://honeyryderchuck.gitlab.io/httpx/wiki/Multipart-Uploads.html#notes
|
38
|
+
file = if media.is_a?(String) ? HTTP::FormData::File.new(media) : meida
|
39
|
+
|
40
|
+
resp = HTTPX.plugin(:multipart).post(UPLOADIMG_URL, params: { access_token: access_token }, form: { media: file })
|
41
|
+
|
42
|
+
r = ::JSON.parse(resp.body, quirks_mode: true)
|
43
|
+
yield r if block_given?
|
44
|
+
r
|
45
|
+
end
|
46
|
+
|
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 }
|
53
|
+
|
54
|
+
resp = HTTPX.post(BATCHGET_MATERIAL_URL, params: { access_token: access_token }, json: payload)
|
55
|
+
|
56
|
+
r = ::JSON.parse(resp.body, quirks_mode: true)
|
57
|
+
yield r if block_given?
|
58
|
+
r
|
59
|
+
end
|
60
|
+
|
61
|
+
# 新增永久图文素材
|
62
|
+
# https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Adding_Permanent_Assets.html
|
63
|
+
def add_news(articles)
|
64
|
+
payload = { articles: articles }
|
65
|
+
|
66
|
+
resp = HTTPX.post(ADD_NEWS_URL, params: { access_token: access_token }, json: payload)
|
67
|
+
|
68
|
+
r = ::JSON.parse(resp.body, quirks_mode: true)
|
69
|
+
yield r if block_given?
|
70
|
+
r
|
71
|
+
end
|
72
|
+
|
73
|
+
def menu_create
|
74
|
+
raise NotImplementedError
|
75
|
+
end
|
76
|
+
end
|
77
|
+
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 42up
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-06-
|
11
|
+
date: 2021-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httpx
|
@@ -94,7 +94,7 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
-
description: easy wechat sdk
|
97
|
+
description: An unofficial easy wechat sdk
|
98
98
|
email:
|
99
99
|
- foobar@v2up.com
|
100
100
|
executables: []
|
@@ -113,6 +113,8 @@ files:
|
|
113
113
|
- bin/setup
|
114
114
|
- easy_wechat.gemspec
|
115
115
|
- lib/easy_wechat.rb
|
116
|
+
- lib/easy_wechat/client.rb
|
117
|
+
- lib/easy_wechat/configuration.rb
|
116
118
|
- lib/easy_wechat/version.rb
|
117
119
|
homepage: https://github.com/42up/easy_wechat
|
118
120
|
licenses:
|
@@ -139,5 +141,5 @@ requirements: []
|
|
139
141
|
rubygems_version: 3.1.4
|
140
142
|
signing_key:
|
141
143
|
specification_version: 4
|
142
|
-
summary: easy wechat sdk
|
144
|
+
summary: An unofficial easy wechat sdk
|
143
145
|
test_files: []
|