wechat-core 0.3 → 0.4
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 +0 -1
- data/CHANGELOG.md +10 -0
- data/Gemfile.lock +37 -0
- data/README.md +128 -5
- data/ROADMAP.md +15 -1
- data/_config.yml +1 -0
- data/bin/console +3 -3
- data/lib/wechat/core/access_token.rb +29 -0
- data/lib/wechat/core/common.rb +18 -0
- data/lib/wechat/core/follower.rb +5 -1
- data/lib/wechat/core/follower_profile.rb +34 -16
- data/lib/wechat/core/server_address.rb +5 -0
- data/lib/wechat/core/tiny_link.rb +20 -0
- data/lib/wechat/core/version.rb +1 -1
- data/lib/wechat/core.rb +0 -1
- data/wechat-core.gemspec +11 -13
- metadata +11 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04e15515aaf3047453f946fc07130449edb2bf21
|
4
|
+
data.tar.gz: 43dc63bca5eecb3526c3123adb8f90ec78a9be46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f495cdcb0a88246aa7496764085346b2fbf940c9f64ce49682d72cbfec864dda5e09e217e79bf5bc52719325dce90611ac7927a504835dc524eebef002d90a34
|
7
|
+
data.tar.gz: 4385a3e77b377615df1d6cf00cc075a144a0b2571176ccfc33df6759232b2bc6be1243861bbfa88f3a66b5ce66bb9b4a5e1c792eb1c6c67f23581ca9098c448f
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -11,3 +11,13 @@
|
|
11
11
|
## v0.3
|
12
12
|
1. Follower wrapper class
|
13
13
|
2. Follower Profile wrapper class
|
14
|
+
|
15
|
+
## v0.4
|
16
|
+
1. Improve the Common module to add the #get_json method & the #post_json method
|
17
|
+
2. Improve the Common module to add the #assert_present! method
|
18
|
+
3. Improve the Access Token wrapper class for the argument validation
|
19
|
+
4. Improve the Follower wrapper class for the argument validation
|
20
|
+
5. Improve the Follower Profile wrapper class for the argument validation
|
21
|
+
6. Improve the Server Address wrapper class for the argument validation
|
22
|
+
7. Improve the Tiny Link wrapper class for the argument validation
|
23
|
+
8. Improve the Access Token wrapper class to deprecate ::load method, use the Access Token ::create method instead
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
wechat-core (0.4)
|
5
|
+
httpclient (>= 2.8)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.2.5)
|
11
|
+
httpclient (2.8.0)
|
12
|
+
rake (10.5.0)
|
13
|
+
rspec (3.4.0)
|
14
|
+
rspec-core (~> 3.4.0)
|
15
|
+
rspec-expectations (~> 3.4.0)
|
16
|
+
rspec-mocks (~> 3.4.0)
|
17
|
+
rspec-core (3.4.4)
|
18
|
+
rspec-support (~> 3.4.0)
|
19
|
+
rspec-expectations (3.4.0)
|
20
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
21
|
+
rspec-support (~> 3.4.0)
|
22
|
+
rspec-mocks (3.4.1)
|
23
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
24
|
+
rspec-support (~> 3.4.0)
|
25
|
+
rspec-support (3.4.1)
|
26
|
+
|
27
|
+
PLATFORMS
|
28
|
+
ruby
|
29
|
+
|
30
|
+
DEPENDENCIES
|
31
|
+
bundler (~> 1.11)
|
32
|
+
rake (~> 10.0)
|
33
|
+
rspec (~> 3.0)
|
34
|
+
wechat-core!
|
35
|
+
|
36
|
+
BUNDLED WITH
|
37
|
+
1.12.5
|
data/README.md
CHANGED
@@ -2,9 +2,18 @@
|
|
2
2
|
|
3
3
|
[](http://opensource.org/licenses/MIT)
|
4
4
|
[](https://badge.fury.io/rb/wechat-core)
|
5
|
+
[](https://gemnasium.com/github.com/topbitdu/wechat-core)
|
6
|
+
|
7
|
+
The Wechat Core Library is a code base to call the core Wechat APIs, such as fetching Access Token, and fetching Follower Profile. 微信核心库用于调用微信核心API,例如获取访问令牌,获取关注者的信息。
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
## Recent Update
|
12
|
+
|
13
|
+
Check out the [Road Map](ROADMAP.md) to find out what's the next.
|
14
|
+
Check out the [Change Log](CHANGELOG.md) to find out what's new.
|
15
|
+
|
5
16
|
|
6
|
-
The Wechat Core Library is a code base to call the Wechat Core APIs.
|
7
|
-
微信核心库用于调用微信核心API。
|
8
17
|
|
9
18
|
## Installation
|
10
19
|
|
@@ -22,29 +31,143 @@ Or install it yourself as:
|
|
22
31
|
|
23
32
|
$ gem install wechat-core
|
24
33
|
|
34
|
+
|
35
|
+
|
25
36
|
## Usage
|
26
37
|
|
27
|
-
|
38
|
+
### Access Token 访问令牌
|
39
|
+
|
40
|
+
[Get the Wechat Access Token 获取微信访问令牌](http://mp.weixin.qq.com/wiki/14/9f9c82c1af308e3b14ba9b973f99a8ba.html)
|
28
41
|
```ruby
|
29
|
-
response =
|
42
|
+
response = Wechat::Core::AccessToken.load Rails.application.secrets.wechat_app_id, Rails.application.secrets.wechat_app_secret
|
30
43
|
if response.present?
|
31
44
|
access_token = response['access_token']
|
32
45
|
expires_in = response['expires_in']
|
33
46
|
end
|
34
47
|
```
|
35
48
|
|
49
|
+
### Follower 关注者
|
50
|
+
|
51
|
+
[Get the Follower List 获取关注者列表](http://mp.weixin.qq.com/wiki/0/d0e07720fc711c02a3eab6ec33054804.html)
|
52
|
+
```ruby
|
53
|
+
response = Wechat::Core::Follower.index access_token
|
54
|
+
if response.present? && 0==response['errcode'].to_i
|
55
|
+
total = response['total']
|
56
|
+
count = response['count']
|
57
|
+
next_open_id = response['next_openid']
|
58
|
+
data = response['data']
|
59
|
+
data['openid'].each do |open_id|
|
60
|
+
# Show open_id
|
61
|
+
end
|
62
|
+
else
|
63
|
+
# Show response['errmsg']
|
64
|
+
end
|
65
|
+
```
|
66
|
+
|
67
|
+
[Get the Follower List with Pagination 分页获取关注者列表](http://mp.weixin.qq.com/wiki/0/d0e07720fc711c02a3eab6ec33054804.html)
|
68
|
+
```ruby
|
69
|
+
response = Wechat::Core::Follower.index access_token, next_open_id
|
70
|
+
if response.present? && 0==response['errcode'].to_i
|
71
|
+
total = response['total']
|
72
|
+
count = response['count']
|
73
|
+
next_open_id = response['next_openid']
|
74
|
+
data = response['data']
|
75
|
+
data['openid'].each do |open_id|
|
76
|
+
# Show open_id
|
77
|
+
end
|
78
|
+
else
|
79
|
+
# Show response['errmsg']
|
80
|
+
end
|
81
|
+
```
|
82
|
+
|
83
|
+
[Get the Follower Profiles by Batch 批量获取关注者轮廓](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)
|
84
|
+
```ruby
|
85
|
+
response = Wechat::Core::FollowerProfile.index access_token, [ open_id_1, open_id_2, ... ]
|
86
|
+
if response.present? && 0==response['errcode'].to_i
|
87
|
+
response['user_info_list'].each do |profile|
|
88
|
+
subscribed = profile['subscribe']
|
89
|
+
open_id = profile['openid']
|
90
|
+
nick_name = profile['nickname']
|
91
|
+
sex = profile['sex']
|
92
|
+
language = profile['language']
|
93
|
+
city = profile['city']
|
94
|
+
province = profile['province']
|
95
|
+
country = profile['country']
|
96
|
+
portrait_link = profile['headimgurl']
|
97
|
+
subscribe_time = profile['subscribe_time']
|
98
|
+
union_id = profile['unionid']
|
99
|
+
remark = profile['remark']
|
100
|
+
group_id = profile['groupid']
|
101
|
+
end
|
102
|
+
else
|
103
|
+
# Show response['errmsg']
|
104
|
+
end
|
105
|
+
```
|
106
|
+
|
107
|
+
[Get the Follower Profile 获取用户基本信息](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)
|
108
|
+
```ruby
|
109
|
+
response = Wechat::Core::FollowerProfile.load access_token, open_id
|
110
|
+
if response.present? && 0==response['errcode'].to_i
|
111
|
+
subscribed = response['subscribe']
|
112
|
+
open_id = response['openid']
|
113
|
+
nick_name = response['nickname']
|
114
|
+
sex = response['sex']
|
115
|
+
language = response['language']
|
116
|
+
city = response['city']
|
117
|
+
province = response['province']
|
118
|
+
country = response['country']
|
119
|
+
portrait_link = response['headimgurl']
|
120
|
+
subscribe_time = response['subscribe_time']
|
121
|
+
union_id = response['unionid']
|
122
|
+
remark = response['remark']
|
123
|
+
group_id = response['groupid']
|
124
|
+
else
|
125
|
+
# Show response['errmsg']
|
126
|
+
end
|
127
|
+
```
|
128
|
+
|
129
|
+
### Server Address 服务器地址
|
130
|
+
|
131
|
+
[Get Server Addresses 获取服务器地址](http://mp.weixin.qq.com/wiki/0/2ad4b6bfd29f30f71d39616c2a0fcedc.html)
|
132
|
+
```ruby
|
133
|
+
response = Wechat::Core::ServerAddress.index access_token
|
134
|
+
if response.present? && 0==response['errcode'].to_i
|
135
|
+
response['ip_list'].each do |ip_address|
|
136
|
+
# Do something with the IP Address...
|
137
|
+
end
|
138
|
+
else
|
139
|
+
# Show response['errmsg']
|
140
|
+
end
|
141
|
+
```
|
142
|
+
|
143
|
+
### Tiny Link 短链接
|
144
|
+
|
145
|
+
[Generate Tiny Link 长链接转短链接接口](http://mp.weixin.qq.com/wiki/10/165c9b15eddcfbd8699ac12b0bd89ae6.html)
|
146
|
+
```ruby
|
147
|
+
response = Wechat::Core::TinyLink.create access_token, 'http://product.company.com/promotion/page.html'
|
148
|
+
if response.present? && 0==response['errcode'].to_i
|
149
|
+
tiny_link = response['short_url']
|
150
|
+
else
|
151
|
+
# Show response['errmsg']
|
152
|
+
end
|
153
|
+
```
|
154
|
+
|
155
|
+
|
156
|
+
|
36
157
|
## Development
|
37
158
|
|
38
159
|
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.
|
39
160
|
|
40
161
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
41
162
|
|
163
|
+
|
164
|
+
|
42
165
|
## Contributing
|
43
166
|
|
44
167
|
Bug reports and pull requests are welcome on GitHub at https://github.com/topbitdu/wechat-core. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
45
168
|
|
46
169
|
|
170
|
+
|
47
171
|
## License
|
48
172
|
|
49
173
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
50
|
-
|
data/ROADMAP.md
CHANGED
@@ -12,5 +12,19 @@
|
|
12
12
|
1. Follower wrapper class
|
13
13
|
2. Follower Profile wrapper class
|
14
14
|
|
15
|
-
|
15
|
+
## v0.4
|
16
|
+
1. Improve the Common module to add the #get_json method & the #post_json method
|
17
|
+
2. Improve the Common module to add the #assert_present! method
|
18
|
+
3. Improve the Access Token wrapper class for the argument validation
|
19
|
+
4. Improve the Follower wrapper class for the argument validation
|
20
|
+
5. Improve the Follower Profile wrapper class for the argument validation
|
21
|
+
6. Improve the Server Address wrapper class for the argument validation
|
22
|
+
7. Improve the Tiny Link wrapper class for the argument validation
|
23
|
+
8. Improve the Access Token wrapper class to deprecate ::load method, use the Access Token ::create method instead
|
24
|
+
|
25
|
+
## v1.0
|
26
|
+
1. Improve the Follower & Follower Profile wrapper class to support the Keyword Arguments
|
27
|
+
2. Removed the depreated classes and methods
|
28
|
+
|
29
|
+
## v1.1
|
16
30
|
1. Logo wrapper class
|
data/_config.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
markdown: kramdown
|
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'wechat/core'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +10,5 @@ require "wechat/core"
|
|
10
10
|
# require "pry"
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
13
|
+
require 'irb'
|
14
14
|
IRB.start
|
@@ -2,6 +2,8 @@ require 'jsonclient'
|
|
2
2
|
|
3
3
|
class Wechat::Core::AccessToken
|
4
4
|
|
5
|
+
extend Wechat::Core::Common
|
6
|
+
|
5
7
|
# 获取 Access Token
|
6
8
|
# http://mp.weixin.qq.com/wiki/11/0e4b294685f817b95cbed85ba5e82b8f.html
|
7
9
|
#
|
@@ -21,4 +23,31 @@ class Wechat::Core::AccessToken
|
|
21
23
|
message.body
|
22
24
|
end
|
23
25
|
|
26
|
+
# 获取 Access Token
|
27
|
+
# http://mp.weixin.qq.com/wiki/11/0e4b294685f817b95cbed85ba5e82b8f.html
|
28
|
+
#
|
29
|
+
# Return hash format if success:
|
30
|
+
# {
|
31
|
+
# access_token: <ACCESS_TOKEN>,
|
32
|
+
# expires_in: 7200
|
33
|
+
# }
|
34
|
+
# The ACCESS_TOKEN is 107 characters in 2015.
|
35
|
+
def self.create(app_id, app_secret)
|
36
|
+
|
37
|
+
assert_present! :app_id, app_id
|
38
|
+
assert_present! :app_secret, app_secret
|
39
|
+
|
40
|
+
message = ::JSONClient.new.get 'https://api.weixin.qq.com/cgi-bin/token',
|
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.body
|
47
|
+
end
|
48
|
+
|
49
|
+
class << self
|
50
|
+
deprecate load: :create, deprecator: ActiveSupport::Deprecation.new('1.0', 'wechat-core')
|
51
|
+
end
|
52
|
+
|
24
53
|
end
|
data/lib/wechat/core/common.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'jsonclient'
|
2
|
+
|
1
3
|
module Wechat::Core::Common
|
2
4
|
|
3
5
|
LANGUAGE_SIMPLIFIED_CHINESE = 'zh_CN'.freeze
|
@@ -140,4 +142,20 @@ module Wechat::Core::Common
|
|
140
142
|
9001036 => '查询起始值begin不合法'
|
141
143
|
}
|
142
144
|
|
145
|
+
def assert_present!(name, value)
|
146
|
+
raise ArgumentError.new("The #{name} argument is required.") if value.blank?
|
147
|
+
end
|
148
|
+
|
149
|
+
def get_json(link, body: {})
|
150
|
+
assert_present! :link, link
|
151
|
+
message = JSONClient.new.get link, body
|
152
|
+
message.body
|
153
|
+
end
|
154
|
+
|
155
|
+
def post_json(link, body: {})
|
156
|
+
assert_present! :link, link
|
157
|
+
message = JSONClient.new.post link, body
|
158
|
+
message.body
|
159
|
+
end
|
160
|
+
|
143
161
|
end
|
data/lib/wechat/core/follower.rb
CHANGED
@@ -2,6 +2,8 @@ require 'jsonclient'
|
|
2
2
|
|
3
3
|
class Wechat::Core::Follower
|
4
4
|
|
5
|
+
extend Wechat::Core::Common
|
6
|
+
|
5
7
|
# 获取关注者列表
|
6
8
|
# http://mp.weixin.qq.com/wiki/0/d0e07720fc711c02a3eab6ec33054804.html
|
7
9
|
#
|
@@ -12,7 +14,9 @@ class Wechat::Core::Follower
|
|
12
14
|
# data: { openid: [ <OPEN_ID_1>, <OPEN_ID_2>, ... ] },
|
13
15
|
# next_openid: <NEXT_OPEN_ID>
|
14
16
|
# }
|
15
|
-
def self.index(access_token, next_open_id
|
17
|
+
def self.index(access_token, next_open_id: nil)
|
18
|
+
|
19
|
+
assert_present! :access_token, access_token
|
16
20
|
|
17
21
|
options = { access_token: access_token }
|
18
22
|
options[:next_openid] = next_open_id if next_open_id.present?
|
@@ -2,33 +2,46 @@ require 'jsonclient'
|
|
2
2
|
|
3
3
|
class Wechat::Core::FollowerProfile
|
4
4
|
|
5
|
+
extend Wechat::Core::Common
|
6
|
+
|
5
7
|
# 批量获取用户基本信息
|
6
|
-
# http://mp.weixin.qq.com/wiki/14/bb5031008f1494a59c6f71fa0f319c66.html
|
8
|
+
# 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
9
|
# 最多支持一次拉取100条。
|
8
10
|
#
|
9
11
|
# Return hash format if success:
|
10
12
|
# {
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
13
|
+
# user_info_list: [
|
14
|
+
# {
|
15
|
+
# subscribe: 1,
|
16
|
+
# openid: <OPEN_ID>,
|
17
|
+
# nickname: <NICK_NAME>,
|
18
|
+
# sex: <GENDER_CODE>,
|
19
|
+
# language: <LANGUAGE_CODE>,
|
20
|
+
# city: <CITY_NAME>,
|
21
|
+
# province: <PROVINCE_NAME>,
|
22
|
+
# country: <COUNTRY_NAME>,
|
23
|
+
# headimgurl: <HEAD_IMAGE_LINK>,
|
24
|
+
# subscribe_time: <SUBSCRIBE_TIME>,
|
25
|
+
# unionid: <UNION_ID>,
|
26
|
+
# remark: <REMARK>,
|
27
|
+
# groupid: <GROUP_ID>
|
28
|
+
# }
|
29
|
+
# ]
|
23
30
|
# }
|
24
|
-
def self.index(access_token, open_ids, language
|
31
|
+
def self.index(access_token, open_ids, language: Wechat::Core::Common::LANGUAGE_SIMPLIFIED_CHINESE)
|
32
|
+
|
33
|
+
assert_present! :access_token, access_token
|
34
|
+
assert_present! :open_ids, open_ids
|
35
|
+
#raise ArgumentError.new('The access_token argument is required.') if access_token.blank?
|
36
|
+
|
25
37
|
followers = open_ids.map { |open_id| { openid: open_id, lang: language } }
|
26
38
|
message = ::JSONClient.new.post "https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token=#{access_token}", { user_list: followers }
|
27
39
|
message.body
|
40
|
+
|
28
41
|
end
|
29
42
|
|
30
43
|
# 获取用户基本信息(UnionID机制)
|
31
|
-
# http://mp.weixin.qq.com/wiki/14/bb5031008f1494a59c6f71fa0f319c66.html
|
44
|
+
# 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
|
32
45
|
# 一次拉取调用最多拉取10000个关注者的OpenID,可以通过多次拉取的方式来满足需求。
|
33
46
|
#
|
34
47
|
# Return hash format if success:
|
@@ -46,7 +59,12 @@ class Wechat::Core::FollowerProfile
|
|
46
59
|
# remark: <REMARK>,
|
47
60
|
# groupid: <GROUP_ID>
|
48
61
|
# }
|
49
|
-
def self.load(access_token, open_id, language
|
62
|
+
def self.load(access_token, open_id, language: 'zh_CN')
|
63
|
+
|
64
|
+
assert_present! :access_token, access_token
|
65
|
+
assert_present! :open_id, open_id
|
66
|
+
#raise ArgumentError.new('The access_token argument is required.') if access_token.blank?
|
67
|
+
|
50
68
|
message = ::JSONClient.new.get 'https://api.weixin.qq.com/cgi-bin/user/info',
|
51
69
|
{
|
52
70
|
access_token: access_token,
|
@@ -2,12 +2,17 @@ require 'jsonclient'
|
|
2
2
|
|
3
3
|
class Wechat::Core::ServerAddress
|
4
4
|
|
5
|
+
extend Wechat::Core::Common
|
6
|
+
|
5
7
|
# 获取微信服务器IP地址
|
6
8
|
# http://mp.weixin.qq.com/wiki/0/2ad4b6bfd29f30f71d39616c2a0fcedc.html
|
7
9
|
#
|
8
10
|
# Return hash format if success:
|
9
11
|
# { ip_list: [ <IP_ADDRESS_1>, <IP_ADDRESS_2>, ... ] }
|
10
12
|
def self.index(access_token)
|
13
|
+
|
14
|
+
assert_present! :access_token, access_token
|
15
|
+
|
11
16
|
message = ::JSONClient.new.get 'https://api.weixin.qq.com/cgi-bin/getcallbackip', { access_token: access_token }
|
12
17
|
message.body
|
13
18
|
end
|
@@ -2,9 +2,29 @@ require 'jsonclient'
|
|
2
2
|
|
3
3
|
class Wechat::Core::TinyLink
|
4
4
|
|
5
|
+
extend Wechat::Core::Common
|
6
|
+
|
5
7
|
# 长链接转短链接接口
|
6
8
|
# http://mp.weixin.qq.com/wiki/10/165c9b15eddcfbd8699ac12b0bd89ae6.html
|
9
|
+
#
|
10
|
+
# Response if success:
|
11
|
+
# {
|
12
|
+
# "errcode": 0,
|
13
|
+
# "errmsg": "ok",
|
14
|
+
# "short_url": "http:\/\/w.url.cn\/s\/AvCo6Ih"
|
15
|
+
# }
|
16
|
+
#
|
17
|
+
# Response if failure:
|
18
|
+
# {
|
19
|
+
# "errcode": 40013,
|
20
|
+
# "errmsg": "invalid appid"
|
21
|
+
# }
|
22
|
+
#
|
7
23
|
def self.create(access_token, link)
|
24
|
+
|
25
|
+
assert_present! :access_token, access_token
|
26
|
+
assert_present! :link, link
|
27
|
+
|
8
28
|
message = ::JSONClient.new.post "https://api.weixin.qq.com/cgi-bin/shorturl?access_token=#{access_token}",
|
9
29
|
{
|
10
30
|
action: 'long2short',
|
data/lib/wechat/core/version.rb
CHANGED
data/lib/wechat/core.rb
CHANGED
data/wechat-core.gemspec
CHANGED
@@ -4,16 +4,14 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'wechat/core/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
|
8
|
-
spec.
|
9
|
-
spec.
|
10
|
-
spec.
|
11
|
-
spec.
|
12
|
-
|
13
|
-
spec.
|
14
|
-
spec.
|
15
|
-
spec.homepage = 'https://github.com/topbitdu/wechat-core'
|
16
|
-
spec.license = 'MIT'
|
7
|
+
spec.name = 'wechat-core'
|
8
|
+
spec.version = Wechat::Core::VERSION
|
9
|
+
spec.authors = [ 'Topbit Du' ]
|
10
|
+
spec.email = [ 'topbit.du@gmail.com' ]
|
11
|
+
spec.summary = 'Wechat Core Library 微信核心库'
|
12
|
+
spec.description = 'Wechat Core Library is a wrapper for calling the core Wechat APIs. 微信核心库封装了微信核心API的调用。'
|
13
|
+
spec.homepage = 'https://github.com/topbitdu/wechat-core'
|
14
|
+
spec.license = 'MIT'
|
17
15
|
|
18
16
|
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
19
17
|
# delete this section to allow pushing this gem to any host.
|
@@ -29,9 +27,9 @@ Gem::Specification.new do |spec|
|
|
29
27
|
spec.require_paths = [ 'lib' ]
|
30
28
|
|
31
29
|
spec.add_development_dependency 'bundler', '~> 1.11'
|
32
|
-
spec.add_development_dependency 'rake',
|
33
|
-
spec.add_development_dependency 'rspec',
|
30
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
31
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
34
32
|
|
35
|
-
spec.add_dependency 'httpclient', '
|
33
|
+
spec.add_dependency 'httpclient', '>= 2.8'
|
36
34
|
|
37
35
|
end
|
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
|
+
version: '0.4'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Topbit Du
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -56,18 +56,17 @@ dependencies:
|
|
56
56
|
name: httpclient
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '2.
|
61
|
+
version: '2.8'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '2.
|
69
|
-
description:
|
70
|
-
calls.
|
68
|
+
version: '2.8'
|
69
|
+
description: Wechat Core Library is a wrapper for calling the core Wechat APIs. 微信核心库封装了微信核心API的调用。
|
71
70
|
email:
|
72
71
|
- topbit.du@gmail.com
|
73
72
|
executables: []
|
@@ -80,10 +79,12 @@ files:
|
|
80
79
|
- CHANGELOG.md
|
81
80
|
- CODE_OF_CONDUCT.md
|
82
81
|
- Gemfile
|
82
|
+
- Gemfile.lock
|
83
83
|
- LICENSE.txt
|
84
84
|
- README.md
|
85
85
|
- ROADMAP.md
|
86
86
|
- Rakefile
|
87
|
+
- _config.yml
|
87
88
|
- bin/console
|
88
89
|
- bin/setup
|
89
90
|
- lib/wechat/core.rb
|
@@ -115,8 +116,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
116
|
version: '0'
|
116
117
|
requirements: []
|
117
118
|
rubyforge_project:
|
118
|
-
rubygems_version: 2.4
|
119
|
+
rubygems_version: 2.6.4
|
119
120
|
signing_key:
|
120
121
|
specification_version: 4
|
121
|
-
summary: Wechat Core Library
|
122
|
+
summary: Wechat Core Library 微信核心库
|
122
123
|
test_files: []
|