blsm-mp-wx 0.1.9 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +25 -0
- data/blsm-mp-wx.gemspec +1 -1
- data/lib/blsm-mp-wx/version.rb +1 -1
- data/lib/blsm-mp-wx.rb +68 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 198ea4580962e8cf69f1228244b6cef0fc19e024
|
4
|
+
data.tar.gz: 123a830043225e4ebd5a0775d6d24cbce78e3f7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e9754d24532bd904de5b4e702a5da00b92a70599e8422b0f51edc21ea9087e9269613c2c7d38b64bd28ae42b97594c18a7ff9789c1efbefee2b1dc41bfca5bd
|
7
|
+
data.tar.gz: bb6d22b26fb5023424db877f903a197891c7b55bb32bd73aef93cd2a7fe0d73b0aeb8ad1c9a1b7a6392cef00e1dad316f9945a3743c36b25dcbe78b874bf0e35
|
data/README.md
CHANGED
@@ -121,6 +121,31 @@ BlsmMpWx.APP_ID_2='another_app_id' #
|
|
121
121
|
expect(r.id>0).to eq(true)
|
122
122
|
```
|
123
123
|
|
124
|
+
### 获取素材列表
|
125
|
+
|
126
|
+
```ruby
|
127
|
+
|
128
|
+
r = BlsmMpWx.batchget_material(nil, 'news', 0)
|
129
|
+
puts "#{r}\n"
|
130
|
+
expect(r[:item_count]>0).to match true
|
131
|
+
```
|
132
|
+
|
133
|
+
### 获取素材总数
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
r = BlsmMpWx.get_material_count(nil, 'news')
|
137
|
+
puts "#{r}\n"
|
138
|
+
expect(r>0).to match true
|
139
|
+
```
|
140
|
+
|
141
|
+
### 获取永久素材
|
142
|
+
|
143
|
+
```ruby
|
144
|
+
r = BlsmMpWx.get_material(nil, 'AKbKJ9aEePImLoQGcYm9IDEtiHe79PPBEXae7tyGxMc')
|
145
|
+
puts "#{r}\n"
|
146
|
+
expect(r.nil?).to match false
|
147
|
+
```
|
148
|
+
|
124
149
|
## Development
|
125
150
|
|
126
151
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/blsm-mp-wx.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
|
13
13
|
spec.summary = %q{首趣微店微信公众号基本模块}
|
14
14
|
spec.description = %q{包括access_token、js_api_ticket的获取,发送消息,模板消息,生成二维码,获取用户信息等。}
|
15
|
-
spec.homepage = "https://bitbucket.org/
|
15
|
+
spec.homepage = "https://bitbucket.org/Xiaopuzhu/blsm-mp-wx/"
|
16
16
|
|
17
17
|
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
18
|
# delete this section to allow pushing this gem to any host.
|
data/lib/blsm-mp-wx/version.rb
CHANGED
data/lib/blsm-mp-wx.rb
CHANGED
@@ -117,7 +117,6 @@ module BlsmMpWx
|
|
117
117
|
req.params[:access_token] = access_token
|
118
118
|
req.headers['Content-Type'] = 'application/json'
|
119
119
|
req.body = msg.to_json
|
120
|
-
req
|
121
120
|
end
|
122
121
|
|
123
122
|
json_obj = parse_json(response.body)
|
@@ -231,6 +230,74 @@ module BlsmMpWx
|
|
231
230
|
})
|
232
231
|
end
|
233
232
|
|
233
|
+
#批量获取公众号的素材列表
|
234
|
+
#=====Parameters
|
235
|
+
# * +app_id+
|
236
|
+
# * +type+ 素材类型:voice、video、image、news
|
237
|
+
def get_material_count(app_id, type)
|
238
|
+
app_id ||= self.APP_ID
|
239
|
+
access_token = access_token(app_id)
|
240
|
+
return nil unless access_token
|
241
|
+
response = Faraday.new(:url => 'https://api.weixin.qq.com').post do |req|
|
242
|
+
req.url '/cgi-bin/material/get_materialcount'
|
243
|
+
req.headers['Content-Type'] = 'application/json'
|
244
|
+
req.params[:access_token] = access_token
|
245
|
+
end
|
246
|
+
|
247
|
+
json_obj = parse_json(response.body)
|
248
|
+
return nil unless json_obj
|
249
|
+
return nil unless json_obj.has_key?("#{type}_count")
|
250
|
+
json_obj["#{type}_count"].to_i
|
251
|
+
end
|
252
|
+
|
253
|
+
#根据media_id来获取永久素材
|
254
|
+
#=====Parameters
|
255
|
+
# * +app_id+
|
256
|
+
# * +media_id+ 要获取的素材的media_id
|
257
|
+
def get_material(app_id, media_id)
|
258
|
+
app_id ||= self.APP_ID
|
259
|
+
access_token = access_token(app_id)
|
260
|
+
return nil unless access_token
|
261
|
+
response = Faraday.new(:url => 'https://api.weixin.qq.com').post do |req|
|
262
|
+
req.url '/cgi-bin/material/get_material'
|
263
|
+
req.headers['Content-Type'] = 'application/json'
|
264
|
+
req.params[:access_token] = access_token
|
265
|
+
req.body= {media_id: media_id}.to_json
|
266
|
+
end
|
267
|
+
body = response.body
|
268
|
+
json_obj = parse_json(body)
|
269
|
+
return body unless json_obj
|
270
|
+
json_obj.inject({}) { |memo, (key, v)| memo[key.to_s.to_sym]=v; memo }
|
271
|
+
end
|
272
|
+
|
273
|
+
#批量获取公众号的素材列表
|
274
|
+
#=====Parameters
|
275
|
+
# * +app_id+
|
276
|
+
# * +type+ 素材类型:voice、video、image、news
|
277
|
+
# * +offset+
|
278
|
+
# * +count+
|
279
|
+
def batchget_material(app_id, type, offset, count=20)
|
280
|
+
app_id ||= self.APP_ID
|
281
|
+
access_token = access_token(app_id)
|
282
|
+
return nil unless access_token
|
283
|
+
response = Faraday.new(:url => 'https://api.weixin.qq.com').post do |req|
|
284
|
+
req.url '/cgi-bin/material/batchget_material'
|
285
|
+
req.headers['Content-Type'] = 'application/json'
|
286
|
+
data = {
|
287
|
+
type: type,
|
288
|
+
offset: offset,
|
289
|
+
count: count
|
290
|
+
}
|
291
|
+
req.params[:access_token] = access_token
|
292
|
+
req.body = data.to_json
|
293
|
+
end
|
294
|
+
|
295
|
+
json_obj = parse_json(response.body)
|
296
|
+
return nil unless json_obj
|
297
|
+
return nil unless json_obj.has_key?('total_count')
|
298
|
+
json_obj.inject({}) { |memo, (key, v)| memo[key.to_s.to_sym]=v; memo }
|
299
|
+
end
|
300
|
+
|
234
301
|
private
|
235
302
|
#解析json类型的数据,并将最后的数据转为hash或array
|
236
303
|
# +json_data_str+ 要转换的json数据
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blsm-mp-wx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- saxer
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -157,7 +157,7 @@ files:
|
|
157
157
|
- lib/blsm-mp-wx/model/vd_mp_msg.rb
|
158
158
|
- lib/blsm-mp-wx/model/vd_mp_wx.rb
|
159
159
|
- lib/blsm-mp-wx/version.rb
|
160
|
-
homepage: https://bitbucket.org/
|
160
|
+
homepage: https://bitbucket.org/Xiaopuzhu/blsm-mp-wx/
|
161
161
|
licenses:
|
162
162
|
- MIT
|
163
163
|
metadata:
|