wxapi 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 05a6023ecbfe39cec24b74c8dbbc721c2b98d6c923a4361b2b54176ed0f1e994
4
- data.tar.gz: c2e7cc04f2901ca7b781ec48e849acfe31a9bf8fbfc0fe09579309d1ef86e621
3
+ metadata.gz: e6c1ca7c45c981fddec344e1b3ee80aeff8c4ee90ed7a0c4d64c5d61b248fefc
4
+ data.tar.gz: e0b4217d4b9b27854e1f8e690a5c59b93cef8d4a9d4dde4513b65dc50ce346fa
5
5
  SHA512:
6
- metadata.gz: 968d5532cc49c9ad8cd66125870d7fcf0b5f459d61e25c202d1400e950d4ca0b5748a408bc924dbf4f6373cfe010976a37638f3b6b081e838c6787976dc124ed
7
- data.tar.gz: 02d633229c61daf254424f3cc49134fd8329448fbdd744a5e2217b2388ccd631b57c0ff025df9e080474cd5e7ec2f9538a7db1caa96c5e1e28c1d73bd50fe90d
6
+ metadata.gz: 978177b85704a44504b763d22290fc5c395f6f099c49224dc8570435c8869b388a1d7605ea33431c8d4ee5f153ddc3c36ec63f1ad80a6f2c46a36e7f2035aeb6
7
+ data.tar.gz: 3726fbd12005b8aca63cb2af99e4194d7a163b0196a5a5b46b52481ca718db1020f9be3411e4dfb502f964af09a7c98145353bdf2a76d441dab519da595cd3a6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- wxapi (1.0.1)
4
+ wxapi (1.0.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -0,0 +1,13 @@
1
+ class Wxapi
2
+ module Attach
3
+ def upload_temp_image(file_path,type='image')
4
+ access_token = get_access_token()
5
+ response = RestClient.post("#{prefix}/cgi-bin/media/upload",
6
+ {
7
+ access_token: access_token,
8
+ type: type,
9
+ media: File.new(file_path, 'rb')})
10
+ JSON.parse(response)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ class Wxapi
2
+ module Remark
3
+ # 设置用户备注名
4
+ def remark_user(open_id,remark)
5
+ body = {
6
+ openid: open_id,
7
+ remark: remark
8
+ }.to_json
9
+ access_token = get_access_token
10
+ response = RestClient.post("#{prefix}/cgi-bin/user/info/updateremark?access_token=#{access_token}", body)
11
+ JSON.parse(response)
12
+ end
13
+
14
+
15
+
16
+ end
17
+ end
data/lib/wxapi/tag.rb ADDED
@@ -0,0 +1,116 @@
1
+ class Wxapi
2
+ module Tag
3
+
4
+ # 1. 创建标签
5
+ #
6
+ # 一个公众号,最多可以创建100个标签。
7
+ def new_tag(name="")
8
+ body = {
9
+ tag:{
10
+ name: name
11
+ }
12
+ }.to_json
13
+ access_token = get_access_token
14
+ response = RestClient.post("#{prefix}/cgi-bin/tags/create?access_token=#{access_token}", body)
15
+ JSON.parse(response)
16
+ end
17
+
18
+ # 获取公众号已创建的标签
19
+ # 返回说明
20
+ #
21
+ # {
22
+ # "tags":[{
23
+ # "id":1,
24
+ # "name":"每天一罐可乐星人",
25
+ # "count":0 //此标签下粉丝数
26
+ # },
27
+ # {
28
+ # "id":2,
29
+ # "name":"星标组",
30
+ # "count":0
31
+ # }]}
32
+ def tags
33
+ access_token = get_access_token
34
+ response = RestClient.get("#{prefix}/cgi-bin/tags/get?access_token=#{access_token}")
35
+ JSON.parse(response)
36
+ end
37
+
38
+ def update_tag(id=0,name="")
39
+ body = {
40
+ tag:{
41
+ id: id,
42
+ name: name
43
+ }
44
+ }.to_json
45
+ access_token = get_access_token
46
+ response = RestClient.post("#{prefix}/cgi-bin/tags/update?access_token=#{access_token}", body)
47
+ JSON.parse(response)
48
+ end
49
+
50
+ # 删除标签
51
+ # 一个标签下的粉丝列表不会自动删除
52
+ # 删除标签后,所有该标签下的粉丝会取消标签的标记。
53
+ def delete_tag(id)
54
+ body = {
55
+ tag:{
56
+ id: id
57
+ }
58
+ }.to_json
59
+ access_token = get_access_token
60
+ response = RestClient.post("#{prefix}/cgi-bin/tags/delete?access_token=#{access_token}", body)
61
+ JSON.parse(response)
62
+
63
+ end
64
+
65
+
66
+ # 批量为用户打标签
67
+
68
+ def tag_users(tagid,openid_list)
69
+ body = {
70
+ openid_list: openid_list
71
+ }.to_json
72
+ access_token = get_access_token
73
+ response = RestClient.post("#{prefix}/cgi-bin/tags/members/batchtagging?access_token=#{access_token}", body)
74
+ JSON.parse(response)
75
+ end
76
+
77
+ #获取标签下粉丝列表
78
+ #
79
+ def users_of_tags(tagid,next_openid="")
80
+ body = {
81
+ tagid: tagid,
82
+ next_openid: next_openid
83
+ }.to_json
84
+ access_token = get_access_token
85
+ response = RestClient.post("#{prefix}/cgi-bin/user/tag/get?access_token=#{access_token}", body)
86
+ JSON.parse(response)
87
+ end
88
+
89
+ # 批量为用户取消标签
90
+ def untag_users(tagid,openid_list=[])
91
+ raise "openid_list is empty" if openid_list.empty?
92
+ raise 'tagid is empty' if tagid == 0
93
+ raise 'size of openid_list is more than 50' if openid_list.size > 50
94
+
95
+ body = {
96
+ openid_list: openid_list
97
+ }.to_json
98
+ access_token = get_access_token
99
+ response = RestClient.post("#{prefix}/cgi-bin/tags/members/batchuntagging?access_token=#{access_token}", body)
100
+ JSON.parse(response)
101
+ end
102
+
103
+
104
+ # 获取用户身上的标签列表
105
+ def tags_of_user(open_id)
106
+ body = {
107
+ openid: open_id
108
+ }.to_json
109
+ access_token = get_access_token
110
+ response = RestClient.post("#{prefix}/cgi-bin/tags/getidlist?access_token=#{access_token}", body)
111
+ JSON.parse(response)
112
+ end
113
+
114
+
115
+ end
116
+ end
data/lib/wxapi/user.rb CHANGED
@@ -34,8 +34,47 @@ class Wxapi
34
34
  #
35
35
  def get_userinfo(openid)
36
36
  # request access_token
37
- access_token = get_access_token()
37
+ access_token = get_access_token
38
38
  JSON.parse RestClient.get("#{prefix}/cgi-bin/user/info?access_token=#{access_token}&openid=#{openid}&lang=zh_CN").body
39
39
  end
40
+
41
+ # 获取公众号的黑名单列表
42
+ def user_list(next_openid = '')
43
+ access_token = get_access_token
44
+ JSON.parse RestClient.get("#{prefix}/cgi-bin/user/get?access_token=#{access_token}&next_openid=#{next_openid}").body
45
+ end
46
+
47
+ # 批量获取用户基本信息
48
+ # 最多支持一次拉取100条。
49
+ def batch_user_detail(openid_list=[],lang="zh_CN")
50
+
51
+ raise 'openid_list is empty' if openid_list.empty?
52
+ raise 'openid_list is too long' if openid_list.length > 100
53
+
54
+
55
+ user_list = []
56
+ openid_list.each do |openid|
57
+ user_list << {openid: openid, lang: lang}
58
+ end
59
+ access_token = get_access_token
60
+ JSON.parse RestClient.post("#{prefix}/cgi-bin/user/info/batchget?access_token=#{access_token}", {user_list: user_list}.to_json)
61
+ end
62
+
63
+ # 2. 拉黑用户
64
+ def get_black_list()
65
+ access_token = get_access_token
66
+ JSON.parse RestClient.post("#{prefix}/cgi-bin/tags/members/getblacklist?access_token=#{access_token}", {begin_openid: ''}.to_json)
67
+ end
68
+
69
+ def batch_black_list(openid_list=[])
70
+ access_token = get_access_token
71
+ JSON.parse RestClient.post("#{prefix}/cgi-bin/tags/members/batchblacklist?access_token=#{access_token}", {openid_list: openid_list}.to_json)
72
+ end
73
+
74
+ #3. 取消拉黑用户
75
+ def batchunblacklist(openid_list=[])
76
+ access_token = get_access_token
77
+ JSON.parse RestClient.post("#{prefix}/cgi-bin/tags/members/batchunblacklist?access_token=#{access_token}", {openid_list: openid_list}.to_json)
78
+ end
40
79
  end
41
80
  end
data/lib/wxapi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Wxapi
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.4"
3
3
  end
data/lib/wxapi.rb CHANGED
@@ -8,7 +8,8 @@ require "wxapi/aes"
8
8
  require "wxapi/utils"
9
9
  require "wxapi/user"
10
10
  require "wxapi/material"
11
-
11
+ require 'rest-client'
12
+ require 'wxapi/attach'
12
13
  class Wxapi
13
14
 
14
15
 
@@ -22,6 +23,7 @@ class Wxapi
22
23
  include Tp
23
24
  include User
24
25
  include Utils
26
+ include Attach
25
27
 
26
28
  # 默认不缓存 access_token, access_token_cache = True 缓存
27
29
  # @param <hash> aoptions
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wxapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - '黄滚 twitter: @hg_nohair'
@@ -113,9 +113,12 @@ files:
113
113
  - lib/wxapi/access_token.rb
114
114
  - lib/wxapi/account.rb
115
115
  - lib/wxapi/aes.rb
116
+ - lib/wxapi/attach.rb
116
117
  - lib/wxapi/kf_message.rb
117
118
  - lib/wxapi/material.rb
118
119
  - lib/wxapi/menu.rb
120
+ - lib/wxapi/remark.rb
121
+ - lib/wxapi/tag.rb
119
122
  - lib/wxapi/templet_message.rb
120
123
  - lib/wxapi/user.rb
121
124
  - lib/wxapi/utils.rb