wxapi 1.0.1 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 100fdf3b99ae4aeb7ddc3a7c4433c502b56048d9235590944b369a7989320729
4
- data.tar.gz: 1af2c21175d8f63f62078b0b3944579d8af9628ef44aff78ab13f2ba3f945267
3
+ metadata.gz: e6c1ca7c45c981fddec344e1b3ee80aeff8c4ee90ed7a0c4d64c5d61b248fefc
4
+ data.tar.gz: e0b4217d4b9b27854e1f8e690a5c59b93cef8d4a9d4dde4513b65dc50ce346fa
5
5
  SHA512:
6
- metadata.gz: d226b31593a1a794963ba8a6acb4820ca785c3eff1545d35e4e2233a46cd2341de4bccef98797db4727ca1d2fc0d3763291549cc015c34d9a3424d0df3e848dd
7
- data.tar.gz: ceabcbb9eb1bb2f5535c3dc9b83b31be552a32ce5afa0c2fcd347242fe0a3095361b18165c3b330ffdd7d3d6ba804036ee3fa2138e4df448254ade1dbeb0d4ce
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.0)
4
+ wxapi (1.0.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/Rakefile CHANGED
@@ -4,6 +4,6 @@ task :default => :spec
4
4
 
5
5
  task :upload do |t|
6
6
  puts "Uploading not implemented"
7
- wxApi = WxApi.new app_id: 'wx3b8fe6d36cc00e3e'
7
+ wxApi = Wxapi.new app_id: 'wx3b8fe6d36cc00e3e'
8
8
  puts wxApi.get_access_token
9
9
  end
data/bin/console CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "bundler/setup"
4
- require "wx_api"
4
+ require "wxapi"
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -5,7 +5,7 @@
5
5
  # Wechat number: zmx119966
6
6
  ####################################################
7
7
 
8
- class WxApi
8
+ class Wxapi
9
9
  module AccessToken
10
10
 
11
11
  ###
data/lib/wxapi/account.rb CHANGED
@@ -5,7 +5,7 @@
5
5
  # Wechat number: zmx119966
6
6
  ####################################################
7
7
 
8
- class WxApi
8
+ class Wxapi
9
9
  module Account
10
10
  ###
11
11
  # 获取临时场景带惨二维码,30天有效
data/lib/wxapi/aes.rb CHANGED
@@ -5,7 +5,7 @@
5
5
  # Wechat number: zmx119966
6
6
  ####################################################
7
7
 
8
- class WxApi
8
+ class Wxapi
9
9
  module Aes
10
10
  # 解密
11
11
  def decrypt(key, dicrypted_string)
@@ -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
@@ -5,7 +5,7 @@
5
5
  # Wechat number: zmx119966
6
6
  ####################################################
7
7
 
8
- class WxApi
8
+ class Wxapi
9
9
  module Kf
10
10
 
11
11
  ###
@@ -5,7 +5,7 @@
5
5
  # Wechat number: zmx119966
6
6
  ####################################################
7
7
 
8
- class WxApi
8
+ class Wxapi
9
9
  module Material
10
10
  ###
11
11
  # 获得临时图片素材的 media_id
data/lib/wxapi/menu.rb CHANGED
@@ -5,7 +5,7 @@
5
5
  # Wechat number: zmx119966
6
6
  ####################################################
7
7
 
8
- class WxApi
8
+ class Wxapi
9
9
  module Menu
10
10
  ###
11
11
  # create wechat public menu
@@ -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
@@ -5,7 +5,7 @@
5
5
  # Wechat number: zmx119966
6
6
  ####################################################
7
7
 
8
- class WxApi
8
+ class Wxapi
9
9
  module Tp
10
10
  ###
11
11
  # @param <JSON> message
data/lib/wxapi/user.rb CHANGED
@@ -5,7 +5,7 @@
5
5
  # Wechat number: zmx119966
6
6
  ####################################################
7
7
 
8
- class WxApi
8
+ class Wxapi
9
9
  module User
10
10
  # 获取用户信息
11
11
  # @return <JSON>
@@ -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/utils.rb CHANGED
@@ -5,7 +5,7 @@
5
5
  # Wechat number: zmx119966
6
6
  ####################################################
7
7
 
8
- class WxApi
8
+ class Wxapi
9
9
  module Utils
10
10
  # todo
11
11
  end
data/lib/wxapi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
- class WxApi
2
- VERSION = "1.0.1"
1
+ class Wxapi
2
+ VERSION = "1.0.4"
3
3
  end
@@ -8,8 +8,9 @@ require "wxapi/aes"
8
8
  require "wxapi/utils"
9
9
  require "wxapi/user"
10
10
  require "wxapi/material"
11
-
12
- class WxApi
11
+ require 'rest-client'
12
+ require 'wxapi/attach'
13
+ class Wxapi
13
14
 
14
15
 
15
16
 
@@ -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
data/test.rb CHANGED
@@ -1,9 +1,9 @@
1
- require './lib/wx_api'
1
+ require './lib/wxapi'
2
2
  require 'redis'
3
3
  require 'rest-client'
4
4
  require 'json'
5
5
  $redis = Redis.new(url: "redis://localhost:6379/0")
6
- $we_api = WxApi.new app_id: 'wx3b8fe6d36cc00e3e',
6
+ $we_api = Wxapi.new app_id: 'wx3b8fe6d36cc00e3e',
7
7
  app_secret: 'e6755d03d7f58b71aac8c22f6271c265',
8
8
  access_token_cache: false,
9
9
  api_prefix: 'https://proxy.biying88.cn/proxywx'
data/wxapi.gemspec CHANGED
@@ -5,7 +5,7 @@ require "wxapi/version"
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "wxapi"
8
- spec.version = WxApi::VERSION
8
+ spec.version = Wxapi::VERSION
9
9
  spec.authors = ["黄滚 twitter: @hg_nohair"]
10
10
  spec.email = ["xurenlu@gmail.com"]
11
11
 
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.1
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - '黄滚 twitter: @hg_nohair'
@@ -109,13 +109,16 @@ files:
109
109
  - Rakefile
110
110
  - bin/console
111
111
  - bin/setup
112
- - lib/wx_api.rb
112
+ - lib/wxapi.rb
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