wx_ext 0.1.3 → 0.1.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/api/base.rb +153 -0
- data/lib/wx_ext/api/js.rb +50 -0
- data/lib/wx_ext/api/menu.rb +31 -0
- data/lib/wx_ext/api/msg.rb +20 -0
- data/lib/wx_ext/api/user/group.rb +46 -0
- data/lib/wx_ext/api/user.rb +47 -0
- data/lib/wx_ext/api.rb +11 -0
- data/lib/wx_ext/helper.rb +22 -0
- data/lib/wx_ext/sougou_weixin.rb +4 -0
- data/lib/wx_ext/version.rb +1 -1
- data/lib/wx_ext/wei_xin.rb +383 -0
- data/lib/wx_ext.rb +5 -376
- data/spec/wx_ext/api/base_spec.rb +43 -0
- data/spec/wx_ext/api/js_spec.rb +20 -0
- data/spec/wx_ext/api/menu_spec.rb +5 -0
- data/spec/wx_ext/api/msg_spec.rb +5 -0
- data/spec/wx_ext/api/user/group_spec.rb +22 -0
- data/spec/wx_ext/api/user_spec.rb +15 -0
- data/spec/wx_ext/weixin_spec.rb +2 -2
- data/wx_ext.gemspec +6 -5
- metadata +53 -17
data/lib/wx_ext.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
+
|
2
3
|
require 'wx_ext/version'
|
3
4
|
require 'wx_ext/sougou_weixin'
|
5
|
+
require 'wx_ext/wei_xin'
|
6
|
+
require 'wx_ext/api'
|
4
7
|
|
5
|
-
|
6
|
-
|
7
|
-
require 'json'
|
8
|
-
require 'nokogiri'
|
9
|
-
|
8
|
+
# 微信扩展接口和基本接口
|
9
|
+
# @author FuShengYang
|
10
10
|
module WxExt
|
11
11
|
def self.root
|
12
12
|
File.dirname __dir__
|
@@ -19,375 +19,4 @@ module WxExt
|
|
19
19
|
def self.spec
|
20
20
|
File.join root, 'spec'
|
21
21
|
end
|
22
|
-
|
23
|
-
class WeiXin
|
24
|
-
attr_accessor :account, :password, :home_url, :token, :user_name, \
|
25
|
-
:ticket_id, :ticket, :cookies, :operation_seq
|
26
|
-
def initialize(account, password)
|
27
|
-
@account = account
|
28
|
-
@password = password
|
29
|
-
@home_url = 'https://mp.weixin.qq.com'
|
30
|
-
@token = nil
|
31
|
-
@ticket = nil
|
32
|
-
@user_name = nil
|
33
|
-
@ticket_id = nil
|
34
|
-
@cookies = {}
|
35
|
-
@operation_seq = ''
|
36
|
-
end
|
37
|
-
|
38
|
-
# 使用用户名和密码登陆微信公众平台获取access_token, 过期时间是7200s
|
39
|
-
def login
|
40
|
-
password = Digest::MD5.hexdigest @password
|
41
|
-
login_headers = {
|
42
|
-
referer: 'https://mp.weixin.qq.com/'
|
43
|
-
}
|
44
|
-
login_params = {
|
45
|
-
username: @account,
|
46
|
-
pwd: password,
|
47
|
-
imgcode: '',
|
48
|
-
f: 'json'
|
49
|
-
}
|
50
|
-
|
51
|
-
resource = RestClient::Resource.new(@home_url, headers: login_headers)
|
52
|
-
res = resource['cgi-bin/login'].post login_params
|
53
|
-
@cookies = res.cookies
|
54
|
-
return_hash = {
|
55
|
-
status: 0,
|
56
|
-
msg: 'ok'
|
57
|
-
}
|
58
|
-
# {"base_resp"=>{"ret"=>0, "err_msg"=>"ok"}, "redirect_url"=>"/cgi-bin/home?t=home/index&lang=zh_CN&token=1869497342"}
|
59
|
-
# {"base_resp":{"ret":-8,"err_msg":"need verify code"}}
|
60
|
-
# {"base_resp":{"ret":-23,"err_msg":"acct\/password error"}}
|
61
|
-
# {"base_resp":{"ret":-21,"err_msg":"user not exist"}}
|
62
|
-
# https://mp.weixin.qq.com/cgi-bin/verifycode?username=tuodan@thecampus.cc&r=1415774604450
|
63
|
-
res_hash = JSON.parse res.to_s
|
64
|
-
sta = res_hash['base_resp']['ret'].to_s
|
65
|
-
if sta == '0'
|
66
|
-
token_reg = /.*token=(\d+)\".*/
|
67
|
-
@token = $1 if token_reg =~ res.to_s
|
68
|
-
elsif sta == '-8'
|
69
|
-
return_hash = {
|
70
|
-
status: -8,
|
71
|
-
msg: 'need_varify_code'
|
72
|
-
}
|
73
|
-
elsif sta == '-23'
|
74
|
-
return_hash = {
|
75
|
-
status: -23,
|
76
|
-
msg: 'password_error'
|
77
|
-
}
|
78
|
-
elsif sta == '-21'
|
79
|
-
return_hash = {
|
80
|
-
status: -21,
|
81
|
-
msg: 'user_not_exist'
|
82
|
-
}
|
83
|
-
else
|
84
|
-
return_hash = {
|
85
|
-
status: -1,
|
86
|
-
msg: 'system_error'
|
87
|
-
}
|
88
|
-
end
|
89
|
-
return_hash
|
90
|
-
end
|
91
|
-
|
92
|
-
# 初始化 ticket, cookies, operation_seq, user_name 等等信息
|
93
|
-
def init
|
94
|
-
msg_send_url = 'https://mp.weixin.qq.com/cgi-bin/masssendpage'\
|
95
|
-
"?t=mass/send&token=#{@token}&lang=zh_CN"
|
96
|
-
msg_send_page = RestClient.get msg_send_url, cookies: @cookies
|
97
|
-
@cookies = @cookies.merge msg_send_page.cookies
|
98
|
-
|
99
|
-
ticket_reg = /.*ticket\s*:\s*\"(\w+)\".*user_name\s*:\s*\"(.*)\",.*nick_name\s*:\s*\"(.*)\".*/m
|
100
|
-
operation_seq_reg = /.*operation_seq\s*:\s*\"(\d+)\".*/
|
101
|
-
@operation_seq = $1 if operation_seq_reg =~ msg_send_page.to_s
|
102
|
-
if ticket_reg =~ msg_send_page.to_s
|
103
|
-
@ticket = $1
|
104
|
-
@user_name = @ticket_id= $2
|
105
|
-
true
|
106
|
-
else
|
107
|
-
false
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
# 上传图片素材到素材中心
|
112
|
-
def upload_file(file, file_name, folder = '/cgi-bin/uploads')
|
113
|
-
upload_url = 'https://mp.weixin.qq.com/cgi-bin/filetransfer'\
|
114
|
-
'?action=upload_material&f=json&writetype=doublewrite'\
|
115
|
-
"&groupid=1&ticket_id=#{@ticket_id}"\
|
116
|
-
"&ticket=#{@ticket}&token=#{@token}&lang=zh_CN"
|
117
|
-
response = RestClient.post upload_url, file: file, \
|
118
|
-
Filename: file_name, \
|
119
|
-
folder: folder
|
120
|
-
JSON.parse response.to_s
|
121
|
-
end
|
122
|
-
|
123
|
-
# 发送单条图文消息到素材中心
|
124
|
-
def upload_single_msg(single_msg_params)
|
125
|
-
post_single_msg_uri = 'cgi-bin/operate_appmsg'\
|
126
|
-
'?t=ajax-response&sub=create&type=10&token'\
|
127
|
-
"=#{@token}&lang=zh_CN"
|
128
|
-
headers = {
|
129
|
-
referer: 'https://mp.weixin.qq.com/cgi-bin/appmsg?t=media/appmsg_edit'\
|
130
|
-
'&action=edit&type=10&isMul=0&isNew=1&lang=zh_CN'\
|
131
|
-
"&token=#{@token}"
|
132
|
-
}
|
133
|
-
resource = RestClient::Resource.new(@home_url, headers: headers,
|
134
|
-
cookies: @cookies)
|
135
|
-
res = resource[post_single_msg_uri].post single_msg_params
|
136
|
-
# {"ret":"0", "msg":"OK"}
|
137
|
-
JSON.parse res.to_s
|
138
|
-
end
|
139
|
-
|
140
|
-
# 发送多图文到素材中心
|
141
|
-
def upload_multi_msg(msg_params)
|
142
|
-
uri = 'cgi-bin/operate_appmsg?t=ajax-response&sub=create&type=10'\
|
143
|
-
"&token=#{@token}&lang=zh_CN"
|
144
|
-
headers = {
|
145
|
-
referer: 'https://mp.weixin.qq.com/cgi-bin/appmsg'\
|
146
|
-
'?t=media/appmsg_edit&action=edit&type=10'\
|
147
|
-
"&isMul=1&isNew=1&lang=zh_CN&token=#{@token}"
|
148
|
-
}
|
149
|
-
resource = RestClient::Resource.new(@home_url, headers: headers,
|
150
|
-
cookies: @cookies)
|
151
|
-
post_msg_res = resource[uri].post msg_params
|
152
|
-
# {"ret":"0", "msg":"OK"}
|
153
|
-
JSON.parse post_msg_res.to_s
|
154
|
-
end
|
155
|
-
|
156
|
-
# 图文预览功能
|
157
|
-
def preview_msg(msg_params_with_name)
|
158
|
-
uri = 'cgi-bin/operate_appmsg?sub=preview&t=ajax-appmsg-preview'\
|
159
|
-
"&type=10&token=#{@token}&lang=zh_CN"
|
160
|
-
headers = {
|
161
|
-
referer: 'https://mp.weixin.qq.com/cgi-bin/appmsg?t=media/appmsg_edit'\
|
162
|
-
"&action=edit&type=10&isMul=0&isNew=1&lang=zh_CN&token=#{@token}"
|
163
|
-
}
|
164
|
-
resource = RestClient::Resource.new(@home_url, headers: headers,
|
165
|
-
cookies: @cookies)
|
166
|
-
|
167
|
-
res = resource[uri].post msg_params_with_name
|
168
|
-
# {"ret":"0", "msg":"preview send success!", "appMsgId":"201796045", "fakeid":""}
|
169
|
-
JSON.parse res.to_s
|
170
|
-
end
|
171
|
-
|
172
|
-
# 群发图文消息
|
173
|
-
def broadcast_msg(msg_params)
|
174
|
-
uri = "cgi-bin/masssend?t=ajax-response&token=#{@token}&lang=zh_CN"
|
175
|
-
headers = {
|
176
|
-
referer: 'https://mp.weixin.qq.com/cgi-bin/masssendpage'\
|
177
|
-
"?t=mass/send&token=#{token}&lang=zh_CN",
|
178
|
-
host: 'mp.weixin.qq.com'
|
179
|
-
}
|
180
|
-
resource = RestClient::Resource.new(@home_url, headers: headers,
|
181
|
-
cookies: @cookies)
|
182
|
-
post_msg_res = resource[uri].post msg_params
|
183
|
-
# {"ret":"0", "msg":"OK"}
|
184
|
-
JSON.parse post_msg_res.to_s
|
185
|
-
end
|
186
|
-
|
187
|
-
# 获取所有的图文列表
|
188
|
-
def get_app_msg_list(msg_begin = 0, msg_count = 10)
|
189
|
-
url = 'https://mp.weixin.qq.com/cgi-bin/appmsg?type=10&action=list'\
|
190
|
-
"&begin=#{msg_begin}&count=#{msg_count}&f=json&token=#{@token}"\
|
191
|
-
"&lang=zh_CN&token=#{@token}&lang=zh_CN&f=json&ajax=1"\
|
192
|
-
"&random=#{rand}"
|
193
|
-
msg_json = RestClient.get url, cookies: @cookies
|
194
|
-
JSON.parse msg_json.to_s
|
195
|
-
end
|
196
|
-
|
197
|
-
# 轮训新消息条数
|
198
|
-
def get_new_msg_num(last_msg_id)
|
199
|
-
uri = 'cgi-bin/getnewmsgnum?f=json&t=ajax-getmsgnum'\
|
200
|
-
"&lastmsgid=#{last_msg_id}&token=#{@token}&lang=zh_CN"
|
201
|
-
post_params = {
|
202
|
-
ajax: 1,
|
203
|
-
f: 'json',
|
204
|
-
lang: 'zh_CN',
|
205
|
-
random: rand,
|
206
|
-
token: @token
|
207
|
-
}
|
208
|
-
post_headers = {
|
209
|
-
referer: 'https://mp.weixin.qq.com/cgi-bin/message?t=message/list'\
|
210
|
-
"&count=20&day=7&token=#{@token}&lang=zh_CN"
|
211
|
-
}
|
212
|
-
resource = RestClient::Resource.new(@home_url, headers: post_headers,
|
213
|
-
cookies: @cookies)
|
214
|
-
res = resource[uri].post post_params
|
215
|
-
JSON.parse res.to_s
|
216
|
-
end
|
217
|
-
|
218
|
-
# 获取联系人信息
|
219
|
-
def get_contact_info(fakeid)
|
220
|
-
uri = 'cgi-bin/getcontactinfo?t=ajax-getcontactinfo'\
|
221
|
-
"&lang=zh_CN&fakeid=#{fakeid}"
|
222
|
-
post_params = {
|
223
|
-
ajax: 1,
|
224
|
-
f: 'json',
|
225
|
-
lang: 'zh_CN',
|
226
|
-
random: rand,
|
227
|
-
token: @token
|
228
|
-
}
|
229
|
-
post_headers = {
|
230
|
-
referer: 'https://mp.weixin.qq.com/cgi-bin/contactmanage?t=user/index'\
|
231
|
-
"&pagesize=10&pageidx=0&type=0&token=#{@token}&lang=zh_CN"
|
232
|
-
}
|
233
|
-
resource = RestClient::Resource.new(@home_url, headers: post_headers,
|
234
|
-
cookies: @cookies)
|
235
|
-
res = resource[uri].post post_params
|
236
|
-
JSON.parse res.to_s
|
237
|
-
end
|
238
|
-
|
239
|
-
# 获取国家列表
|
240
|
-
def get_country_list
|
241
|
-
url = 'https://mp.weixin.qq.com/cgi-bin/getregions'\
|
242
|
-
"?t=setting/ajax-getregions&id=0&token=#{@token}&lang=zh_CN"\
|
243
|
-
"&token=#{@token}&lang=zh_CN&f=json&ajax=1&random=#{rand}"
|
244
|
-
resource = RestClient::Resource.new(url, cookies: @cookies)
|
245
|
-
res = resource.get
|
246
|
-
JSON.parse res.to_s
|
247
|
-
end
|
248
|
-
|
249
|
-
# 获取每日可推送消息数
|
250
|
-
def get_day_msg_count
|
251
|
-
url = 'https://mp.weixin.qq.com/cgi-bin/masssendpage'\
|
252
|
-
"?t=mass/send&token=#{@token}&lang=zh_CN"
|
253
|
-
res = RestClient.get(url, cookies: @cookies)
|
254
|
-
day_msg_count = 0
|
255
|
-
reg = /.*mass_send_left\s*:\s*can_verify_apply\s*\?\s*\'(\d*)\'\*/
|
256
|
-
day_msg_count = $1 if reg =~ res.to_s
|
257
|
-
day_msg_count.to_i
|
258
|
-
end
|
259
|
-
|
260
|
-
# 获取 total_count, count, day, frommsgid, can_search_msg, offset, action=search, keyword, last_msg_id, filterivrmsg=0/1 和 msg_items
|
261
|
-
def get_msg_items(count = 20, day = 7, filterivrmsg = 1, action='', keyword='', frommsgid='', offset='')
|
262
|
-
url = 'https://mp.weixin.qq.com/cgi-bin/message?t=message/list'\
|
263
|
-
"&action=#{action}&keyword=#{keyword}&frommsgid=#{frommsgid}&offset=#{offset}&count=#{count}"\
|
264
|
-
"&day=#{day}filterivrmsg=#{filterivrmsg}&token=#{@token}&lang=zh_CN"
|
265
|
-
resource = RestClient::Resource.new(url, cookies: @cookies)
|
266
|
-
res = resource.get
|
267
|
-
reg = /.*total_count\s*:\s*(\d*).*latest_msg_id\s*:\s*\'(\d*)\'.*list\s*:\s*\((.*)\)\.msg_item,.*filterivrmsg\s*:\s*\"(\d*)\".*/m
|
268
|
-
return_hash = {
|
269
|
-
status: -1,
|
270
|
-
msg: 'system_error'
|
271
|
-
}
|
272
|
-
if reg =~ res.to_s
|
273
|
-
return_hash = {
|
274
|
-
status: 0,
|
275
|
-
msg: 'ok',
|
276
|
-
total_count: $1,
|
277
|
-
latest_msg_id: $2,
|
278
|
-
count: 20,
|
279
|
-
day: 7,
|
280
|
-
frommsgid: '',
|
281
|
-
can_search_msg: '1',
|
282
|
-
offset: '',
|
283
|
-
action: '',
|
284
|
-
keyword: '',
|
285
|
-
msg_items: JSON.parse($3)['msg_item'],
|
286
|
-
filterivrmsg: $4
|
287
|
-
}
|
288
|
-
end
|
289
|
-
return_hash
|
290
|
-
end
|
291
|
-
|
292
|
-
# 获取粉丝数目
|
293
|
-
def get_fans_count
|
294
|
-
url = 'https://mp.weixin.qq.com/cgi-bin/contactmanage?t=user/index'\
|
295
|
-
"&pagesize=10&pageidx=0&type=0&token=#{ @token }&lang=zh_CN"
|
296
|
-
res = RestClient.get(url, cookies: @cookies)
|
297
|
-
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
|
298
|
-
return_hash = {
|
299
|
-
status: -1,
|
300
|
-
msg: 'system_error'
|
301
|
-
}
|
302
|
-
if reg =~ res.to_s
|
303
|
-
return_hash = {
|
304
|
-
status: 0,
|
305
|
-
msg: 'ok',
|
306
|
-
page_index: $1,
|
307
|
-
page_count: $2,
|
308
|
-
page_size: $3,
|
309
|
-
group_list: JSON.parse($4)['groups'],
|
310
|
-
friends_list: JSON.parse($5)['contacts'],
|
311
|
-
total_count: $6
|
312
|
-
}
|
313
|
-
end
|
314
|
-
return_hash
|
315
|
-
end
|
316
|
-
|
317
|
-
# {"base_resp":{"ret":10706,"err_msg":"customer block"}} 48小时内的才行
|
318
|
-
# {"base_resp":{"ret":0,"err_msg":"ok"}}
|
319
|
-
# 快速回复
|
320
|
-
def quick_reply(content, quickreplyid, tofakeid)
|
321
|
-
post_uri = 'cgi-bin/singlesend'\
|
322
|
-
"?t=ajax-response&f=json&token=#{ @token }&lang=zh_CN"
|
323
|
-
params = {
|
324
|
-
ajax: 1,
|
325
|
-
content: content,
|
326
|
-
f: 'json',
|
327
|
-
imgcode: '',
|
328
|
-
lang: 'zh_CN',
|
329
|
-
mask: false,
|
330
|
-
quickreplyid: quickreplyid,
|
331
|
-
random: rand,
|
332
|
-
tofakeid: tofakeid,
|
333
|
-
token: @token,
|
334
|
-
type: 1
|
335
|
-
}
|
336
|
-
headers = {
|
337
|
-
referer: 'https://mp.weixin.qq.com/cgi-bin/message'\
|
338
|
-
"?t=message/list&count=20&day=7&token=#{ @token }&lang=zh_CN"
|
339
|
-
}
|
340
|
-
resource = RestClient::Resource.new(@home_url, headers: headers,
|
341
|
-
cookies: @cookies)
|
342
|
-
res = resource[post_uri].post params
|
343
|
-
JSON.parse res.to_s
|
344
|
-
end
|
345
|
-
|
346
|
-
# https://mp.weixin.qq.com/cgi-bin/setstarmessage?t=ajax-setstarmessage&token=1664040225&lang=zh_CN
|
347
|
-
# { "ret":0, "msg":"sys ok"}
|
348
|
-
# 收藏消息
|
349
|
-
def collect_msg(msgid)
|
350
|
-
uri = "cgi-bin/setstarmessage?t=ajax-setstarmessage&token=#{ @token }&lang=zh_CN"
|
351
|
-
params = {
|
352
|
-
ajax: 1,
|
353
|
-
f: 'json',
|
354
|
-
lang: 'zh_CN',
|
355
|
-
msgid: msgid,
|
356
|
-
random: rand,
|
357
|
-
token: @token,
|
358
|
-
value: 1
|
359
|
-
}
|
360
|
-
headers = {
|
361
|
-
referer: 'https://mp.weixin.qq.com/cgi-bin/message'\
|
362
|
-
"?t=message/list&token=#{ @token }&count=20&day=7"
|
363
|
-
}
|
364
|
-
resource = RestClient::Resource.new(@home_url, headers: headers,
|
365
|
-
cookies: @cookies)
|
366
|
-
res = resource[uri].post params
|
367
|
-
JSON.parse res.to_s
|
368
|
-
end
|
369
|
-
|
370
|
-
# 取消收藏消息
|
371
|
-
def un_collect_msg(msgid)
|
372
|
-
uri = "cgi-bin/setstarmessage?t=ajax-setstarmessage&token=#{ @token }&lang=zh_CN"
|
373
|
-
params = {
|
374
|
-
ajax: 1,
|
375
|
-
f: 'json',
|
376
|
-
lang: 'zh_CN',
|
377
|
-
msgid: msgid,
|
378
|
-
random: rand,
|
379
|
-
token: @token,
|
380
|
-
value: 0
|
381
|
-
}
|
382
|
-
headers = {
|
383
|
-
referer: 'https://mp.weixin.qq.com/cgi-bin/message'\
|
384
|
-
"?t=message/list&token=#{ @token }&count=20&day=7"
|
385
|
-
}
|
386
|
-
resource = RestClient::Resource.new(@home_url, headers: headers,
|
387
|
-
cookies: @cookies)
|
388
|
-
res = resource[uri].post params
|
389
|
-
# { "ret":0, "msg":"sys ok"}
|
390
|
-
JSON.parse res.to_s
|
391
|
-
end
|
392
|
-
end
|
393
22
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe WxExt::Api::Base do
|
5
|
+
before(:all) do
|
6
|
+
@app_id = 'app_id'
|
7
|
+
@access_token_hash = WxExt::Api::Base.get_access_token('app_id', 'app_secret')
|
8
|
+
@access_token = @access_token_hash['access_token']
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should get access_token' do
|
12
|
+
expect(@access_token_hash['expires_in']).to eql(7200)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should get weixin ip list' do
|
16
|
+
res_hash = WxExt::Api::Base.get_weixin_ips(@access_token)
|
17
|
+
puts '=' * 20
|
18
|
+
puts res_hash
|
19
|
+
expect(res_hash['ip_list']).not_to be_empty
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should return a code and msg hash' do
|
23
|
+
res_hash = WxExt::Api::Base.code_msg
|
24
|
+
puts '=' * 20
|
25
|
+
puts res_hash
|
26
|
+
expect(res_hash).not_to be_empty
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should upload a media to weixin' do
|
30
|
+
file = File.new(File.join(WxExt.spec, "test.png"), 'rb')
|
31
|
+
res_hash = WxExt::Api::Base.upload_media(@access_token, 'image', file)
|
32
|
+
puts '=' * 20
|
33
|
+
puts res_hash
|
34
|
+
expect(res_hash['created_at'].to_s).to match(/\d*/)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should download a media from weixin' do
|
38
|
+
file = File.new(File.join(WxExt.spec, "test.png"), 'rb')
|
39
|
+
res_hash = WxExt::Api::Base.upload_media(@access_token, 'image', file)
|
40
|
+
expect(res_hash['created_at'].to_s).to match(/\d*/)
|
41
|
+
WxExt::Api::Base.download_media(@access_token, res_hash['media_id'])
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe WxExt::Api::Js do
|
5
|
+
before(:all) do
|
6
|
+
@app_id = 'app_id'
|
7
|
+
@access_token_hash = WxExt::Api::Base.get_access_token('app_id', 'app_secret')
|
8
|
+
@access_token = @access_token_hash['access_token']
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should get js api ticken' do
|
12
|
+
jsapi_ticket_hash = WxExt::Api::Js.get_jsapi_ticket(@access_token)
|
13
|
+
expect(jsapi_ticket_hash['errcode']).to eql(0)
|
14
|
+
end
|
15
|
+
|
16
|
+
#it 'should get js config' do
|
17
|
+
# config_hash = WxExt::Api::Base.get_jsapi_config(@access_token, '', @app_id)
|
18
|
+
# expect(config_hash[:app_id]).to eql(@app_id)
|
19
|
+
#end
|
20
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe WxExt::Api::User::Group do
|
5
|
+
before(:all) do
|
6
|
+
@app_id = 'app_id'
|
7
|
+
@access_token_hash = WxExt::Api::Base.get_access_token('app_id', 'app_secret')
|
8
|
+
@access_token = @access_token_hash['access_token']
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should create a group, then get all groups' do
|
12
|
+
group_hash = WxExt::Api::User::Group.create_group(@access_token, '众联酒业')
|
13
|
+
puts '-' * 20
|
14
|
+
puts group_hash
|
15
|
+
expect(group_hash['group']).not_to be_empty
|
16
|
+
|
17
|
+
groups = WxExt::Api::User::Group.groups(@access_token)
|
18
|
+
puts '-' * 20
|
19
|
+
puts groups
|
20
|
+
expect(groups).not_to be_empty
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe WxExt::Api::User do
|
5
|
+
before(:all) do
|
6
|
+
@app_id = 'app_id'
|
7
|
+
@access_token_hash = WxExt::Api::Base.get_access_token('app_id', 'app_secret')
|
8
|
+
@access_token = @access_token_hash['access_token']
|
9
|
+
end
|
10
|
+
|
11
|
+
#it 'should get js config' do
|
12
|
+
# config_hash = WxExt::Api::Base.get_jsapi_config(@access_token, '', @app_id)
|
13
|
+
# expect(config_hash[:app_id]).to eql(@app_id)
|
14
|
+
#end
|
15
|
+
end
|
data/spec/wx_ext/weixin_spec.rb
CHANGED
@@ -6,12 +6,12 @@ describe WxExt::WeiXin do
|
|
6
6
|
@weixin = WxExt::WeiXin.new 'username', 'pass'
|
7
7
|
end
|
8
8
|
|
9
|
-
|
9
|
+
|
10
10
|
it 'should login to the mp' do
|
11
11
|
res_hash = @weixin.login
|
12
12
|
expect(res_hash[:status]).to eql(0)
|
13
13
|
end
|
14
|
-
|
14
|
+
=begin
|
15
15
|
it 'should init method should init all params' do
|
16
16
|
res_hash = @weixin.login
|
17
17
|
flag = @weixin.init
|
data/wx_ext.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = WxExt::VERSION
|
9
9
|
spec.authors = ['flowerwrong']
|
10
10
|
spec.email = ['sysuyangkang@gmail.com']
|
11
|
-
spec.summary = %q{
|
12
|
-
spec.description = %q{
|
11
|
+
spec.summary = %q{A gem to hack mp.weixin.qq.com and weixin base api.}
|
12
|
+
spec.description = %q{This gem provide hack mp.weixin.qq.com and weixin open api.}
|
13
13
|
spec.homepage = 'http://thecampus.cc'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
@@ -20,8 +20,9 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency 'bundler', '~> 1.7'
|
22
22
|
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
spec.add_development_dependency 'yard', '~> 0.8'
|
24
|
+
spec.add_development_dependency 'rspec', '~> 3.1'
|
23
25
|
|
24
|
-
spec.
|
25
|
-
spec.add_dependency '
|
26
|
-
spec.add_dependency 'nokogiri'
|
26
|
+
spec.add_dependency 'rest-client', '~> 1.7'
|
27
|
+
spec.add_dependency 'nokogiri', '~> 1.6'
|
27
28
|
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.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- flowerwrong
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,49 +38,63 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: yard
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.8'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.8'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rspec
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
|
-
- - "
|
59
|
+
- - "~>"
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
61
|
+
version: '3.1'
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
|
-
- - "
|
66
|
+
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
68
|
+
version: '3.1'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
70
|
+
name: rest-client
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
|
-
- - "
|
73
|
+
- - "~>"
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
75
|
+
version: '1.7'
|
62
76
|
type: :runtime
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
|
-
- - "
|
80
|
+
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
82
|
+
version: '1.7'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: nokogiri
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
|
-
- - "
|
87
|
+
- - "~>"
|
74
88
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
89
|
+
version: '1.6'
|
76
90
|
type: :runtime
|
77
91
|
prerelease: false
|
78
92
|
version_requirements: !ruby/object:Gem::Requirement
|
79
93
|
requirements:
|
80
|
-
- - "
|
94
|
+
- - "~>"
|
81
95
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
83
|
-
description:
|
96
|
+
version: '1.6'
|
97
|
+
description: This gem provide hack mp.weixin.qq.com and weixin open api.
|
84
98
|
email:
|
85
99
|
- sysuyangkang@gmail.com
|
86
100
|
executables: []
|
@@ -93,10 +107,25 @@ files:
|
|
93
107
|
- README.md
|
94
108
|
- Rakefile
|
95
109
|
- lib/wx_ext.rb
|
110
|
+
- lib/wx_ext/api.rb
|
111
|
+
- lib/wx_ext/api/base.rb
|
112
|
+
- lib/wx_ext/api/js.rb
|
113
|
+
- lib/wx_ext/api/menu.rb
|
114
|
+
- lib/wx_ext/api/msg.rb
|
115
|
+
- lib/wx_ext/api/user.rb
|
116
|
+
- lib/wx_ext/api/user/group.rb
|
117
|
+
- lib/wx_ext/helper.rb
|
96
118
|
- lib/wx_ext/sougou_weixin.rb
|
97
119
|
- lib/wx_ext/version.rb
|
120
|
+
- lib/wx_ext/wei_xin.rb
|
98
121
|
- spec/spec_helper.rb
|
99
122
|
- spec/test.png
|
123
|
+
- spec/wx_ext/api/base_spec.rb
|
124
|
+
- spec/wx_ext/api/js_spec.rb
|
125
|
+
- spec/wx_ext/api/menu_spec.rb
|
126
|
+
- spec/wx_ext/api/msg_spec.rb
|
127
|
+
- spec/wx_ext/api/user/group_spec.rb
|
128
|
+
- spec/wx_ext/api/user_spec.rb
|
100
129
|
- spec/wx_ext/sougou_weixin_spec.rb
|
101
130
|
- spec/wx_ext/weixin_spec.rb
|
102
131
|
- wx_ext.gemspec
|
@@ -123,9 +152,16 @@ rubyforge_project:
|
|
123
152
|
rubygems_version: 2.4.5
|
124
153
|
signing_key:
|
125
154
|
specification_version: 4
|
126
|
-
summary:
|
155
|
+
summary: A gem to hack mp.weixin.qq.com and weixin base api.
|
127
156
|
test_files:
|
128
157
|
- spec/spec_helper.rb
|
129
158
|
- spec/test.png
|
159
|
+
- spec/wx_ext/api/base_spec.rb
|
160
|
+
- spec/wx_ext/api/js_spec.rb
|
161
|
+
- spec/wx_ext/api/menu_spec.rb
|
162
|
+
- spec/wx_ext/api/msg_spec.rb
|
163
|
+
- spec/wx_ext/api/user/group_spec.rb
|
164
|
+
- spec/wx_ext/api/user_spec.rb
|
130
165
|
- spec/wx_ext/sougou_weixin_spec.rb
|
131
166
|
- spec/wx_ext/weixin_spec.rb
|
167
|
+
has_rdoc:
|