Module: Wxapi::Tag

Included in:
Wxapi
Defined in:
lib/wxapi/tag.rb

Instance Method Summary collapse

Instance Method Details

#delete_tag(id) ⇒ Object

删除标签一个标签下的粉丝列表不会自动删除删除标签后,所有该标签下的粉丝会取消标签的标记。



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/wxapi/tag.rb', line 53

def delete_tag(id)
  body = {
    tag:{
      id: id
    }
  }.to_json
  access_token = get_access_token
  response = RestClient.post("#{prefix}/cgi-bin/tags/delete?access_token=#{access_token}", body)
  JSON.parse(response)

end

#new_tag(name = "") ⇒ Object

  1. 创建标签

一个公众号,最多可以创建100个标签。



7
8
9
10
11
12
13
14
15
16
# File 'lib/wxapi/tag.rb', line 7

def new_tag(name="")
  body = {
    tag:{
      name: name
    }
  }.to_json
  access_token = get_access_token
  response = RestClient.post("#{prefix}/cgi-bin/tags/create?access_token=#{access_token}", body)
  JSON.parse(response)
end

#tag_users(tagid, openid_list) ⇒ Object

批量为用户打标签



68
69
70
71
72
73
74
75
# File 'lib/wxapi/tag.rb', line 68

def tag_users(tagid,openid_list)
  body = {
    openid_list: openid_list
  }.to_json
  access_token = get_access_token
  response = RestClient.post("#{prefix}/cgi-bin/tags/members/batchtagging?access_token=#{access_token}", body)
  JSON.parse(response)
end

#tagsObject

获取公众号已创建的标签返回说明

{ “tags”:[

"id":1,
"name":"每天一罐可乐星人",
"count":0 //此标签下粉丝数

,

"id":2,
"name":"星标组",
"count":0

]}



32
33
34
35
36
# File 'lib/wxapi/tag.rb', line 32

def tags
  access_token = get_access_token
  response = RestClient.get("#{prefix}/cgi-bin/tags/get?access_token=#{access_token}")
  JSON.parse(response)
end

#tags_of_user(open_id) ⇒ Object

获取用户身上的标签列表



105
106
107
108
109
110
111
112
# File 'lib/wxapi/tag.rb', line 105

def tags_of_user(open_id)
  body = {
    openid: open_id
  }.to_json
  access_token = get_access_token
  response = RestClient.post("#{prefix}/cgi-bin/tags/getidlist?access_token=#{access_token}", body)
  JSON.parse(response)
end

#untag_users(tagid, openid_list = []) ⇒ Object

批量为用户取消标签



90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/wxapi/tag.rb', line 90

def untag_users(tagid,openid_list=[])
  raise "openid_list is empty" if openid_list.empty?
  raise 'tagid is empty' if tagid == 0
  raise 'size of openid_list is more than 50' if openid_list.size > 50

  body = {
    openid_list: openid_list
  }.to_json
  access_token = get_access_token
  response = RestClient.post("#{prefix}/cgi-bin/tags/members/batchuntagging?access_token=#{access_token}", body)
  JSON.parse(response)
end

#update_tag(id = 0, name = "") ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/wxapi/tag.rb', line 38

def update_tag(id=0,name="")
  body = {
    tag:{
      id: id,
      name: name
    }
  }.to_json
  access_token = get_access_token
  response = RestClient.post("#{prefix}/cgi-bin/tags/update?access_token=#{access_token}", body)
  JSON.parse(response)
end

#users_of_tags(tagid, next_openid = "") ⇒ Object

获取标签下粉丝列表



79
80
81
82
83
84
85
86
87
# File 'lib/wxapi/tag.rb', line 79

def users_of_tags(tagid,next_openid="")
  body = {
    tagid: tagid,
    next_openid: next_openid
  }.to_json
  access_token = get_access_token
  response = RestClient.post("#{prefix}/cgi-bin/user/tag/get?access_token=#{access_token}", body)
  JSON.parse(response)
end