Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
weixin_authorize
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
weixin_authorize
Commits
d2df2d80
Commit
d2df2d80
authored
Mar 19, 2014
by
lanrion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor groups.rb
parent
27e67364
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
11 deletions
+40
-11
lib/weixin_authorize/api/groups.rb
+4
-8
spec/api/groups_spec.rb
+36
-3
No files found.
lib/weixin_authorize/api/groups.rb
View file @
d2df2d80
...
...
@@ -7,8 +7,7 @@ module WeixinAuthorize
# https://api.weixin.qq.com/cgi-bin/groups/create?access_token=ACCESS_TOKEN
def
create_group
(
group_name
)
create_url
=
"
#{
group_base_url
}
/create"
group
=
MultiJson
.
dump
({
group:
{
name:
group_name
}})
http_post
(
create_url
,
group
)
http_post
(
create_url
,
{
group:
{
name:
group_name
}})
end
# 查询所有分组
...
...
@@ -22,24 +21,21 @@ module WeixinAuthorize
# https://api.weixin.qq.com/cgi-bin/groups/getid?access_token=ACCESS_TOKEN
def
get_group_for
(
openid
)
group_url
=
"
#{
group_base_url
}
/getid"
openid
=
MultiJson
.
dump
({
openid:
openid
})
http_post
(
group_url
,
openid
)
http_post
(
group_url
,
{
openid:
openid
})
end
# 修改分组名
# https://api.weixin.qq.com/cgi-bin/groups/update?access_token=ACCESS_TOKEN
def
update_group_name
(
group_id
,
new_group_name
)
group_url
=
"
#{
group_base_url
}
/update"
group
=
MultiJson
.
dump
({
group:
{
id:
openid
,
name:
new_group_name
}})
http_post
(
group_url
,
group
)
http_post
(
group_url
,
{
group:
{
id:
group_id
,
name:
new_group_name
}})
end
# 移动用户分组
# https://api.weixin.qq.com/cgi-bin/groups/members/update?access_token=ACCESS_TOKEN
def
update_group_for_openid
(
openid
,
to_groupid
)
group_url
=
"
#{
group_base_url
}
/members/update"
group
=
MultiJson
.
dump
({
openid:
openid
,
to_groupid:
to_groupid
})
http_post
(
group_url
,
group
)
http_post
(
group_url
,
{
openid:
openid
,
to_groupid:
to_groupid
})
end
private
...
...
spec/api/groups_spec.rb
View file @
d2df2d80
require
"spec_helper"
describe
WeixinAuthorize
::
Api
::
Groups
do
let
(
:group_name
)
do
"test group_name"
end
let
(
:group_name_2
)
do
"test group_name_2"
end
it
"create a group"
do
response
=
$client
.
create_group
(
"test"
)
puts
response
response
=
$client
.
create_group
(
group_name
)
expect
(
response
[
"group"
][
"name"
]).
to
eq
(
group_name
)
end
it
"get groups"
do
groups
=
$client
.
groups
puts
groups
expect
(
groups
[
"groups"
][
-
1
][
"name"
]).
to
eq
(
group_name
)
end
it
"#get_group_for ENV['OPENID']"
do
group
=
$client
.
get_group_for
(
ENV
[
"OPENID"
])
expect
(
group
.
keys
).
to
eq
([
"groupid"
])
end
it
"#update_group_name"
do
response
=
$client
.
create_group
(
group_name
)
expect
(
response
[
"group"
][
"name"
]).
to
eq
(
group_name
)
response
=
$client
.
update_group_name
(
response
[
"group"
][
"id"
],
group_name_2
)
expect
(
response
[
"errcode"
]).
to
eq
(
0
)
groups
=
$client
.
groups
expect
(
groups
[
"groups"
][
-
1
][
"name"
]).
to
eq
(
group_name_2
)
end
it
"#update_group_for_openid"
do
groups
=
$client
.
groups
last_group_id
=
groups
[
"groups"
][
-
1
][
"id"
]
$client
.
update_group_for_openid
(
ENV
[
"OPENID"
],
last_group_id
)
group
=
$client
.
get_group_for
(
ENV
[
"OPENID"
])
expect
(
group
[
"groupid"
]).
to
eq
(
last_group_id
)
$client
.
update_group_for_openid
(
ENV
[
"OPENID"
],
0
)
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment