wx_ext 0.1.6 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -7
- data/lib/wx_ext/api/base.rb +142 -142
- data/lib/wx_ext/api/customer_service.rb +18 -18
- data/lib/wx_ext/api/js.rb +49 -46
- data/lib/wx_ext/api/mass.rb +62 -62
- data/lib/wx_ext/api/menu.rb +30 -31
- data/lib/wx_ext/api/msg.rb +32 -33
- data/lib/wx_ext/api/qrcode.rb +8 -8
- data/lib/wx_ext/api/semantic.rb +11 -12
- data/lib/wx_ext/api/template_msg.rb +32 -33
- data/lib/wx_ext/api/user/group.rb +52 -52
- data/lib/wx_ext/api/user.rb +78 -79
- data/lib/wx_ext/helper.rb +20 -20
- data/lib/wx_ext/version.rb +1 -1
- data/lib/wx_ext.rb +4 -5
- metadata +2 -2
data/lib/wx_ext/api/menu.rb
CHANGED
@@ -10,40 +10,39 @@ module WxExt
|
|
10
10
|
# User api of weixin.
|
11
11
|
#
|
12
12
|
# @author FuShengYang
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
Helper.http_post(url, menu_hash.to_json)
|
25
|
-
end
|
13
|
+
module Menu
|
14
|
+
# Create menu via post.
|
15
|
+
#
|
16
|
+
# @param [Enumerable<String>] access_token
|
17
|
+
# @param [Hash] menu_hash
|
18
|
+
# @return [Hash] Json based hash.
|
19
|
+
def create_menu(access_token, menu_hash)
|
20
|
+
url = 'https://api.weixin.qq.com/cgi-bin/menu/create'\
|
21
|
+
"?access_token=#{access_token}"
|
22
|
+
Helper.http_post(url, menu_hash.to_json)
|
23
|
+
end
|
26
24
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
25
|
+
# Get menus via get.
|
26
|
+
#
|
27
|
+
# @param [Enumerable<String>] access_token
|
28
|
+
# @return [Hash] Json based hash.
|
29
|
+
def menus(access_token)
|
30
|
+
url = 'https://api.weixin.qq.com/cgi-bin/menu/get'\
|
31
|
+
"?access_token=#{access_token}"
|
32
|
+
Helper.http_get(url, { accept: :json })
|
33
|
+
end
|
36
34
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
end
|
35
|
+
# Del menu via get.
|
36
|
+
#
|
37
|
+
# @param [Enumerable<String>] access_token
|
38
|
+
# @return [Hash] Json based hash.
|
39
|
+
def del_menu(access_token)
|
40
|
+
url = 'https://api.weixin.qq.com/cgi-bin/menu/delete'\
|
41
|
+
"?access_token=#{access_token}"
|
42
|
+
Helper.http_get(url, { accept: :json })
|
46
43
|
end
|
44
|
+
|
45
|
+
extend self
|
47
46
|
end
|
48
47
|
end
|
49
48
|
end
|
data/lib/wx_ext/api/msg.rb
CHANGED
@@ -10,42 +10,41 @@ module WxExt
|
|
10
10
|
# User api of weixin.
|
11
11
|
#
|
12
12
|
# @author FuShengYang
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
Helper.http_post(url, ticket_hash.to_json)
|
25
|
-
end
|
13
|
+
module Qrcode
|
14
|
+
# Create ticket via post.
|
15
|
+
#
|
16
|
+
# @param [Enumerable<String>] access_token
|
17
|
+
# @param [Hash] ticket_hash
|
18
|
+
# @return [Hash] Json based hash.
|
19
|
+
def create_ticket(access_token, ticket_hash)
|
20
|
+
url = 'https://api.weixin.qq.com/cgi-bin/qrcode/create'\
|
21
|
+
"?access_token=#{access_token}"
|
22
|
+
Helper.http_post(url, ticket_hash.to_json)
|
23
|
+
end
|
26
24
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
25
|
+
# Get the qrcode via ticket.
|
26
|
+
#
|
27
|
+
# @param [Enumerable<String>] ticket
|
28
|
+
# @return [Hash] Json based hash.
|
29
|
+
def get_qrcode_by_ticket(ticket)
|
30
|
+
url = 'https://mp.weixin.qq.com/cgi-bin/showqrcode'\
|
31
|
+
"?ticket=#{ticket}"
|
32
|
+
Helper.http_get url
|
33
|
+
end
|
36
34
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
end
|
35
|
+
# Long url to short url via post.
|
36
|
+
#
|
37
|
+
# @param [Enumerable<String>] access_token
|
38
|
+
# @param [Enumerable<String>] action
|
39
|
+
# @param [Enumerable<String>] long_url
|
40
|
+
# @return [Hash] Json based hash.
|
41
|
+
def long_url_2_short(access_token, action='long2short', long_url)
|
42
|
+
url = 'https://api.weixin.qq.com/cgi-bin/shorturl'\
|
43
|
+
"?access_token=#{access_token}"
|
44
|
+
Helper.http_post(url, { action: action, long_url: long_url }.to_json)
|
48
45
|
end
|
46
|
+
|
47
|
+
extend self
|
49
48
|
end
|
50
49
|
end
|
51
50
|
end
|
data/lib/wx_ext/api/qrcode.rb
CHANGED
@@ -11,15 +11,15 @@ module WxExt
|
|
11
11
|
#
|
12
12
|
# @author FuShengYang
|
13
13
|
module Msg
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
signature == Digest::SHA1.hexdigest(array.join) ? true : false
|
21
|
-
end
|
14
|
+
# Check the signature before send msg.
|
15
|
+
#
|
16
|
+
# @return [Boolean] Check the signature true or false.
|
17
|
+
def check_signature(signature, timestamp, nonce, token)
|
18
|
+
array = [token, timestamp, nonce].sort
|
19
|
+
signature == Digest::SHA1.hexdigest(array.join) ? true : false
|
22
20
|
end
|
21
|
+
|
22
|
+
extend self
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
data/lib/wx_ext/api/semantic.rb
CHANGED
@@ -11,19 +11,18 @@ module WxExt
|
|
11
11
|
#
|
12
12
|
# @author FuShengYang
|
13
13
|
module Semantic
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
"?access_token=#{access_token}"
|
24
|
-
Helper.http_post(url, semantic_hash.to_json)
|
25
|
-
end
|
14
|
+
# Create semantic search via post.
|
15
|
+
#
|
16
|
+
# @param [Enumerable<String>] access_token
|
17
|
+
# @param [Hash] semantic_hash
|
18
|
+
# @return [Hash] Json based hash.
|
19
|
+
def semantic_search(access_token, semantic_hash)
|
20
|
+
url = 'https://api.weixin.qq.com/semantic/semproxy/search'\
|
21
|
+
"?access_token=#{access_token}"
|
22
|
+
Helper.http_post(url, semantic_hash.to_json)
|
26
23
|
end
|
24
|
+
|
25
|
+
extend self
|
27
26
|
end
|
28
27
|
end
|
29
28
|
end
|
@@ -11,42 +11,41 @@ module WxExt
|
|
11
11
|
#
|
12
12
|
# @author FuShengYang
|
13
13
|
module TemplateMsg
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
Helper.http_post(url, { industry_id1: industry_id1, industry_id2: industry_id2 }.to_json)
|
26
|
-
end
|
14
|
+
# Set the industry via post.
|
15
|
+
#
|
16
|
+
# @param [Enumerable<String>] access_token
|
17
|
+
# @param [Enumerable<String>] industry_id1
|
18
|
+
# @param [Enumerable<String>] industry_id2
|
19
|
+
# @return [Hash] Json based hash.
|
20
|
+
def set_industry(access_token, industry_id1, industry_id2)
|
21
|
+
url = 'https://api.weixin.qq.com/cgi-bin/template/api_set_industry'\
|
22
|
+
"?access_token=#{access_token}"
|
23
|
+
Helper.http_post(url, { industry_id1: industry_id1, industry_id2: industry_id2 }.to_json)
|
24
|
+
end
|
27
25
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
26
|
+
# Get the template ID via post.
|
27
|
+
#
|
28
|
+
# @param [Enumerable<String>] access_token
|
29
|
+
# @param [Enumerable<String>] template_id_short
|
30
|
+
# @return [Hash] Json based hash.
|
31
|
+
def get_template_id(access_token, template_id_short)
|
32
|
+
url = 'https://api.weixin.qq.com/cgi-bin/template/api_add_template'\
|
33
|
+
"?access_token=#{access_token}"
|
34
|
+
Helper.http_post(url, { template_id_short: template_id_short })
|
35
|
+
end
|
38
36
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
37
|
+
# Send the template msg via post.
|
38
|
+
#
|
39
|
+
# @param [Enumerable<String>] access_token
|
40
|
+
# @param [Hash] template_msg_hash
|
41
|
+
# @return [Hash] Json based hash.
|
42
|
+
def send_template_msg(access_token, template_msg_hash)
|
43
|
+
url = 'https://api.weixin.qq.com/cgi-bin/message/template/send'\
|
44
|
+
"?access_token=#{access_token}"
|
45
|
+
Helper.http_post(url, template_msg_hash.to_json)
|
49
46
|
end
|
47
|
+
|
48
|
+
extend self
|
50
49
|
end
|
51
50
|
end
|
52
51
|
end
|
@@ -15,63 +15,63 @@ module WxExt
|
|
15
15
|
#
|
16
16
|
# @author FuShengYang
|
17
17
|
module Group
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
18
|
+
# Create user group via post.
|
19
|
+
#
|
20
|
+
# @param [Enumerable<String>] access_token
|
21
|
+
# @param [Enumerable<String>] group_name
|
22
|
+
# @return [Hash] A json parse hash.
|
23
|
+
def create_group(access_token, group_name)
|
24
|
+
url = 'https://api.weixin.qq.com/cgi-bin/groups/create'\
|
25
|
+
"?access_token=#{access_token}"
|
26
|
+
Helper.http_post(url, { group: { name: group_name } }.to_json)
|
27
|
+
end
|
29
28
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
29
|
+
# Get all groups via get.
|
30
|
+
#
|
31
|
+
# @param [Enumerable<String>] access_token
|
32
|
+
# @return [Hash] A json parse hash.
|
33
|
+
def groups(access_token)
|
34
|
+
url = 'https://api.weixin.qq.com/cgi-bin/groups/get'\
|
35
|
+
"?access_token=#{access_token}"
|
36
|
+
Helper.http_get(url, { accept: :json }.to_json)
|
37
|
+
end
|
39
38
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
39
|
+
# Get user of group via post.
|
40
|
+
#
|
41
|
+
# @param [Enumerable<String>] access_token
|
42
|
+
# @param [Enumerable<String>] openid
|
43
|
+
# @return [Hash] A json parse hash.
|
44
|
+
def user_of_group(access_token, openid)
|
45
|
+
url = 'https://api.weixin.qq.com/cgi-bin/groups/getid'\
|
46
|
+
"?access_token=#{access_token}"
|
47
|
+
Helper.http_post(url, { openid: openid }.to_json)
|
48
|
+
end
|
50
49
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
50
|
+
# Update user group name via post.
|
51
|
+
#
|
52
|
+
# @param [Enumerable<String>] access_token
|
53
|
+
# @param [Enumerable<String>] id
|
54
|
+
# @param [Enumerable<String>] name
|
55
|
+
# @return [Hash] A json parse hash.
|
56
|
+
def update_group_name(access_token, id, name)
|
57
|
+
url = 'https://api.weixin.qq.com/cgi-bin/groups/update'\
|
58
|
+
"?access_token=#{access_token}"
|
59
|
+
Helper.http_post(url, { group: { id: id, name: name } }.to_json)
|
60
|
+
end
|
62
61
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
end
|
62
|
+
# Move user group via post.
|
63
|
+
#
|
64
|
+
# @param [Enumerable<String>] access_token
|
65
|
+
# @param [Enumerable<String>] openid
|
66
|
+
# @param [Enumerable<String>] to_groupid
|
67
|
+
# @return [Hash] A json parse hash.
|
68
|
+
def mv_user_group(access_token, openid, to_groupid)
|
69
|
+
url = 'https://api.weixin.qq.com/cgi-bin/groups/members/update'\
|
70
|
+
"?access_token=#{access_token}"
|
71
|
+
Helper.http_post(url, { openid: openid, to_groupid: to_groupid }.to_json)
|
74
72
|
end
|
73
|
+
|
74
|
+
extend self
|
75
75
|
end
|
76
76
|
end
|
77
77
|
end
|
data/lib/wx_ext/api/user.rb
CHANGED
@@ -11,92 +11,91 @@ module WxExt
|
|
11
11
|
#
|
12
12
|
# @author FuShengYang
|
13
13
|
module User
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
Helper.http_post(url, { openid: openid, remark: remark }.to_json)
|
26
|
-
end
|
14
|
+
# Change the remark of user via post.
|
15
|
+
#
|
16
|
+
# @param [Enumerable<String>] access_token
|
17
|
+
# @param [Enumerable<String>] openid
|
18
|
+
# @param [Enumerable<String>] remark
|
19
|
+
# @return [Hash] Json based hash.
|
20
|
+
def change_remark(access_token, openid, remark)
|
21
|
+
url = 'https://api.weixin.qq.com/cgi-bin/user/info/updateremark'\
|
22
|
+
"?access_token=#{access_token}"
|
23
|
+
Helper.http_post(url, { openid: openid, remark: remark }.to_json)
|
24
|
+
end
|
27
25
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
26
|
+
# Get the user base info.
|
27
|
+
#
|
28
|
+
# @param [Enumerable<String>] access_token
|
29
|
+
# @param [Enumerable<String>] openid
|
30
|
+
# @param [Enumerable<String>] lang
|
31
|
+
# @return [Hash] Json based hash.
|
32
|
+
def get_user_base_info(access_token, openid, lang='zh_CN')
|
33
|
+
url = 'https://api.weixin.qq.com/cgi-bin/user/info'\
|
34
|
+
"?access_token=#{access_token}&openid=#{openid}&lang=#{lang}"
|
35
|
+
Helper.http_get(url, { accept: :json })
|
36
|
+
end
|
39
37
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
38
|
+
# Get user list of weixin.
|
39
|
+
#
|
40
|
+
# @param [Enumerable<String>] access_token
|
41
|
+
# @param [Enumerable<String>] next_openid
|
42
|
+
# @return [Hash] Json based hash.
|
43
|
+
def user_list(access_token, next_openid=nil)
|
44
|
+
url = 'https://api.weixin.qq.com/cgi-bin/user/get'\
|
45
|
+
"?access_token=#{access_token}"
|
46
|
+
url += "&next_openid=#{next_openid}" if next_openid
|
47
|
+
Helper.http_get(url, { accept: :json })
|
48
|
+
end
|
51
49
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
50
|
+
# Get oauth2 token with code.
|
51
|
+
#
|
52
|
+
# @param [Enumerable<String>] app_id
|
53
|
+
# @param [Enumerable<String>] app_secret
|
54
|
+
# @param [Enumerable<String>] code
|
55
|
+
# @param [Enumerable<String>] grant_type
|
56
|
+
# @return [Hash] Json based hash.
|
57
|
+
def get_oauth2_token_with_code(app_id, app_secret, code, grant_type='authorization_code')
|
58
|
+
url = 'https://api.weixin.qq.com/sns/oauth2/access_token'\
|
59
|
+
"?appid=#{app_id}&secret=#{app_secret}&code=CODE&grant_type=#{grant_type}"
|
60
|
+
Helper.http_get(url, { accept: :json })
|
61
|
+
end
|
64
62
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
63
|
+
# Refresh oauth2 token.
|
64
|
+
#
|
65
|
+
# @param [Enumerable<String>] app_id
|
66
|
+
# @param [Enumerable<String>] refresh_token
|
67
|
+
# @param [Enumerable<String>] grant_type
|
68
|
+
# @return [Hash] Json based hash.
|
69
|
+
def refresh_oauth2_token(app_id, refresh_token, grant_type='refresh_token')
|
70
|
+
url = 'https://api.weixin.qq.com/sns/oauth2/refresh_token'\
|
71
|
+
"?appid=#{app_id}&grant_type=#{grant_type}&refresh_token=#{refresh_token}"
|
72
|
+
Helper.http_get(url, { accept: :json })
|
73
|
+
end
|
76
74
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
75
|
+
# Get user info with snsapi_userinfo.
|
76
|
+
#
|
77
|
+
# @param [Enumerable<String>] oauth2_token
|
78
|
+
# @param [Enumerable<String>] openid
|
79
|
+
# @param [Enumerable<String>] lang
|
80
|
+
# @return [Hash] Json based hash.
|
81
|
+
def get_user_info_with_snsapi_userinfo(oauth2_token, openid, lang)
|
82
|
+
url = 'https://api.weixin.qq.com/sns/userinfo'\
|
83
|
+
"?access_token=#{oauth2_token}&#{openid}=OPENID&lang=#{lang}"
|
84
|
+
Helper.http_get(url, { accept: :json })
|
85
|
+
end
|
88
86
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
end
|
87
|
+
# Check the oauth2_token.
|
88
|
+
#
|
89
|
+
# @param [Enumerable<String>] openid
|
90
|
+
# @param [Enumerable<String>] oauth2_token
|
91
|
+
# @return [Hash] Json based hash.
|
92
|
+
def check_oauth2_token(openid, oauth2_token)
|
93
|
+
url = 'https://api.weixin.qq.com/sns/auth'\
|
94
|
+
"?access_token=#{oauth2_token}&openid=#{openid}"
|
95
|
+
Helper.http_get(url, { accept: :json })
|
99
96
|
end
|
97
|
+
|
98
|
+
extend self
|
100
99
|
end
|
101
100
|
end
|
102
101
|
end
|
data/lib/wx_ext/helper.rb
CHANGED
@@ -8,27 +8,27 @@ module WxExt
|
|
8
8
|
#
|
9
9
|
# @author FuShengYang
|
10
10
|
module Helper
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
11
|
+
# Http get helper of this gem, always return a hash.
|
12
|
+
#
|
13
|
+
# @param [Enumerable<String>] url
|
14
|
+
# @param [Hash] headers
|
15
|
+
# @return [Hash] A json parse hash.
|
16
|
+
def http_get(url, headers = {})
|
17
|
+
res = RestClient.get url, headers
|
18
|
+
JSON.parse res
|
19
|
+
end
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
21
|
+
# Http post helper of this gem, always return a hash.
|
22
|
+
#
|
23
|
+
# @param [Enumerable<String>] url
|
24
|
+
# @param [Hash] params
|
25
|
+
# @param [Hash] headers
|
26
|
+
# @return [Hash] A json parse hash.
|
27
|
+
def http_post(url, params, headers = {})
|
28
|
+
res = RestClient.post url, params, headers
|
29
|
+
JSON.parse res
|
32
30
|
end
|
31
|
+
|
32
|
+
extend self
|
33
33
|
end
|
34
34
|
end
|
data/lib/wx_ext/version.rb
CHANGED