Class: MpWeixin::Interface::Group
- Defined in:
- lib/mp_weixin/interface/group.rb
Overview
分组管理
开发者可以使用接口,对公众平台的分组进行查询、创建、修改操作,也可以使用接口在需要时移动用户到某个分组。
Instance Method Summary collapse
-
#create(arg = nil) ⇒ Object
创建分组:.
-
#get_groups(opts = {}) ⇒ Object
查询所有分组.
-
#getid(opts = {}) ⇒ Object
查询用户所在分组.
-
#update(opts = {}) ⇒ Object
修改分组名.
-
#update_memgers(opts = {}) ⇒ Object
移动用户分组.
Methods inherited from Base
#default_request_params, #get, #initialize, #post, #request
Constructor Details
This class inherits a constructor from MpWeixin::Interface::Base
Instance Method Details
#create(arg = nil) ⇒ Object
创建分组:
一个公众账号,最多支持创建500个分组。 接口调用请求说明
http请求方式: POST(请使用https协议)
https://api.weixin.qq.com/cgi-bin/groups/create?access_token=ACCESS_TOKEN
POST数据格式:json
POST数据例子:{"group":{"name":"test"}}
20 21 22 23 24 25 26 27 28 |
# 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 = {}) ⇒ Object
查询所有分组
http请求方式: GET(请使用https协议)
https://api.weixin.qq.com/cgi-bin/groups/get?access_token=ACCESS_TOKEN
36 37 38 |
# 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 = {}) ⇒ Object
查询用户所在分组
通过用户的OpenID查询其所在的GroupID。 接口调用请求说明
http请求方式: POST(请使用https协议)
https://api.weixin.qq.com/cgi-bin/groups/getid?access_token=ACCESS_TOKEN
POST数据格式:json
POST数据例子:{"openid":"od8XIjsmk6QdVTETa9jLtGWA6KBc"}
50 51 52 53 54 55 |
# 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 = {}) ⇒ Object
修改分组名
接口调用请求说明
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"}}
67 68 69 70 71 72 |
# 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 = {}) ⇒ Object
移动用户分组
接口调用请求说明
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}
84 85 86 87 88 89 |
# 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 |