Commit 1692ed38 by lanrion

added groups apis

parent 307bdf68
......@@ -3,6 +3,7 @@ require "weixin_authorize/version"
require "weixin_authorize/api/user"
require "weixin_authorize/api/menu"
require "weixin_authorize/api/custom"
require "weixin_authorize/api/groups"
require "weixin_authorize/client"
module WeixinAuthorize
......
# encoding: utf-8
module WeixinAuthorize
module Api
module Groups
# 创建分组
# https://api.weixin.qq.com/cgi-bin/groups/create?access_token=ACCESS_TOKEN
def create_group(group_name)
create_url = "#{group_base_url}/create?#{access_token_param}"
group = MultiJson.dump({group: {name: group_name}})
JSON.parse(RestClient.post(create_url, group))
end
# 查询所有分组
# https://api.weixin.qq.com/cgi-bin/groups/get?access_token=ACCESS_TOKEN
def groups
groups_url = "#{group_base_url}/get?#{access_token_param}"
JSON.parse(RestClient.get(groups_url))
end
# 查询用户所在分组
# https://api.weixin.qq.com/cgi-bin/groups/getid?access_token=ACCESS_TOKEN
def get_group_for(openid)
group_url = "#{group_base_url}/getid?#{access_token_param}"
openid = MultiJson.dump({openid: openid})
JSON.parse(RestClient.post(group_url, 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?#{access_token_param}"
group = MultiJson.dump({group: {id: openid, name: new_group_name}})
JSON.parse(RestClient.post(group_url, group))
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?#{access_token_param}"
group = MultiJson.dump({openid: openid, to_groupid: to_groupid})
JSON.parse(RestClient.post(group_url, group))
end
private
def group_base_url
"#{endpoint}/groups"
end
end
end
end
......@@ -7,6 +7,7 @@ module WeixinAuthorize
include Api::User
include Api::Menu
include Api::Custom
include Api::Groups
attr_accessor :access_token
......
require "spec_helper"
describe WeixinAuthorize::Api::Groups do
it "create a group" do
response = $client.create_group("test")
response
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment