wechat-core 0.4.1 → 0.4.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/CHANGELOG.md +7 -0
- data/Gemfile.lock +20 -20
- data/README.md +2 -0
- data/ROADMAP.md +7 -0
- data/lib/wechat/core/access_token.rb +6 -8
- data/lib/wechat/core/common.rb +9 -0
- data/lib/wechat/core/follower.rb +5 -2
- data/lib/wechat/core/follower_profile.rb +13 -7
- data/lib/wechat/core/server_address.rb +6 -2
- data/lib/wechat/core/tiny_link.rb +5 -2
- data/lib/wechat/core/version.rb +1 -1
- data/wechat-core.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1fb64c38de72269f3964193557840d1a082e8338
|
4
|
+
data.tar.gz: a2f81055f5a1f6958a9b0b3d9ccf560dff71b3b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f38dd883d10e79b7c9f5e5c5f9a3d351b8c89cf933c6184c49e3a4473411d90e4c27b7d3073f923eeeca5b55b1552378fc2f51aa34466bae1339d56166f95cd2
|
7
|
+
data.tar.gz: '09791946ee19d6e59acb26c305ca2c9c73652613277dff4ec79d17beb9d2324914922acee6b939069fbdf2a56300797a454854f469e8a9513cbaa32cfd188092'
|
data/CHANGELOG.md
CHANGED
@@ -28,3 +28,10 @@
|
|
28
28
|
3. Improve the Follower Profile wrapper class for the HTTP request
|
29
29
|
4. Improve the Server Address wrapper class for the HTTP request
|
30
30
|
5. Improve the Tiny Link wrapper class for the HTTP request
|
31
|
+
|
32
|
+
## v0.4.2
|
33
|
+
1. Improve the Access Token wrapper class for the HTTP request
|
34
|
+
2. Improve the Follower wrapper class for the HTTP request
|
35
|
+
3. Improve the Follower Profile wrapper class for the HTTP request
|
36
|
+
4. Improve the Server Address wrapper class for the HTTP request
|
37
|
+
5. Improve the Tiny Link wrapper class for the HTTP request
|
data/Gemfile.lock
CHANGED
@@ -8,32 +8,32 @@ PATH
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activesupport (5.0.
|
11
|
+
activesupport (5.0.2)
|
12
12
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
13
|
i18n (~> 0.7)
|
14
14
|
minitest (~> 5.1)
|
15
15
|
tzinfo (~> 1.1)
|
16
|
-
concurrent-ruby (1.0.
|
17
|
-
diff-lcs (1.
|
18
|
-
httpclient (2.8.
|
19
|
-
i18n (0.
|
20
|
-
minitest (5.
|
16
|
+
concurrent-ruby (1.0.5)
|
17
|
+
diff-lcs (1.3)
|
18
|
+
httpclient (2.8.3)
|
19
|
+
i18n (0.8.1)
|
20
|
+
minitest (5.10.1)
|
21
21
|
rake (10.5.0)
|
22
|
-
rspec (3.
|
23
|
-
rspec-core (~> 3.
|
24
|
-
rspec-expectations (~> 3.
|
25
|
-
rspec-mocks (~> 3.
|
26
|
-
rspec-core (3.
|
27
|
-
rspec-support (~> 3.
|
28
|
-
rspec-expectations (3.
|
22
|
+
rspec (3.5.0)
|
23
|
+
rspec-core (~> 3.5.0)
|
24
|
+
rspec-expectations (~> 3.5.0)
|
25
|
+
rspec-mocks (~> 3.5.0)
|
26
|
+
rspec-core (3.5.4)
|
27
|
+
rspec-support (~> 3.5.0)
|
28
|
+
rspec-expectations (3.5.0)
|
29
29
|
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
-
rspec-support (~> 3.
|
31
|
-
rspec-mocks (3.
|
30
|
+
rspec-support (~> 3.5.0)
|
31
|
+
rspec-mocks (3.5.0)
|
32
32
|
diff-lcs (>= 1.2.0, < 2.0)
|
33
|
-
rspec-support (~> 3.
|
34
|
-
rspec-support (3.
|
35
|
-
thread_safe (0.3.
|
36
|
-
tzinfo (1.2.
|
33
|
+
rspec-support (~> 3.5.0)
|
34
|
+
rspec-support (3.5.0)
|
35
|
+
thread_safe (0.3.6)
|
36
|
+
tzinfo (1.2.3)
|
37
37
|
thread_safe (~> 0.1)
|
38
38
|
|
39
39
|
PLATFORMS
|
@@ -46,4 +46,4 @@ DEPENDENCIES
|
|
46
46
|
wechat-core!
|
47
47
|
|
48
48
|
BUNDLED WITH
|
49
|
-
1.
|
49
|
+
1.13.6
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# Wechat::Core 微信核心库
|
2
2
|
|
3
|
+
[](http://www.rubydoc.info/gems/wechat-core/frames)
|
3
4
|
[](http://opensource.org/licenses/MIT)
|
5
|
+
|
4
6
|
[](https://badge.fury.io/rb/wechat-core)
|
5
7
|
[](https://gemnasium.com/github.com/topbitdu/wechat-core)
|
6
8
|
|
data/ROADMAP.md
CHANGED
@@ -29,6 +29,13 @@
|
|
29
29
|
4. Improve the Server Address wrapper class for the HTTP request
|
30
30
|
5. Improve the Tiny Link wrapper class for the HTTP request
|
31
31
|
|
32
|
+
## v0.4.2
|
33
|
+
1. Improve the Access Token wrapper class for the HTTP request
|
34
|
+
2. Improve the Follower wrapper class for the HTTP request
|
35
|
+
3. Improve the Follower Profile wrapper class for the HTTP request
|
36
|
+
4. Improve the Server Address wrapper class for the HTTP request
|
37
|
+
5. Improve the Tiny Link wrapper class for the HTTP request
|
38
|
+
|
32
39
|
## v1.0
|
33
40
|
1. Improve the Follower & Follower Profile wrapper class to support the Keyword Arguments
|
34
41
|
2. Removed the depreated classes and methods
|
@@ -1,9 +1,13 @@
|
|
1
1
|
require 'jsonclient'
|
2
2
|
|
3
|
+
##
|
4
|
+
# Access Token 是访问令牌的远程调用封装类。
|
5
|
+
|
3
6
|
class Wechat::Core::AccessToken
|
4
7
|
|
5
8
|
extend Wechat::Core::Common
|
6
9
|
|
10
|
+
##
|
7
11
|
# 获取 Access Token
|
8
12
|
# http://mp.weixin.qq.com/wiki/11/0e4b294685f817b95cbed85ba5e82b8f.html
|
9
13
|
#
|
@@ -23,6 +27,7 @@ class Wechat::Core::AccessToken
|
|
23
27
|
message.body
|
24
28
|
end
|
25
29
|
|
30
|
+
##
|
26
31
|
# 获取 Access Token
|
27
32
|
# http://mp.weixin.qq.com/wiki/11/0e4b294685f817b95cbed85ba5e82b8f.html
|
28
33
|
#
|
@@ -37,19 +42,12 @@ class Wechat::Core::AccessToken
|
|
37
42
|
assert_present! :app_id, app_id
|
38
43
|
assert_present! :app_secret, app_secret
|
39
44
|
|
40
|
-
|
41
|
-
# {
|
42
|
-
# grant_type: 'client_credential',
|
43
|
-
# appid: app_id, # Rails.application.secrets.wechat_app_id,
|
44
|
-
# secret: app_secret, # Rails.application.secrets.wechat_app_secret
|
45
|
-
# }
|
46
|
-
message = get_json 'https://api.weixin.qq.com/cgi-bin/token', body:
|
45
|
+
get_json 'https://api.weixin.qq.com/cgi-bin/token', body:
|
47
46
|
{
|
48
47
|
grant_type: 'client_credential',
|
49
48
|
appid: app_id, # Rails.application.secrets.wechat_app_id,
|
50
49
|
secret: app_secret, # Rails.application.secrets.wechat_app_secret
|
51
50
|
}
|
52
|
-
message.body
|
53
51
|
end
|
54
52
|
|
55
53
|
class << self
|
data/lib/wechat/core/common.rb
CHANGED
@@ -142,16 +142,25 @@ module Wechat::Core::Common
|
|
142
142
|
9001036 => '查询起始值begin不合法'
|
143
143
|
}
|
144
144
|
|
145
|
+
##
|
146
|
+
# 判断给定的参数 value 是否为空,如果为空,则抛出 ArgumentError 异常。参数名为 name 。例如:
|
147
|
+
# assert_present! :access_token, access_token
|
145
148
|
def assert_present!(name, value)
|
146
149
|
raise ArgumentError.new("The #{name} argument is required.") if value.blank?
|
147
150
|
end
|
148
151
|
|
152
|
+
##
|
153
|
+
# 向链接 link 发出 GET 请求,参数为 body 指定的 Hash。返回的数据结构必须为 JSON 格式。如:
|
154
|
+
# get_json 'https://api.product.com/path/resources.json', body: { page: 2, per_page: 5 }
|
149
155
|
def get_json(link, body: {})
|
150
156
|
assert_present! :link, link
|
151
157
|
message = JSONClient.new.get link, body
|
152
158
|
message.body
|
153
159
|
end
|
154
160
|
|
161
|
+
##
|
162
|
+
# 向链接 link 发出 GET 请求,参数为 body 指定的 Hash。返回的数据结构必须为 JSON 格式。如:
|
163
|
+
# post_json 'https://api.product.com/path/resources.json', body: { name: 'Some Name' }
|
155
164
|
def post_json(link, body: {})
|
156
165
|
assert_present! :link, link
|
157
166
|
message = JSONClient.new.post link, body
|
data/lib/wechat/core/follower.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
|
+
##
|
2
|
+
# Follower 是关注者概要信息的远程调用封装类。
|
3
|
+
|
1
4
|
class Wechat::Core::Follower
|
2
5
|
|
3
6
|
extend Wechat::Core::Common
|
4
7
|
|
8
|
+
##
|
5
9
|
# 获取关注者列表
|
6
10
|
# http://mp.weixin.qq.com/wiki/0/d0e07720fc711c02a3eab6ec33054804.html
|
7
11
|
#
|
@@ -19,8 +23,7 @@ class Wechat::Core::Follower
|
|
19
23
|
options = { access_token: access_token }
|
20
24
|
options[:next_openid] = next_open_id if next_open_id.present?
|
21
25
|
|
22
|
-
|
23
|
-
message.body
|
26
|
+
get_json 'https://api.weixin.qq.com/cgi-bin/user/get', body: options
|
24
27
|
end
|
25
28
|
|
26
29
|
end
|
@@ -1,7 +1,11 @@
|
|
1
|
+
##
|
2
|
+
# Follower Profile 是关注者画像的远程调用封装类。
|
3
|
+
|
1
4
|
class Wechat::Core::FollowerProfile
|
2
5
|
|
3
6
|
extend Wechat::Core::Common
|
4
7
|
|
8
|
+
##
|
5
9
|
# 批量获取用户基本信息
|
6
10
|
# http://mp.weixin.qq.com/wiki/14/bb5031008f1494a59c6f71fa0f319c66.html#.E6.89.B9.E9.87.8F.E8.8E.B7.E5.8F.96.E7.94.A8.E6.88.B7.E5.9F.BA.E6.9C.AC.E4.BF.A1.E6.81.AF
|
7
11
|
# 最多支持一次拉取100条。
|
@@ -20,7 +24,7 @@ class Wechat::Core::FollowerProfile
|
|
20
24
|
# country: <COUNTRY_NAME>,
|
21
25
|
# headimgurl: <HEAD_IMAGE_LINK>,
|
22
26
|
# subscribe_time: <SUBSCRIBE_TIME>,
|
23
|
-
# unionid: <UNION_ID>,
|
27
|
+
# unionid: <UNION_ID>,
|
24
28
|
# remark: <REMARK>,
|
25
29
|
# groupid: <GROUP_ID>
|
26
30
|
# }
|
@@ -32,14 +36,17 @@ class Wechat::Core::FollowerProfile
|
|
32
36
|
assert_present! :open_ids, open_ids
|
33
37
|
|
34
38
|
followers = open_ids.map { |open_id| { openid: open_id, lang: language } }
|
35
|
-
|
36
|
-
|
39
|
+
post_json "https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token=#{access_token}", body:
|
40
|
+
{
|
41
|
+
user_list: followers
|
42
|
+
}
|
37
43
|
|
38
44
|
end
|
39
45
|
|
46
|
+
##
|
40
47
|
# 获取用户基本信息(UnionID机制)
|
41
48
|
# http://mp.weixin.qq.com/wiki/14/bb5031008f1494a59c6f71fa0f319c66.html#.E8.8E.B7.E5.8F.96.E7.94.A8.E6.88.B7.E5.9F.BA.E6.9C.AC.E4.BF.A1.E6.81.AF.EF.BC.88.E5.8C.85.E6.8B.ACUnionID.E6.9C.BA.E5.88.B6.EF.BC.89
|
42
|
-
# 一次拉取调用最多拉取10000个关注者的OpenID,可以通过多次拉取的方式来满足需求。
|
49
|
+
# 一次拉取调用最多拉取10000个关注者的OpenID,可以通过多次拉取的方式来满足需求。
|
43
50
|
#
|
44
51
|
# Return hash format if success:
|
45
52
|
# {
|
@@ -56,18 +63,17 @@ class Wechat::Core::FollowerProfile
|
|
56
63
|
# remark: <REMARK>,
|
57
64
|
# groupid: <GROUP_ID>
|
58
65
|
# }
|
59
|
-
def self.load(access_token, open_id, language:
|
66
|
+
def self.load(access_token, open_id, language: Wechat::Core::Common::LANGUAGE_SIMPLIFIED_CHINESE)
|
60
67
|
|
61
68
|
assert_present! :access_token, access_token
|
62
69
|
assert_present! :open_id, open_id
|
63
70
|
|
64
|
-
|
71
|
+
get_json 'https://api.weixin.qq.com/cgi-bin/user/info', body:
|
65
72
|
{
|
66
73
|
access_token: access_token,
|
67
74
|
openid: open_id,
|
68
75
|
lang: language
|
69
76
|
}
|
70
|
-
message.body
|
71
77
|
end
|
72
78
|
|
73
79
|
end
|
@@ -1,7 +1,11 @@
|
|
1
|
+
##
|
2
|
+
# Server Address 是服务器地址的远程调用封装类。
|
3
|
+
|
1
4
|
class Wechat::Core::ServerAddress
|
2
5
|
|
3
6
|
extend Wechat::Core::Common
|
4
7
|
|
8
|
+
##
|
5
9
|
# 获取微信服务器IP地址
|
6
10
|
# http://mp.weixin.qq.com/wiki/0/2ad4b6bfd29f30f71d39616c2a0fcedc.html
|
7
11
|
#
|
@@ -11,8 +15,8 @@ class Wechat::Core::ServerAddress
|
|
11
15
|
|
12
16
|
assert_present! :access_token, access_token
|
13
17
|
|
14
|
-
|
15
|
-
|
18
|
+
get_json 'https://api.weixin.qq.com/cgi-bin/getcallbackip', body: { access_token: access_token }
|
19
|
+
|
16
20
|
end
|
17
21
|
|
18
22
|
end
|
@@ -1,7 +1,11 @@
|
|
1
|
+
##
|
2
|
+
# Tiny Link 是短链接的远程调用封装类。
|
3
|
+
|
1
4
|
class Wechat::Core::TinyLink
|
2
5
|
|
3
6
|
extend Wechat::Core::Common
|
4
7
|
|
8
|
+
##
|
5
9
|
# 长链接转短链接接口
|
6
10
|
# http://mp.weixin.qq.com/wiki/10/165c9b15eddcfbd8699ac12b0bd89ae6.html
|
7
11
|
#
|
@@ -23,12 +27,11 @@ class Wechat::Core::TinyLink
|
|
23
27
|
assert_present! :access_token, access_token
|
24
28
|
assert_present! :link, link
|
25
29
|
|
26
|
-
|
30
|
+
post_json "https://api.weixin.qq.com/cgi-bin/shorturl?access_token=#{access_token}", body:
|
27
31
|
{
|
28
32
|
action: 'long2short',
|
29
33
|
long_url: link
|
30
34
|
}
|
31
|
-
message.body
|
32
35
|
end
|
33
36
|
|
34
37
|
end
|
data/lib/wechat/core/version.rb
CHANGED
data/wechat-core.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wechat-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Topbit Du
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|