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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f8a9175b614f4a055da85f6303f46a43e49960fd
4
- data.tar.gz: fa906a29a4b0b5c7aa4cebc193941af670912185
3
+ metadata.gz: fa7a71f5629b784d99acb5c66f3f1658aa1121ab
4
+ data.tar.gz: 9946d80a5524ccfe3e9a0709f7af2a5ce6ed0edc
5
5
  SHA512:
6
- metadata.gz: fe8b3ff1f7086f4bb70ee9f12ed3faaf0c90dda65a548a0c0ab05db31ef508c5540e65a95e4c40ee2da7c9000a960fad8d5af9a4a07518a215a9cd58c2ec5a03
7
- data.tar.gz: 361b995e41b4b3bc565bd71bfa3ec74d81db33a8519bc09bc2ed26cfd4f745f05fd46ea1b34cad2ea4ebe1400eec4eed3a9e8440effc4bf44274b4bdfe7bd93a
6
+ metadata.gz: ec01435f4bd066a37b728d1cde4fce99398afbf0f356cc5eb686f383aec9d9108c8ab51472f05808e249834f8ccc87f3243608816b4ee0b5f9029244a82b13fd
7
+ data.tar.gz: 6ab156dae07547d8d282dfb7bc149ccc68753d2e4209279294c55e9068c106612c613ae4abcda77742b0cb4870a59871bda53349d9fe1da0fe655886080b2166
data/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  Add this line to your application's Gemfile:
8
8
 
9
9
  ```ruby
10
- gem 'wx_ext', '~> 0.0.3'
10
+ gem 'wx_ext', '~> 0.0.4'
11
11
  ```
12
12
 
13
13
  And then execute:
@@ -1,4 +1,4 @@
1
1
  # encoding: UTF-8
2
2
  module WxExt
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
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 = "https://mp.weixin.qq.com/cgi-bin/filetransfer?action=upload_material&f=json&writetype=doublewrite&groupid=1&ticket_id=#{@ticket_id}&ticket=#{@ticket}&token=#{@token}&lang=zh_CN"
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
- # https://mp.weixin.qq.com/cgi-bin/message?t=message/list&token=1664040225&count=20&day=7
238
- # https://mp.weixin.qq.com/cgi-bin/message?t=message/list&count=20&day=7&token=1664040225&lang=zh_CN
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=1664040225&lang=zh_CN
241
- def quick_reply
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
- def collect_msg
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
- private
249
-
250
- def set_cookie(page, k, v)
251
- case Capybara.current_session.driver
252
- when Capybara::Poltergeist::Driver
253
- page.driver.set_cookie(k, v)
254
- when Capybara::RackTest::Driver
255
- headers = {}
256
- Rack::Utils.set_cookie_header!(headers, k, v)
257
- cookie_string = headers['Set-Cookie']
258
- Capybara.current_session.driver.browser.set_cookie(cookie_string)
259
- when Capybara::Selenium::Driver
260
- page.driver.browser.manage.add_cookie(name: k, value: v)
261
- else
262
- fail 'no cookie-setter implemented for driver '\
263
- "#{Capybara.current_session.driver.class.name}"
264
- end
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
@@ -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', '11111111'
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.3
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-19 00:00:00.000000000 Z
11
+ date: 2014-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler