wx_ext 0.1.6 → 0.1.8

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
  SHA1:
3
- metadata.gz: 23c3940298003a23d43bbd1ff4ee9af7211a3221
4
- data.tar.gz: d62ae090872a99c079048c344418b25c5fb0bf6b
3
+ metadata.gz: 9cfbcac6ac267ac9cc7b021590b75ba89136f1d5
4
+ data.tar.gz: ce32c32fa26f850e1e7d6ab1dd59175a8e17a2ca
5
5
  SHA512:
6
- metadata.gz: a92c4ac504ebe1b2d8602cc5d7cd094d302bdd925c5d57c37c2fe036364be52618dd33dbbfcb98361d065fd49b3ec2af3bd57e00e29b4b0e375177c015ef5381
7
- data.tar.gz: bceaf355c71931d988c0d9879a5234be4cf6408c794fb53888b5e1789ba095f0c53959bb689ac76949895ae77078dc01c4eb81d5d4d64c79e7fea3a959c39199
6
+ metadata.gz: 59d2457c7a110da971cb70d669fec7cf74366bc3f4b419ed89097994c3ec8e51a55960d0edbc44bfbd7a127fe556b9d791bdfcb9e1ce88636fe8b2f90df05201
7
+ data.tar.gz: 3f5cf2cbbea4ee9dc43edff9cb1a93852986e344933b25530ba0a9e9ec7baeda8efbcd062e020fe266482a8ff28356110244a555469d4c7e36c07b89c61fb8f0
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # WxExt
2
2
 
3
- 微信接口之外的扩展gem
3
+ Weixin extention, sougou weixin post spider and weixin api gem
4
4
 
5
5
  ## Installation
6
6
 
@@ -16,15 +16,15 @@ And then execute:
16
16
 
17
17
  ## Usage
18
18
 
19
- 使用请看spec/wx_ext/
19
+ See spec/wx_ext/
20
20
 
21
- ## 测试
21
+ ## Test
22
22
 
23
- 1. 修改 spec/wx_ext/weixin_spec.rb 文件中的账户密码
24
- 2. rspec spec/wx_ext/weixin_spec.rb
25
- 3. rspec spec/wx_ext/sougou_weixin_spec.rb
23
+ 1. Change `spec/wx_ext/weixin_spec.rb` file username and pass
24
+ 2. `rspec spec/wx_ext/weixin_spec.rb`
25
+ 3. `rspec spec/wx_ext/sougou_weixin_spec.rb`
26
26
 
27
- ## yard
27
+ ## Yard
28
28
 
29
29
  `yardoc lib/*.rb lib/wx_ext/*.rb lib/wx_ext/api/*.rb lib/wx_ext/api/user/*.rb`
30
30
 
@@ -11,153 +11,153 @@ module WxExt
11
11
  # User api of weixin.
12
12
  #
13
13
  # @author FuShengYang
14
- module Base
15
- class << self
16
- # Get the access_token for other apis via get.
17
- #
18
- # @param [Enumerable<String>] appid
19
- # @param [Enumerable<String>] secret
20
- # @param [Enumerable<String>] grant_type
21
- # @return [Hash] "access_token":"ACCESS_TOKEN","expires_in":7200
22
- def get_access_token(appid, secret, grant_type = 'client_credential')
23
- url = 'https://api.weixin.qq.com/cgi-bin/token'\
24
- "?grant_type=#{grant_type}&appid=#{appid}&secret=#{secret}"
25
- Helper.http_get(url, { accept: :json })
26
- end
14
+ module Base
15
+ # Get the access_token for other apis via get.
16
+ #
17
+ # @param [Enumerable<String>] appid
18
+ # @param [Enumerable<String>] secret
19
+ # @param [Enumerable<String>] grant_type
20
+ # @return [Hash] "access_token":"ACCESS_TOKEN","expires_in":7200
21
+ def get_access_token(appid, secret, grant_type = 'client_credential')
22
+ url = 'https://api.weixin.qq.com/cgi-bin/token'\
23
+ "?grant_type=#{grant_type}&appid=#{appid}&secret=#{secret}"
24
+ Helper.http_get(url, { accept: :json })
25
+ end
27
26
 
28
- # Get weixin server ips.
29
- #
30
- # @param [Enumerable<String>] access_token
31
- # @return [Hash] A json parse hash.
32
- def get_weixin_ips(access_token)
33
- url = 'https://api.weixin.qq.com/cgi-bin/getcallbackip'\
34
- "?access_token=#{access_token}"
35
- Helper.http_get(url, { accept: :json })
36
- end
27
+ # Get weixin server ips.
28
+ #
29
+ # @param [Enumerable<String>] access_token
30
+ # @return [Hash] A json parse hash.
31
+ def get_weixin_ips(access_token)
32
+ url = 'https://api.weixin.qq.com/cgi-bin/getcallbackip'\
33
+ "?access_token=#{access_token}"
34
+ Helper.http_get(url, { accept: :json })
35
+ end
37
36
 
38
- # Get weixin error_code and msg map.
39
- #
40
- # @return [Hash] A json parse hash.
41
- def code_msg
42
- {
43
- -1 => '系统繁忙,此时请开发者稍候再试',
44
- 0 => '请求成功',
45
- 40001 => '获取access_token时AppSecret错误,或者access_token无效。请开发者认真比对AppSecret的正确性,或查看是否正在为恰当的公众号调用接口',
46
- 40002 => '不合法的凭证类型',
47
- 40003 => '不合法的OpenID,请开发者确认OpenID(该用户)是否已关注公众号,或是否是其他公众号的OpenID',
48
- 40004 => '不合法的媒体文件类型',
49
- 40005 => '不合法的文件类型',
50
- 40006 => '不合法的文件大小',
51
- 40007 => '不合法的媒体文件id',
52
- 40008 => '不合法的消息类型',
53
- 40009 => '不合法的图片文件大小',
54
- 40010 => '不合法的语音文件大小',
55
- 40011 => '不合法的视频文件大小',
56
- 40012 => '不合法的缩略图文件大小',
57
- 40013 => '不合法的AppID,请开发者检查AppID的正确性,避免异常字符,注意大小写',
58
- 40014 => '不合法的access_token,请开发者认真比对access_token的有效性(如是否过期),或查看是否正在为恰当的公众号调用接口',
59
- 40015 => '不合法的菜单类型',
60
- 40016 => '不合法的按钮个数',
61
- 40017 => '不合法的按钮个数',
62
- 40018 => '不合法的按钮名字长度',
63
- 40019 => '不合法的按钮KEY长度',
64
- 40020 => '不合法的按钮URL长度',
65
- 40021 => '不合法的菜单版本号',
66
- 40022 => '不合法的子菜单级数',
67
- 40023 => '不合法的子菜单按钮个数',
68
- 40024 => '不合法的子菜单按钮类型',
69
- 40025 => '不合法的子菜单按钮名字长度',
70
- 40026 => '不合法的子菜单按钮KEY长度',
71
- 40027 => '不合法的子菜单按钮URL长度',
72
- 40028 => '不合法的自定义菜单使用用户',
73
- 40029 => '不合法的oauth_code',
74
- 40030 => '不合法的refresh_token',
75
- 40031 => '不合法的openid列表',
76
- 40032 => '不合法的openid列表长度',
77
- 40033 => '不合法的请求字符,不能包含\uxxxx格式的字符',
78
- 40035 => '不合法的参数',
79
- 40038 => '不合法的请求格式',
80
- 40039 => '不合法的URL长度',
81
- 40050 => '不合法的分组id',
82
- 40051 => '分组名字不合法',
83
- 41001 => '缺少access_token参数',
84
- 41002 => '缺少appid参数',
85
- 41003 => '缺少refresh_token参数',
86
- 41004 => '缺少secret参数',
87
- 41005 => '缺少多媒体文件数据',
88
- 41006 => '缺少media_id参数',
89
- 41007 => '缺少子菜单数据',
90
- 41008 => '缺少oauth code',
91
- 41009 => '缺少openid',
92
- 42001 => 'access_token超时,请检查access_token的有效期,请参考基础支持-获取access_token中,对access_token的详细机制说明',
93
- 42002 => 'refresh_token超时',
94
- 42003 => 'oauth_code超时',
95
- 43001 => '需要GET请求',
96
- 43002 => '需要POST请求',
97
- 43003 => '需要HTTPS请求',
98
- 43004 => '需要接收者关注',
99
- 43005 => '需要好友关系',
100
- 44001 => '多媒体文件',
101
- 44002 => 'POST的数据包',
102
- 44003 => '图文消息内容',
103
- 44004 => '文本消息内容',
104
- 45001 => '多媒体文件大小超过',
105
- 45002 => '消息内容超过',
106
- 45003 => '标题字段超过',
107
- 45004 => '描述字段超过',
108
- 45005 => '链接字段超过',
109
- 45006 => '图片链接字段超过',
110
- 45007 => '语音播放时间超过',
111
- 45008 => '图文消息超过',
112
- 45009 => '接口调用超过',
113
- 45010 => '创建菜单个数超过',
114
- 45015 => '回复时间超过',
115
- 45016 => '系统分组,不允许修改',
116
- 45017 => '分组名字过长',
117
- 45018 => '分组数量超过上限',
118
- 46001 => '不存在媒体数据',
119
- 46002 => '不存在的菜单版本',
120
- 46003 => '不存在的菜单数据',
121
- 46004 => '不存在的用户',
122
- 47001 => '解析JSON/XML内容错误',
123
- 48001 => 'api功能未授权,请确认公众号已获得该接口,可以在公众平台官网-开发者中心页中查看接口权限',
124
- 50001 => '用户未授权该api',
125
- 61451 => '参数错误(invalid parameter)',
126
- 61452 => '无效客服账号(invalid kf_account)',
127
- 61453 => '客服帐号已存在(kf_account exsited)',
128
- 61454 => '客服帐号名长度超过(仅允许10个英文字符,不包括@及@后的公众号的微信号)(invalid kf_acount length)',
129
- 61455 => '客服帐号名包含非法字符(仅允许英文+数字)(illegal character in kf_account)',
130
- 61456 => '客服帐号个数超过(10个客服账号)(kf_account count exceeded)',
131
- 61457 => '无效头像文件类型(invalid file type)',
132
- 61450 => '系统错误(system error)',
133
- 61500 => '日期格式错误',
134
- 61501 => '日期范围错误'
135
- }
136
- end
37
+ # Get weixin error_code and msg map.
38
+ #
39
+ # @return [Hash] A json parse hash.
40
+ def code_msg
41
+ {
42
+ -1 => '系统繁忙,此时请开发者稍候再试',
43
+ 0 => '请求成功',
44
+ 40001 => '获取access_token时AppSecret错误,或者access_token无效。请开发者认真比对AppSecret的正确性,或查看是否正在为恰当的公众号调用接口',
45
+ 40002 => '不合法的凭证类型',
46
+ 40003 => '不合法的OpenID,请开发者确认OpenID(该用户)是否已关注公众号,或是否是其他公众号的OpenID',
47
+ 40004 => '不合法的媒体文件类型',
48
+ 40005 => '不合法的文件类型',
49
+ 40006 => '不合法的文件大小',
50
+ 40007 => '不合法的媒体文件id',
51
+ 40008 => '不合法的消息类型',
52
+ 40009 => '不合法的图片文件大小',
53
+ 40010 => '不合法的语音文件大小',
54
+ 40011 => '不合法的视频文件大小',
55
+ 40012 => '不合法的缩略图文件大小',
56
+ 40013 => '不合法的AppID,请开发者检查AppID的正确性,避免异常字符,注意大小写',
57
+ 40014 => '不合法的access_token,请开发者认真比对access_token的有效性(如是否过期),或查看是否正在为恰当的公众号调用接口',
58
+ 40015 => '不合法的菜单类型',
59
+ 40016 => '不合法的按钮个数',
60
+ 40017 => '不合法的按钮个数',
61
+ 40018 => '不合法的按钮名字长度',
62
+ 40019 => '不合法的按钮KEY长度',
63
+ 40020 => '不合法的按钮URL长度',
64
+ 40021 => '不合法的菜单版本号',
65
+ 40022 => '不合法的子菜单级数',
66
+ 40023 => '不合法的子菜单按钮个数',
67
+ 40024 => '不合法的子菜单按钮类型',
68
+ 40025 => '不合法的子菜单按钮名字长度',
69
+ 40026 => '不合法的子菜单按钮KEY长度',
70
+ 40027 => '不合法的子菜单按钮URL长度',
71
+ 40028 => '不合法的自定义菜单使用用户',
72
+ 40029 => '不合法的oauth_code',
73
+ 40030 => '不合法的refresh_token',
74
+ 40031 => '不合法的openid列表',
75
+ 40032 => '不合法的openid列表长度',
76
+ 40033 => '不合法的请求字符,不能包含\uxxxx格式的字符',
77
+ 40035 => '不合法的参数',
78
+ 40038 => '不合法的请求格式',
79
+ 40039 => '不合法的URL长度',
80
+ 40050 => '不合法的分组id',
81
+ 40051 => '分组名字不合法',
82
+ 41001 => '缺少access_token参数',
83
+ 41002 => '缺少appid参数',
84
+ 41003 => '缺少refresh_token参数',
85
+ 41004 => '缺少secret参数',
86
+ 41005 => '缺少多媒体文件数据',
87
+ 41006 => '缺少media_id参数',
88
+ 41007 => '缺少子菜单数据',
89
+ 41008 => '缺少oauth code',
90
+ 41009 => '缺少openid',
91
+ 42001 => 'access_token超时,请检查access_token的有效期,请参考基础支持-获取access_token中,对access_token的详细机制说明',
92
+ 42002 => 'refresh_token超时',
93
+ 42003 => 'oauth_code超时',
94
+ 43001 => '需要GET请求',
95
+ 43002 => '需要POST请求',
96
+ 43003 => '需要HTTPS请求',
97
+ 43004 => '需要接收者关注',
98
+ 43005 => '需要好友关系',
99
+ 44001 => '多媒体文件',
100
+ 44002 => 'POST的数据包',
101
+ 44003 => '图文消息内容',
102
+ 44004 => '文本消息内容',
103
+ 45001 => '多媒体文件大小超过',
104
+ 45002 => '消息内容超过',
105
+ 45003 => '标题字段超过',
106
+ 45004 => '描述字段超过',
107
+ 45005 => '链接字段超过',
108
+ 45006 => '图片链接字段超过',
109
+ 45007 => '语音播放时间超过',
110
+ 45008 => '图文消息超过',
111
+ 45009 => '接口调用超过',
112
+ 45010 => '创建菜单个数超过',
113
+ 45015 => '回复时间超过',
114
+ 45016 => '系统分组,不允许修改',
115
+ 45017 => '分组名字过长',
116
+ 45018 => '分组数量超过上限',
117
+ 46001 => '不存在媒体数据',
118
+ 46002 => '不存在的菜单版本',
119
+ 46003 => '不存在的菜单数据',
120
+ 46004 => '不存在的用户',
121
+ 47001 => '解析JSON/XML内容错误',
122
+ 48001 => 'api功能未授权,请确认公众号已获得该接口,可以在公众平台官网-开发者中心页中查看接口权限',
123
+ 50001 => '用户未授权该api',
124
+ 61451 => '参数错误(invalid parameter)',
125
+ 61452 => '无效客服账号(invalid kf_account)',
126
+ 61453 => '客服帐号已存在(kf_account exsited)',
127
+ 61454 => '客服帐号名长度超过(仅允许10个英文字符,不包括@及@后的公众号的微信号)(invalid kf_acount length)',
128
+ 61455 => '客服帐号名包含非法字符(仅允许英文+数字)(illegal character in kf_account)',
129
+ 61456 => '客服帐号个数超过(10个客服账号)(kf_account count exceeded)',
130
+ 61457 => '无效头像文件类型(invalid file type)',
131
+ 61450 => '系统错误(system error)',
132
+ 61500 => '日期格式错误',
133
+ 61501 => '日期范围错误'
134
+ }
135
+ end
137
136
 
138
- # Upload media to weixin.
139
- #
140
- # @param [Enumerable<String>] access_token
141
- # @param [Enumerable<String>] type 媒体文件类型,分别有图片(image)、语音(voice)、视频(video)和缩略图(thumb)
142
- # @param [File] media form-data中媒体文件标识,有filename、filelength、content-type等信息
143
- # @return [Hash] "type":"TYPE","media_id":"MEDIA_ID","created_at":123456789
144
- def upload_media(access_token, type, media)
145
- url = 'http://file.api.weixin.qq.com/cgi-bin/media/upload'\
146
- "?access_token=#{access_token}&type=#{type}"
147
- Helper.http_post(url, {file: media})
148
- end
137
+ # Upload media to weixin.
138
+ #
139
+ # @param [Enumerable<String>] access_token
140
+ # @param [Enumerable<String>] type 媒体文件类型,分别有图片(image)、语音(voice)、视频(video)和缩略图(thumb)
141
+ # @param [File] media form-data中媒体文件标识,有filename、filelength、content-type等信息
142
+ # @return [Hash] "type":"TYPE","media_id":"MEDIA_ID","created_at":123456789
143
+ def upload_media(access_token, type, media)
144
+ url = 'http://file.api.weixin.qq.com/cgi-bin/media/upload'\
145
+ "?access_token=#{access_token}&type=#{type}"
146
+ Helper.http_post(url, {file: media})
147
+ end
149
148
 
150
- # Download media from weixin.
151
- #
152
- # @param [Enumerable<String>] access_token
153
- # @param [Enumerable<String>] media_id
154
- # @return [Image] Download img.
155
- def download_media(access_token, media_id)
156
- url = 'http://file.api.weixin.qq.com/cgi-bin/media/get'\
157
- "?access_token=#{access_token}&media_id=#{media_id}"
158
- RestClient.get url
159
- end
149
+ # Download media from weixin.
150
+ #
151
+ # @param [Enumerable<String>] access_token
152
+ # @param [Enumerable<String>] media_id
153
+ # @return [Image] Download img.
154
+ def download_media(access_token, media_id)
155
+ url = 'http://file.api.weixin.qq.com/cgi-bin/media/get'\
156
+ "?access_token=#{access_token}&media_id=#{media_id}"
157
+ RestClient.get url
160
158
  end
159
+
160
+ extend self
161
161
  end
162
162
  end
163
163
  end
@@ -11,25 +11,25 @@ module WxExt
11
11
  #
12
12
  # @author FuShengYang
13
13
  module CustomerService
14
- class << self
15
- # Reply msg via post.
16
- #
17
- # @param [Enumerable<String>] access_token
18
- # @param [Enumerable<String>] to_user_openid
19
- # @param [Enumerable<String>] msg_type
20
- # @param [Hash] msg_hash
21
- # @return [Hash] Json based hash.
22
- def reply_msg(access_token, to_user_openid, msg_type, msg_hash)
23
- url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send'\
24
- "?access_token=#{access_token}"
25
- msg_hash = {
26
- :touser => to_user_openid,
27
- :msgtype => msg_type,
28
- "#{msg_type}".to_sym => msg_hash
29
- }
30
- Helper.http_post(url, msg_hash.to_json)
31
- end
14
+ # Reply msg via post.
15
+ #
16
+ # @param [Enumerable<String>] access_token
17
+ # @param [Enumerable<String>] to_user_openid
18
+ # @param [Enumerable<String>] msg_type
19
+ # @param [Hash] msg_hash
20
+ # @return [Hash] Json based hash.
21
+ def reply_msg(access_token, to_user_openid, msg_type, msg_hash)
22
+ url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send'\
23
+ "?access_token=#{access_token}"
24
+ msg_hash = {
25
+ :touser => to_user_openid,
26
+ :msgtype => msg_type,
27
+ "#{msg_type}".to_sym => msg_hash
28
+ }
29
+ Helper.http_post(url, msg_hash.to_json)
32
30
  end
31
+
32
+ extend self
33
33
  end
34
34
  end
35
35
  end
data/lib/wx_ext/api/js.rb CHANGED
@@ -11,58 +11,61 @@ module WxExt
11
11
  # User api of weixin.
12
12
  #
13
13
  # @author FuShengYang
14
- module Js
15
- class << self
16
- # Get js api ticket.
17
- #
18
- # @param [Enumerable<String>] access_token
19
- # @return [Hash] Json based hash.
20
- def get_jsapi_ticket(access_token)
21
- url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=#{access_token}&type=jsapi"
22
- Helper.http_get(url, { accept: :json })
23
- end
14
+ module Js
15
+ # Get js api ticket.
16
+ #
17
+ # @param [Enumerable<String>] access_token
18
+ # @return [Hash] Json based hash.
19
+ def get_jsapi_ticket(access_token)
20
+ url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=#{access_token}&type=jsapi"
21
+ Helper.http_get(url, { accept: :json })
22
+ end
24
23
 
25
- # Get js api config hash.
26
- #
27
- # @param [Enumerable<String>] access_token
28
- # @param [Enumerable<String>] url
29
- # @param [Enumerable<String>] app_id
30
- # @return [Hash] Json based hash.
31
- def get_jsapi_config(access_token, url, app_id)
32
- config_hash = {}
33
- jsapi_ticket_hash = get_jsapi_ticket(access_token)
34
- timestamp = set_timestamp
35
- noncestr = set_noncestr
36
- if jsapi_ticket_hash['errcode'] == 0
37
- jsapi_ticket = jsapi_ticket_hash['ticket']
38
- str = "jsapi_ticket=#{jsapi_ticket}&noncestr=#{noncestr}&timestamp=#{timestamp}&url=#{url}"
39
- signature = Digest::SHA1.hexdigest(str)
40
- config_hash = {
41
- app_id: app_id,
42
- timestamp: timestamp,
43
- noncestr: noncestr,
44
- signature: signature
45
- }
46
- end
47
- config_hash
24
+ # Get js api config hash.
25
+ #
26
+ # @param [Enumerable<String>] access_token
27
+ # @param [Enumerable<String>] url
28
+ # @param [Enumerable<String>] app_id
29
+ # @return [Hash] Json based hash.
30
+ def get_jsapi_config(access_token, url, app_id)
31
+ config_hash = {}
32
+ jsapi_ticket_hash = get_jsapi_ticket(access_token)
33
+ timestamp = set_timestamp
34
+ noncestr = set_noncestr
35
+ if jsapi_ticket_hash['errcode'] == 0
36
+ jsapi_ticket = jsapi_ticket_hash['ticket']
37
+ str = "jsapi_ticket=#{jsapi_ticket}&noncestr=#{noncestr}&timestamp=#{timestamp}&url=#{url}"
38
+ signature = Digest::SHA1.hexdigest(str)
39
+ config_hash = {
40
+ app_id: app_id,
41
+ timestamp: timestamp,
42
+ noncestr: noncestr,
43
+ signature: signature,
44
+ jsapi_ticket: jsapi_ticket,
45
+ url: url,
46
+ str: str
47
+ }
48
48
  end
49
+ config_hash
50
+ end
49
51
 
50
- private
52
+ private
51
53
 
52
- # Set the noncestr of 16 byte.
53
- #
54
- # @return [String] 16 byte str.
55
- def set_noncestr
56
- [*'a'..'z',*'0'..'9',*'A'..'Z'].sample(16).join
57
- end
54
+ # Set the noncestr of 16 byte.
55
+ #
56
+ # @return [String] 16 byte str.
57
+ def set_noncestr
58
+ [*'a'..'z',*'0'..'9',*'A'..'Z'].sample(16).join
59
+ end
58
60
 
59
- # Set the timestamp.
60
- #
61
- # @return [String] timestamp str.
62
- def set_timestamp
63
- Time.now.to_i.to_s
64
- end
61
+ # Set the timestamp.
62
+ #
63
+ # @return [String] timestamp str.
64
+ def set_timestamp
65
+ Time.now.to_i.to_s
65
66
  end
67
+
68
+ extend self
66
69
  end
67
70
  end
68
71
  end
@@ -10,74 +10,74 @@ module WxExt
10
10
  # User api of weixin.
11
11
  #
12
12
  # @author FuShengYang
13
- module Mass
14
- class << self
15
- # Upload news to weixin server via post.
16
- #
17
- # @param [Enumerable<String>] access_token
18
- # @param [Hash] news_hash
19
- # @return [Hash] Json based hash.
20
- def upload_news(access_token, news_hash)
21
- url = 'https://api.weixin.qq.com/cgi-bin/media/uploadnews'\
22
- "?access_token=#{access_token}"
23
- Helper.http_post(url, news_hash.to_json)
24
- end
13
+ module Mass
14
+ # Upload news to weixin server via post.
15
+ #
16
+ # @param [Enumerable<String>] access_token
17
+ # @param [Hash] news_hash
18
+ # @return [Hash] Json based hash.
19
+ def upload_news(access_token, news_hash)
20
+ url = 'https://api.weixin.qq.com/cgi-bin/media/uploadnews'\
21
+ "?access_token=#{access_token}"
22
+ Helper.http_post(url, news_hash.to_json)
23
+ end
25
24
 
26
- # Mass to users by filter group via post.
27
- #
28
- # @param [Enumerable<String>] access_token
29
- # @param [Hash] filter_hash
30
- # @return [Hash] Json based hash.
31
- def mass_by_filter_group(access_token, filter_hash)
32
- url = 'https://api.weixin.qq.com/cgi-bin/message/mass/sendall'\
33
- "?access_token=#{access_token}"
34
- Helper.http_post(url, filter_hash.to_json)
35
- end
25
+ # Mass to users by filter group via post.
26
+ #
27
+ # @param [Enumerable<String>] access_token
28
+ # @param [Hash] filter_hash
29
+ # @return [Hash] Json based hash.
30
+ def mass_by_filter_group(access_token, filter_hash)
31
+ url = 'https://api.weixin.qq.com/cgi-bin/message/mass/sendall'\
32
+ "?access_token=#{access_token}"
33
+ Helper.http_post(url, filter_hash.to_json)
34
+ end
36
35
 
37
- # Mass to users by openid via post.
38
- #
39
- # @param [Enumerable<String>] access_token
40
- # @param [Hash] openid_hash
41
- # @return [Hash] Json based hash.
42
- def mass_by_openid(access_token, openid_hash)
43
- url = 'https://api.weixin.qq.com/cgi-bin/message/mass/send'\
44
- "?access_token=#{access_token}"
45
- Helper.http_post(url, openid_hash.to_json)
46
- end
36
+ # Mass to users by openid via post.
37
+ #
38
+ # @param [Enumerable<String>] access_token
39
+ # @param [Hash] openid_hash
40
+ # @return [Hash] Json based hash.
41
+ def mass_by_openid(access_token, openid_hash)
42
+ url = 'https://api.weixin.qq.com/cgi-bin/message/mass/send'\
43
+ "?access_token=#{access_token}"
44
+ Helper.http_post(url, openid_hash.to_json)
45
+ end
47
46
 
48
- # Del mass via post.
49
- #
50
- # @param [Enumerable<String>] access_token
51
- # @param [String] msg_id
52
- # @return [Hash] Json based hash.
53
- def del_mass(access_token, msg_id)
54
- url = 'https://api.weixin.qq.com/cgi-bin/message/mass/delete'\
55
- "?access_token=#{access_token}"
56
- Helper.http_post(url, { msg_id: msg_id }.to_json)
57
- end
47
+ # Del mass via post.
48
+ #
49
+ # @param [Enumerable<String>] access_token
50
+ # @param [String] msg_id
51
+ # @return [Hash] Json based hash.
52
+ def del_mass(access_token, msg_id)
53
+ url = 'https://api.weixin.qq.com/cgi-bin/message/mass/delete'\
54
+ "?access_token=#{access_token}"
55
+ Helper.http_post(url, { msg_id: msg_id }.to_json)
56
+ end
58
57
 
59
- # Preview mass via post.
60
- #
61
- # @param [Enumerable<String>] access_token
62
- # @param [Hash] preview_hash
63
- # @return [Hash] Json based hash.
64
- def preview_mass(access_token, preview_hash)
65
- url = 'https://api.weixin.qq.com/cgi-bin/message/mass/preview'\
66
- "?access_token=#{access_token}"
67
- Helper.http_post(url, preview_hash.to_json)
68
- end
58
+ # Preview mass via post.
59
+ #
60
+ # @param [Enumerable<String>] access_token
61
+ # @param [Hash] preview_hash
62
+ # @return [Hash] Json based hash.
63
+ def preview_mass(access_token, preview_hash)
64
+ url = 'https://api.weixin.qq.com/cgi-bin/message/mass/preview'\
65
+ "?access_token=#{access_token}"
66
+ Helper.http_post(url, preview_hash.to_json)
67
+ end
69
68
 
70
- # Get mass status via post.
71
- #
72
- # @param [Enumerable<String>] access_token
73
- # @param [String] msg_id
74
- # @return [Hash] Json based hash.
75
- def get_mass_status(access_token, msg_id)
76
- url = 'https://api.weixin.qq.com/cgi-bin/message/mass/get'\
77
- "?access_token=#{access_token}"
78
- Helper.http_post(url, { msg_id: msg_id }.to_json)
79
- end
69
+ # Get mass status via post.
70
+ #
71
+ # @param [Enumerable<String>] access_token
72
+ # @param [String] msg_id
73
+ # @return [Hash] Json based hash.
74
+ def get_mass_status(access_token, msg_id)
75
+ url = 'https://api.weixin.qq.com/cgi-bin/message/mass/get'\
76
+ "?access_token=#{access_token}"
77
+ Helper.http_post(url, { msg_id: msg_id }.to_json)
80
78
  end
79
+
80
+ extend self
81
81
  end
82
82
  end
83
83
  end