class MpWeixin::Interface::Group
分组管理
开发者可以使用接口,对公众平台的分组进行查询、创建、修改操作,也可以使用接口在需要时移动用户到某个分组。
Public Instance Methods
create(arg = nil)
click to toggle source
创建分组:
一个公众账号,最多支持创建500个分组。 接口调用请求说明
http请求方式: POST(请使用https协议) https://api.weixin.qq.com/cgi-bin/groups/create?access_token=ACCESS_TOKEN POST数据格式:json POST数据例子:{"group":{"name":"test"}}
# File lib/mp_weixin/interface/group.rb, line 20 def create(arg = nil) if arg.present? opts = arg.is_a?(Hash) ? arg : {group: {name: arg}} # JSON.generate(user_message.protocol_params, :ascii_only => true) opts_json = JSON.generate(opts, :ascii_only => false) post '/cgi-bin/groups/create', :body => opts_json, :params => default_request_params end end
get_groups(opts = {})
click to toggle source
查询所有分组
http请求方式: GET(请使用https协议) https://api.weixin.qq.com/cgi-bin/groups/get?access_token=ACCESS_TOKEN
# File lib/mp_weixin/interface/group.rb, line 36 def get_groups(opts = {}) get '/cgi-bin/groups/get', :params => opts.merge(default_request_params) end
getid(opts = {})
click to toggle source
查询用户所在分组
通过用户的OpenID查询其所在的GroupID。 接口调用请求说明
http请求方式: POST(请使用https协议) https://api.weixin.qq.com/cgi-bin/groups/getid?access_token=ACCESS_TOKEN POST数据格式:json POST数据例子:{"openid":"od8XIjsmk6QdVTETa9jLtGWA6KBc"}
# File lib/mp_weixin/interface/group.rb, line 50 def getid(opts = {}) # JSON.generate(user_message.protocol_params, :ascii_only => true) opts_json = JSON.generate(opts, :ascii_only => false) if opts.is_a?(Hash) post '/cgi-bin/groups/getid', :body => opts_json, :params => default_request_params end
update(opts = {})
click to toggle source
修改分组名
接口调用请求说明
http请求方式: POST(请使用https协议) https://api.weixin.qq.com/cgi-bin/groups/update?access_token=ACCESS_TOKEN POST数据格式:json POST数据例子:{"group":{"id":108,"name":"test2_modify2"}}
# File lib/mp_weixin/interface/group.rb, line 67 def update(opts = {}) # JSON.generate(user_message.protocol_params, :ascii_only => true) opts_json = JSON.generate(opts, :ascii_only => false) if opts.is_a?(Hash) post '/cgi-bin/groups/update', :body => opts_json, :params => default_request_params end
update_memgers(opts = {})
click to toggle source
移动用户分组
接口调用请求说明
http请求方式: POST(请使用https协议) https://api.weixin.qq.com/cgi-bin/groups/members/update?access_token=ACCESS_TOKEN POST数据格式:json POST数据例子:{"openid":"oDF3iYx0ro3_7jD4HFRDfrjdCM58","to_groupid":108}
# File lib/mp_weixin/interface/group.rb, line 84 def update_memgers(opts = {}) # JSON.generate(user_message.protocol_params, :ascii_only => true) opts_json = JSON.generate(opts, :ascii_only => false) if opts.is_a?(Hash) post '/cgi-bin/groups/members/update', :body => opts_json, :params => default_request_params end