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
5bd539ea
Commit
5bd539ea
authored
Mar 16, 2014
by
lanrion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor groups.rb with "http_get" and "http_post" method
parent
3539338f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
12 deletions
+19
-12
lib/weixin_authorize/api/groups.rb
+13
-11
spec/api/groups_spec.rb
+6
-1
No files found.
lib/weixin_authorize/api/groups.rb
View file @
5bd539ea
...
@@ -6,46 +6,48 @@ module WeixinAuthorize
...
@@ -6,46 +6,48 @@ module WeixinAuthorize
# 创建分组
# 创建分组
# https://api.weixin.qq.com/cgi-bin/groups/create?access_token=ACCESS_TOKEN
# https://api.weixin.qq.com/cgi-bin/groups/create?access_token=ACCESS_TOKEN
def
create_group
(
group_name
)
def
create_group
(
group_name
)
create_url
=
"
#{
group_base_url
}
/create
?
#{
access_token_param
}
"
create_url
=
"
#{
group_base_url
}
/create"
group
=
MultiJson
.
dump
({
group:
{
name:
group_name
}})
group
=
MultiJson
.
dump
({
group:
{
name:
group_name
}})
JSON
.
parse
(
RestClient
.
post
(
create_url
,
group
))
http_post
(
create_url
,
group
)
end
end
# 查询所有分组
# 查询所有分组
# https://api.weixin.qq.com/cgi-bin/groups/get?access_token=ACCESS_TOKEN
# https://api.weixin.qq.com/cgi-bin/groups/get?access_token=ACCESS_TOKEN
def
groups
def
groups
groups_url
=
"
#{
group_base_url
}
/get
?
#{
access_token_param
}
"
groups_url
=
"
#{
group_base_url
}
/get"
JSON
.
parse
(
RestClient
.
get
(
groups_url
)
)
http_get
(
groups_url
)
end
end
# 查询用户所在分组
# 查询用户所在分组
# https://api.weixin.qq.com/cgi-bin/groups/getid?access_token=ACCESS_TOKEN
# https://api.weixin.qq.com/cgi-bin/groups/getid?access_token=ACCESS_TOKEN
def
get_group_for
(
openid
)
def
get_group_for
(
openid
)
group_url
=
"
#{
group_base_url
}
/getid
?
#{
access_token_param
}
"
group_url
=
"
#{
group_base_url
}
/getid"
openid
=
MultiJson
.
dump
({
openid:
openid
})
openid
=
MultiJson
.
dump
({
openid:
openid
})
JSON
.
parse
(
RestClient
.
post
(
group_url
,
openid
))
http_post
(
group_url
,
openid
)
end
end
# 修改分组名
# 修改分组名
# https://api.weixin.qq.com/cgi-bin/groups/update?access_token=ACCESS_TOKEN
# https://api.weixin.qq.com/cgi-bin/groups/update?access_token=ACCESS_TOKEN
def
update_group_name
(
group_id
,
new_group_name
)
def
update_group_name
(
group_id
,
new_group_name
)
group_url
=
"
#{
group_base_url
}
/update
?
#{
access_token_param
}
"
group_url
=
"
#{
group_base_url
}
/update"
group
=
MultiJson
.
dump
({
group:
{
id:
openid
,
name:
new_group_name
}})
group
=
MultiJson
.
dump
({
group:
{
id:
openid
,
name:
new_group_name
}})
JSON
.
parse
(
RestClient
.
post
(
group_url
,
group
)
)
http_post
(
group_url
,
group
)
end
end
# 移动用户分组
# 移动用户分组
# https://api.weixin.qq.com/cgi-bin/groups/members/update?access_token=ACCESS_TOKEN
# https://api.weixin.qq.com/cgi-bin/groups/members/update?access_token=ACCESS_TOKEN
def
update_group_for_openid
(
openid
,
to_groupid
)
def
update_group_for_openid
(
openid
,
to_groupid
)
group_url
=
"
#{
group_base_url
}
/members/update
?
#{
access_token_param
}
"
group_url
=
"
#{
group_base_url
}
/members/update"
group
=
MultiJson
.
dump
({
openid:
openid
,
to_groupid:
to_groupid
})
group
=
MultiJson
.
dump
({
openid:
openid
,
to_groupid:
to_groupid
})
JSON
.
parse
(
RestClient
.
post
(
group_url
,
group
)
)
http_post
(
group_url
,
group
)
end
end
private
private
def
group_base_url
def
group_base_url
"
#{
endpoint
}
/groups"
"/groups"
end
end
end
end
...
...
spec/api/groups_spec.rb
View file @
5bd539ea
...
@@ -2,6 +2,11 @@ require "spec_helper"
...
@@ -2,6 +2,11 @@ require "spec_helper"
describe
WeixinAuthorize
::
Api
::
Groups
do
describe
WeixinAuthorize
::
Api
::
Groups
do
it
"create a group"
do
it
"create a group"
do
response
=
$client
.
create_group
(
"test"
)
response
=
$client
.
create_group
(
"test"
)
response
puts
response
end
it
"get groups"
do
groups
=
$client
.
groups
puts
groups
end
end
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