wx_ext 0.1.5 → 0.1.6
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/lib/wx_ext/api/base.rb +1 -0
- data/lib/wx_ext/api/customer_service.rb +2 -0
- data/lib/wx_ext/api/js.rb +1 -0
- data/lib/wx_ext/api/mass.rb +2 -0
- data/lib/wx_ext/api/menu.rb +2 -0
- data/lib/wx_ext/api/msg.rb +2 -0
- data/lib/wx_ext/api/qrcode.rb +2 -0
- data/lib/wx_ext/api/semantic.rb +2 -0
- data/lib/wx_ext/api/template_msg.rb +2 -0
- data/lib/wx_ext/api/user/group.rb +2 -0
- data/lib/wx_ext/api/user.rb +3 -1
- data/lib/wx_ext/version.rb +1 -1
- data/spec/wx_ext/api/customer_service_spec.rb +21 -0
- data/spec/wx_ext/api/menu_spec.rb +52 -0
- data/spec/wx_ext/api/semantic_spec.rb +23 -0
- data/spec/wx_ext/api/template_msg_spec.rb +15 -0
- data/spec/wx_ext/api/user_spec.rb +31 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23c3940298003a23d43bbd1ff4ee9af7211a3221
|
4
|
+
data.tar.gz: d62ae090872a99c079048c344418b25c5fb0bf6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a92c4ac504ebe1b2d8602cc5d7cd094d302bdd925c5d57c37c2fe036364be52618dd33dbbfcb98361d065fd49b3ec2af3bd57e00e29b4b0e375177c015ef5381
|
7
|
+
data.tar.gz: bceaf355c71931d988c0d9879a5234be4cf6408c794fb53888b5e1789ba095f0c53959bb689ac76949895ae77078dc01c4eb81d5d4d64c79e7fea3a959c39199
|
data/lib/wx_ext/api/base.rb
CHANGED
data/lib/wx_ext/api/js.rb
CHANGED
data/lib/wx_ext/api/mass.rb
CHANGED
data/lib/wx_ext/api/menu.rb
CHANGED
data/lib/wx_ext/api/msg.rb
CHANGED
data/lib/wx_ext/api/qrcode.rb
CHANGED
data/lib/wx_ext/api/semantic.rb
CHANGED
data/lib/wx_ext/api/user.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
+
require 'wx_ext/helper'
|
4
|
+
|
3
5
|
module WxExt
|
4
6
|
# Weixin api
|
5
7
|
#
|
@@ -40,7 +42,7 @@ module WxExt
|
|
40
42
|
# @param [Enumerable<String>] access_token
|
41
43
|
# @param [Enumerable<String>] next_openid
|
42
44
|
# @return [Hash] Json based hash.
|
43
|
-
def user_list(access_token, next_openid)
|
45
|
+
def user_list(access_token, next_openid=nil)
|
44
46
|
url = 'https://api.weixin.qq.com/cgi-bin/user/get'\
|
45
47
|
"?access_token=#{access_token}"
|
46
48
|
url += "&next_openid=#{next_openid}" if next_openid
|
data/lib/wx_ext/version.rb
CHANGED
@@ -2,4 +2,25 @@
|
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
describe WxExt::Api::CustomerService 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 reply text msg to user' do
|
12
|
+
res_hash = WxExt::Api::CustomerService.reply_msg(@access_token, 'oK_Xnt2a9LAh0cbYuBGFSPxnvu1w', 'text', { content: 'Hello World' })
|
13
|
+
puts '=' * 20
|
14
|
+
puts res_hash
|
15
|
+
expect(res_hash['errcode']).to eql(0)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should reply img msg to user' do
|
19
|
+
file = File.new(File.join(WxExt.spec, "test.png"), 'rb')
|
20
|
+
file_hash = WxExt::Api::Base.upload_media(@access_token, 'image', file)
|
21
|
+
res_hash = WxExt::Api::CustomerService.reply_msg(@access_token, 'oK_Xnt2a9LAh0cbYuBGFSPxnvu1w', 'image', { media_id: file_hash['media_id'] })
|
22
|
+
puts '=' * 20
|
23
|
+
puts res_hash
|
24
|
+
expect(res_hash['errcode']).to eql(0)
|
25
|
+
end
|
5
26
|
end
|
@@ -2,4 +2,56 @@
|
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
describe WxExt::Api::Menu 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 menu and then del it' do
|
12
|
+
menu_hash = {
|
13
|
+
button: [
|
14
|
+
{
|
15
|
+
type: 'click',
|
16
|
+
name: '今日歌曲',
|
17
|
+
key: 'V1001_TODAY_MUSIC'
|
18
|
+
},
|
19
|
+
{
|
20
|
+
name: '菜单',
|
21
|
+
sub_button: [
|
22
|
+
{
|
23
|
+
type: 'view',
|
24
|
+
name: '搜索',
|
25
|
+
url: 'http://www.soso.com/'
|
26
|
+
},
|
27
|
+
{
|
28
|
+
type: 'view',
|
29
|
+
name: '视频',
|
30
|
+
url: 'http://v.qq.com/'
|
31
|
+
},
|
32
|
+
{
|
33
|
+
type: 'click',
|
34
|
+
name: '赞一下我们',
|
35
|
+
key: 'V1001_GOOD'
|
36
|
+
}
|
37
|
+
]
|
38
|
+
}
|
39
|
+
]
|
40
|
+
}
|
41
|
+
create_hash = WxExt::Api::Menu.create_menu(@access_token, menu_hash)
|
42
|
+
puts '=' * 20
|
43
|
+
puts create_hash
|
44
|
+
expect(create_hash['errcode']).to eql(0)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should get all menus and then del it' do
|
48
|
+
res_hash = WxExt::Api::Menu.menus(@access_token)
|
49
|
+
puts '=' * 20
|
50
|
+
puts res_hash
|
51
|
+
expect(res_hash['menu']).not_to be_empty
|
52
|
+
|
53
|
+
del_hash = WxExt::Api::Menu.del_menu(@access_token)
|
54
|
+
expect(del_hash['errcode']).to eql(0)
|
55
|
+
puts del_hash
|
56
|
+
end
|
5
57
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe WxExt::Api::Semantic 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 发送语义理解请求' do
|
12
|
+
semantic_hash = {
|
13
|
+
query: '查一下明天从北京到上海的南航机票',
|
14
|
+
city: '北京',
|
15
|
+
category: 'flight,hotel',
|
16
|
+
appid: @app_id,
|
17
|
+
uid: 'oK_Xnt2a9LAh0cbYuBGFSPxnvu1w'
|
18
|
+
}
|
19
|
+
hash = WxExt::Api::Semantic.semantic_search(@access_token, semantic_hash)
|
20
|
+
puts hash
|
21
|
+
expect(hash['errcode']).to eql(0)
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe WxExt::Api::TemplateMsg 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
|
@@ -8,8 +8,35 @@ describe WxExt::Api::User do
|
|
8
8
|
@access_token = @access_token_hash['access_token']
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
it 'should get user list' do
|
12
|
+
user_list_hash = WxExt::Api::User.user_list(@access_token)
|
13
|
+
puts '-' * 20
|
14
|
+
puts user_list_hash
|
15
|
+
expect(user_list_hash['total'].to_s).to match(/\d*/)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should get user info of oK_Xnt2a9LAh0cbYuBGFSPxnvu1w' do
|
19
|
+
user_hash = WxExt::Api::User.get_user_base_info(@access_token, 'oK_Xnt2a9LAh0cbYuBGFSPxnvu1w')
|
20
|
+
puts '-' * 20
|
21
|
+
puts user_hash
|
22
|
+
expect(user_hash['sex'].to_s).to match(/\d*/)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should get user info of 南' do
|
26
|
+
user_list_hash = WxExt::Api::User.user_list(@access_token)
|
27
|
+
user_list_hash['data']['openid'].each do |openid|
|
28
|
+
user_hash = WxExt::Api::User.get_user_base_info(@access_token, openid)
|
29
|
+
if user_hash['nickname'] == '南'
|
30
|
+
puts '-' * 20
|
31
|
+
# oK_Xnt2a9LAh0cbYuBGFSPxnvu1w
|
32
|
+
puts user_hash
|
33
|
+
end
|
34
|
+
end
|
35
|
+
expect(user_list_hash['total'].to_s).to match(/\d*/)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should remark nickname of 南' do
|
39
|
+
remark_hash = WxExt::Api::User.change_remark(@access_token, 'oK_Xnt2a9LAh0cbYuBGFSPxnvu1w', 'good boy')
|
40
|
+
expect(remark_hash['errcode']).to eql(0)
|
41
|
+
end
|
15
42
|
end
|