wx_ext 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/wx_ext/version.rb +1 -1
- data/lib/wx_ext.rb +28 -0
- data/spec/wx_ext/weixin_spec.rb +40 -7
- 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: 797ac4daf9107e77b285eee805cb71bb5823a3af
|
4
|
+
data.tar.gz: ccf4970ab608529ef2dd21e06ff39cba034982f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc9ecd44eb86193b226ed4529c3ddc15321852bd41f5dde86ea8fdedd5a6df1ba2693937325ca8a1d81cff6a10a212b5af71bbbd9200f3b085a7b906f0014a46
|
7
|
+
data.tar.gz: f5f5f609b2fcd25814d24583fb6c95b533fe46a30f60cda3c16b6e4dcad9e3e00e3224d24cd2b4862c0777887b1768dfcda2ccb6cd86fe8ba1ebb95b0facd8b5
|
data/README.md
CHANGED
@@ -25,7 +25,7 @@ And then execute:
|
|
25
25
|
|
26
26
|
## Contributing
|
27
27
|
|
28
|
-
1. Fork it ( https://github.com/
|
28
|
+
1. Fork it ( https://github.com/FlowerWrong/wx_ext/fork )
|
29
29
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
30
30
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
31
31
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/lib/wx_ext/version.rb
CHANGED
data/lib/wx_ext.rb
CHANGED
@@ -6,6 +6,18 @@ require 'json'
|
|
6
6
|
require 'nokogiri'
|
7
7
|
|
8
8
|
module WxExt
|
9
|
+
def self.root
|
10
|
+
File.dirname __dir__
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.lib
|
14
|
+
File.join root, 'lib'
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.spec
|
18
|
+
File.join root, 'spec'
|
19
|
+
end
|
20
|
+
|
9
21
|
class WeiXin
|
10
22
|
attr_accessor :account, :password, :home_url, :token, :user_name, \
|
11
23
|
:ticket_id, :ticket, :cookies, :operation_seq
|
@@ -126,6 +138,22 @@ module WxExt
|
|
126
138
|
JSON.parse post_msg_res.to_s
|
127
139
|
end
|
128
140
|
|
141
|
+
# 图文预览功能
|
142
|
+
def preview_msg(msg_params_with_name)
|
143
|
+
uri = 'cgi-bin/operate_appmsg?sub=preview&t=ajax-appmsg-preview'\
|
144
|
+
"&type=10&token=#{@token}&lang=zh_CN"
|
145
|
+
headers = {
|
146
|
+
referer: 'https://mp.weixin.qq.com/cgi-bin/appmsg?t=media/appmsg_edit'\
|
147
|
+
"&action=edit&type=10&isMul=0&isNew=1&lang=zh_CN&token=#{@token}"
|
148
|
+
}
|
149
|
+
resource = RestClient::Resource.new(@home_url, headers: headers,
|
150
|
+
cookies: @cookies)
|
151
|
+
|
152
|
+
res = resource[uri].post msg_params_with_name
|
153
|
+
# {"ret":"0", "msg":"preview send success!", "appMsgId":"201796045", "fakeid":""}
|
154
|
+
JSON.parse res.to_s
|
155
|
+
end
|
156
|
+
|
129
157
|
# 群发图文消息
|
130
158
|
def broadcast_msg(msg_params)
|
131
159
|
uri = "cgi-bin/masssend?t=ajax-response&token=#{@token}&lang=zh_CN"
|
data/spec/wx_ext/weixin_spec.rb
CHANGED
@@ -21,6 +21,38 @@ describe WxExt::WeiXin do
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
+
it "should preview msg method should preview a msg to me" do
|
25
|
+
res_hash = @weixin.login
|
26
|
+
flag = @weixin.init
|
27
|
+
file = File.new(File.join(WxExt.spec, "test.png"), 'rb')
|
28
|
+
file_hash = @weixin.upload_file(file, "test.png")
|
29
|
+
file_id = file_hash["content"]
|
30
|
+
msg_params_with_name = {
|
31
|
+
AppMsgId: '',
|
32
|
+
ajax: 1,
|
33
|
+
author0: '作者' + rand.to_s,
|
34
|
+
content0: '正文' + rand.to_s,
|
35
|
+
count: 1,
|
36
|
+
digest0: 'test摘要' + rand.to_s,
|
37
|
+
f: 'json',
|
38
|
+
fileid0: file_id,
|
39
|
+
lang: 'zh_CN',
|
40
|
+
preusername: 'nan474947',
|
41
|
+
random: rand,
|
42
|
+
show_cover_pic0: 1, # 0 => 封面图片不显示在正文中
|
43
|
+
sourceurl0: 'http://thecampus.cc/' + rand.to_s,
|
44
|
+
title0: 'test标题' + rand.to_s,
|
45
|
+
token: @weixin.token,
|
46
|
+
vid: ''
|
47
|
+
}
|
48
|
+
|
49
|
+
msg_hash = @weixin.preview_msg(msg_params_with_name)
|
50
|
+
puts "==" * 20
|
51
|
+
puts msg_hash
|
52
|
+
expect(msg_hash["ret"].to_s).to eql("0")
|
53
|
+
end
|
54
|
+
|
55
|
+
|
24
56
|
it 'should reply to yang' do
|
25
57
|
res_hash = @weixin.login
|
26
58
|
flag = @weixin.init
|
@@ -116,8 +148,8 @@ describe WxExt::WeiXin do
|
|
116
148
|
puts @weixin.token
|
117
149
|
puts @weixin.ticket_id
|
118
150
|
puts @weixin.ticket
|
119
|
-
file = File.new("
|
120
|
-
file_hash = @weixin.upload_file(file, "
|
151
|
+
file = File.new(File.join(WxExt.spec, "test.png"), 'rb')
|
152
|
+
file_hash = @weixin.upload_file(file, "test.png")
|
121
153
|
puts "==" * 20
|
122
154
|
puts file_hash
|
123
155
|
expect(file_hash["base_resp"]["ret"].to_s).to eql("0")
|
@@ -126,8 +158,8 @@ describe WxExt::WeiXin do
|
|
126
158
|
it "should upload_single_msg method should upload a msg to sucaizhongxin" do
|
127
159
|
res_hash = @weixin.login
|
128
160
|
flag = @weixin.init
|
129
|
-
file = File.new("
|
130
|
-
file_hash = @weixin.upload_file(file, "
|
161
|
+
file = File.new(File.join(WxExt.spec, "test.png"), 'rb')
|
162
|
+
file_hash = @weixin.upload_file(file, "test.png")
|
131
163
|
file_id = file_hash["content"]
|
132
164
|
single_msg_params = {
|
133
165
|
AppMsgId: '',
|
@@ -140,7 +172,7 @@ describe WxExt::WeiXin do
|
|
140
172
|
fileid0: file_id,
|
141
173
|
lang: 'zh_CN',
|
142
174
|
random: rand,
|
143
|
-
show_cover_pic0: 1,
|
175
|
+
show_cover_pic0: 1, # 0 => 封面图片不显示在正文中
|
144
176
|
sourceurl0: 'http://thecampus.cc/' + rand.to_s,
|
145
177
|
title0: 'test标题' + rand.to_s,
|
146
178
|
token: @weixin.token,
|
@@ -155,8 +187,8 @@ describe WxExt::WeiXin do
|
|
155
187
|
it "should upload_multi_msg method should upload multi msg to sucaizhongxin" do
|
156
188
|
res_hash = @weixin.login
|
157
189
|
flag = @weixin.init
|
158
|
-
file = File.new("
|
159
|
-
file_hash = @weixin.upload_file(file, "
|
190
|
+
file = File.new(File.join(WxExt.spec, "test.png"), 'rb')
|
191
|
+
file_hash = @weixin.upload_file(file, "test.png")
|
160
192
|
file_id = file_hash["content"]
|
161
193
|
msg_params = {
|
162
194
|
AppMsgId: '',
|
@@ -230,4 +262,5 @@ describe WxExt::WeiXin do
|
|
230
262
|
puts msg_hash["app_msg_info"]["item"][0]["app_id"]
|
231
263
|
expect(msg_hash["base_resp"]["ret"].to_s).to eql("0")
|
232
264
|
end
|
265
|
+
|
233
266
|
end
|
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.5
|
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
|
+
date: 2014-12-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
117
|
version: '0'
|
118
118
|
requirements: []
|
119
119
|
rubyforge_project:
|
120
|
-
rubygems_version: 2.4.
|
120
|
+
rubygems_version: 2.4.5
|
121
121
|
signing_key:
|
122
122
|
specification_version: 4
|
123
123
|
summary: a gem to hack mp.weixin.qq.com
|