wx_ext 0.0.3 → 0.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/README.md +1 -1
- data/lib/wx_ext/version.rb +1 -1
- data/lib/wx_ext.rb +97 -23
- data/spec/wx_ext/weixin_spec.rb +46 -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: fa7a71f5629b784d99acb5c66f3f1658aa1121ab
|
4
|
+
data.tar.gz: 9946d80a5524ccfe3e9a0709f7af2a5ce6ed0edc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec01435f4bd066a37b728d1cde4fce99398afbf0f356cc5eb686f383aec9d9108c8ab51472f05808e249834f8ccc87f3243608816b4ee0b5f9029244a82b13fd
|
7
|
+
data.tar.gz: 6ab156dae07547d8d282dfb7bc149ccc68753d2e4209279294c55e9068c106612c613ae4abcda77742b0cb4870a59871bda53349d9fe1da0fe655886080b2166
|
data/README.md
CHANGED
data/lib/wx_ext/version.rb
CHANGED
data/lib/wx_ext.rb
CHANGED
@@ -83,7 +83,10 @@ module WxExt
|
|
83
83
|
|
84
84
|
# 上传图片素材到素材中心
|
85
85
|
def upload_file(file, file_name, folder = '/cgi-bin/uploads')
|
86
|
-
upload_url =
|
86
|
+
upload_url = 'https://mp.weixin.qq.com/cgi-bin/filetransfer'\
|
87
|
+
'?action=upload_material&f=json&writetype=doublewrite'\
|
88
|
+
"&groupid=1&ticket_id=#{@ticket_id}"\
|
89
|
+
"&ticket=#{@ticket}&token=#{@token}&lang=zh_CN"
|
87
90
|
response = RestClient.post upload_url, file: file, \
|
88
91
|
Filename: file_name, \
|
89
92
|
folder: folder
|
@@ -234,34 +237,105 @@ module WxExt
|
|
234
237
|
return_hash
|
235
238
|
end
|
236
239
|
|
237
|
-
|
238
|
-
|
240
|
+
def get_fans_count
|
241
|
+
url = 'https://mp.weixin.qq.com/cgi-bin/contactmanage?t=user/index'\
|
242
|
+
"&pagesize=10&pageidx=0&type=0&token=#{ @token }&lang=zh_CN"
|
243
|
+
res = RestClient.get(url, cookies: @cookies)
|
244
|
+
reg = /.*pageIdx\s*:\s*(\d*).*pageCount\s*:\s*(\d*).*pageSize\s*:\s*(\d*).*groupsList\s*:\s*\((.*)\)\.groups,.*friendsList\s*:\s*\((.*)\)\.contacts,.*totalCount\s*:\s*\'(\d)\'\s*\*\s*.*/m
|
245
|
+
return_hash = {
|
246
|
+
status: -1,
|
247
|
+
msg: 'system_error'
|
248
|
+
}
|
249
|
+
if reg =~ res.to_s
|
250
|
+
return_hash = {
|
251
|
+
status: 0,
|
252
|
+
msg: 'ok',
|
253
|
+
page_index: $1,
|
254
|
+
page_count: $2,
|
255
|
+
page_size: $3,
|
256
|
+
group_list: JSON.parse($4)['groups'],
|
257
|
+
friends_list: JSON.parse($5)['contacts'],
|
258
|
+
total_count: $6
|
259
|
+
}
|
260
|
+
end
|
261
|
+
return_hash
|
262
|
+
end
|
239
263
|
|
240
|
-
# https://mp.weixin.qq.com/cgi-bin/singlesend?t=ajax-response&f=json&token=
|
241
|
-
|
264
|
+
# https://mp.weixin.qq.com/cgi-bin/singlesend?t=ajax-response&f=json&token=593714377&lang=zh_CN
|
265
|
+
# {"base_resp":{"ret":10706,"err_msg":"customer block"}} 48小时内的才行
|
266
|
+
# {"base_resp":{"ret":0,"err_msg":"ok"}}
|
267
|
+
# 快速回复
|
268
|
+
def quick_reply(content, quickreplyid, tofakeid)
|
269
|
+
post_uri = 'cgi-bin/singlesend'\
|
270
|
+
"?t=ajax-response&f=json&token=#{ @token }&lang=zh_CN"
|
271
|
+
params = {
|
272
|
+
ajax: 1,
|
273
|
+
content: content,
|
274
|
+
f: 'json',
|
275
|
+
imgcode: '',
|
276
|
+
lang: 'zh_CN',
|
277
|
+
mask: false,
|
278
|
+
quickreplyid: quickreplyid,
|
279
|
+
random: rand,
|
280
|
+
tofakeid: tofakeid,
|
281
|
+
token: @token,
|
282
|
+
type: 1
|
283
|
+
}
|
284
|
+
headers = {
|
285
|
+
referer: 'https://mp.weixin.qq.com/cgi-bin/message'\
|
286
|
+
"?t=message/list&count=20&day=7&token=#{ @token }&lang=zh_CN"
|
287
|
+
}
|
288
|
+
resource = RestClient::Resource.new(@home_url, headers: headers,
|
289
|
+
cookies: @cookies)
|
290
|
+
res = resource[post_uri].post params
|
291
|
+
JSON.parse res.to_s
|
242
292
|
end
|
243
293
|
|
244
294
|
# https://mp.weixin.qq.com/cgi-bin/setstarmessage?t=ajax-setstarmessage&token=1664040225&lang=zh_CN
|
245
|
-
|
295
|
+
# { "ret":0, "msg":"sys ok"}
|
296
|
+
# 收藏消息
|
297
|
+
def collect_msg(msgid)
|
298
|
+
uri = "cgi-bin/setstarmessage?t=ajax-setstarmessage&token=#{ @token }&lang=zh_CN"
|
299
|
+
params = {
|
300
|
+
ajax: 1,
|
301
|
+
f: 'json',
|
302
|
+
lang: 'zh_CN',
|
303
|
+
msgid: msgid,
|
304
|
+
random: rand,
|
305
|
+
token: @token,
|
306
|
+
value: 1
|
307
|
+
}
|
308
|
+
headers = {
|
309
|
+
referer: 'https://mp.weixin.qq.com/cgi-bin/message'\
|
310
|
+
"?t=message/list&token=#{ @token }&count=20&day=7"
|
311
|
+
}
|
312
|
+
resource = RestClient::Resource.new(@home_url, headers: headers,
|
313
|
+
cookies: @cookies)
|
314
|
+
res = resource[uri].post params
|
315
|
+
JSON.parse res.to_s
|
246
316
|
end
|
247
317
|
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
318
|
+
# 取消收藏消息
|
319
|
+
def un_collect_msg(msgid)
|
320
|
+
uri = "cgi-bin/setstarmessage?t=ajax-setstarmessage&token=#{ @token }&lang=zh_CN"
|
321
|
+
params = {
|
322
|
+
ajax: 1,
|
323
|
+
f: 'json',
|
324
|
+
lang: 'zh_CN',
|
325
|
+
msgid: msgid,
|
326
|
+
random: rand,
|
327
|
+
token: @token,
|
328
|
+
value: 0
|
329
|
+
}
|
330
|
+
headers = {
|
331
|
+
referer: 'https://mp.weixin.qq.com/cgi-bin/message'\
|
332
|
+
"?t=message/list&token=#{ @token }&count=20&day=7"
|
333
|
+
}
|
334
|
+
resource = RestClient::Resource.new(@home_url, headers: headers,
|
335
|
+
cookies: @cookies)
|
336
|
+
res = resource[uri].post params
|
337
|
+
# { "ret":0, "msg":"sys ok"}
|
338
|
+
JSON.parse res.to_s
|
265
339
|
end
|
266
340
|
end
|
267
341
|
end
|
data/spec/wx_ext/weixin_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
describe WxExt::WeiXin do
|
5
5
|
before(:all) do
|
6
|
-
@weixin = WxExt::WeiXin.new 'flowerwrong', '
|
6
|
+
@weixin = WxExt::WeiXin.new 'flowerwrong@hotmail.com', '1*flower@wrong*1'
|
7
7
|
end
|
8
8
|
|
9
9
|
it 'should login to the mp' do
|
@@ -21,6 +21,51 @@ describe WxExt::WeiXin do
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
+
it 'should reply to yang' do
|
25
|
+
res_hash = @weixin.login
|
26
|
+
flag = @weixin.init
|
27
|
+
if flag
|
28
|
+
quick_reply_res_hash = @weixin.quick_reply('测试回复2', 201123100, 204060720)
|
29
|
+
puts '==' * 20
|
30
|
+
puts quick_reply_res_hash
|
31
|
+
expect(quick_reply_res_hash['base_resp']['ret'].to_s).to eql('0')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should star msg' do
|
36
|
+
res_hash = @weixin.login
|
37
|
+
flag = @weixin.init
|
38
|
+
if flag
|
39
|
+
star_res_hash = @weixin.collect_msg('201123100')
|
40
|
+
puts '==' * 20
|
41
|
+
puts star_res_hash
|
42
|
+
expect(star_res_hash['ret'].to_s).to eql('0')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should un star msg' do
|
47
|
+
res_hash = @weixin.login
|
48
|
+
flag = @weixin.init
|
49
|
+
if flag
|
50
|
+
star_res_hash = @weixin.un_collect_msg('201123100')
|
51
|
+
puts '==' * 20
|
52
|
+
puts star_res_hash
|
53
|
+
expect(star_res_hash['ret'].to_s).to eql('0')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
it 'should get fans count' do
|
59
|
+
res_hash = @weixin.login
|
60
|
+
flag = @weixin.init
|
61
|
+
if flag
|
62
|
+
fans_res_hash = @weixin.get_fans_count
|
63
|
+
puts '==' * 20
|
64
|
+
puts fans_res_hash
|
65
|
+
expect(fans_res_hash[:status]).to eql(0)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
24
69
|
it 'should get fakeids and msg ids' do
|
25
70
|
res_hash = @weixin.login
|
26
71
|
flag = @weixin.init
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wx_ext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- flowerwrong
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|