Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
weixin_authorize
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
weixin_authorize
Commits
f8c5a52f
Commit
f8c5a52f
authored
Feb 12, 2015
by
lanrion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完善群发信息API接口
parent
5eafcfbc
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
16 deletions
+32
-16
lib/weixin_authorize/api/mass.rb
+16
-4
lib/weixin_authorize/api/media.rb
+5
-5
spec/api/mass_spec.rb
+10
-6
spec/spec_helper.rb
+1
-1
No files found.
lib/weixin_authorize/api/mass.rb
View file @
f8c5a52f
...
...
@@ -3,7 +3,7 @@ module WeixinAuthorize
module
Api
module
Mass
MSG_TYPE
=
[
"mpnews"
,
"image"
,
"text"
,
"voice"
,
"mpvideo"
]
.
freeze
MSG_TYPE
=
[
"mpnews"
,
"image"
,
"text"
,
"voice"
,
"mpvideo"
]
# media_info= {"media_id" media_id}
# https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_token=ACCESS_TOKEN
...
...
@@ -21,7 +21,6 @@ module WeixinAuthorize
def
mass_with_openids
(
openids
,
media_info
,
msgtype
=
"mpnews"
)
openid_option
=
{
"touser"
=>
openids
}
media
=
generate_media
(
msgtype
,
media_info
,
openid_option
)
mass_url
=
"
#{
mass_base_url
}
/send"
http_post
(
mass_url
,
media
)
end
...
...
@@ -30,7 +29,21 @@ module WeixinAuthorize
# 另外,删除群发消息只能删除图文消息和视频消息,其他类型的消息一经发送,无法删除。
def
mass_delete_with_msgid
(
msg_id
)
mass_url
=
"
#{
mass_base_url
}
/delete"
http_post
(
mass_url
,
{
"msgid"
=>
msg_id
})
http_post
(
mass_url
,
{
"msg_id"
=>
msg_id
})
end
# 预览接口【订阅号与服务号认证后均可用】
def
mass_preview
(
openid
,
media_info
,
msgtype
=
"mpnews"
)
openid_option
=
{
"touser"
=>
openid
}
media
=
generate_media
(
msgtype
,
media_info
,
openid_option
)
mass_url
=
"
#{
mass_base_url
}
/preview"
http_post
(
mass_url
,
media
)
end
# 查询群发消息发送状态【订阅号与服务号认证后均可用】
def
mass_get_status
(
msg_id
)
mass_url
=
"
#{
mass_base_url
}
/get"
http_post
(
mass_url
,
{
"msg_id"
=>
msg_id
})
end
private
...
...
@@ -42,7 +55,6 @@ module WeixinAuthorize
def
generate_media
(
msgtype
,
media_info
,
option
)
msgtype
=
msgtype
.
to_s
raise
"
#{
msgtype
}
is a valid msgtype"
if
not
MSG_TYPE
.
include?
(
msgtype
)
{
msgtype
=>
convert_media_info
(
msgtype
,
media_info
),
"msgtype"
=>
msgtype
...
...
lib/weixin_authorize/api/media.rb
View file @
f8c5a52f
...
...
@@ -22,7 +22,7 @@ module WeixinAuthorize
download_media_url
end
# 上传图文消息素材
# 上传图文消息素材
, 主要用于群发消息接口
# {
# "articles": [
# {
...
...
@@ -70,6 +70,10 @@ module WeixinAuthorize
private
def
media_base_url
"/media"
end
def
process_file
(
media
)
return
media
if
media
.
is_a?
(
File
)
&&
jpep?
(
media
)
...
...
@@ -87,10 +91,6 @@ module WeixinAuthorize
file
end
def
media_base_url
"/media"
end
def
process_media
(
uploader
)
uploader
=
covert
(
uploader
)
uploader
.
file
.
to_file
...
...
spec/api/mass_spec.rb
View file @
f8c5a52f
...
...
@@ -45,17 +45,21 @@ describe WeixinAuthorize::Api::Mass do
end
it
"#mass_with_group with mpnews"
do
response
=
$client
.
mass_with_group
(
"1"
,
mass_media_id
)
response
=
$client
.
mass_with_group
(
"1"
,
"mass_group_text"
,
"text"
)
expect
(
response
.
code
).
to
eq
(
WeixinAuthorize
::
OK_CODE
)
expect
(
response
.
result
[
"type"
]).
to
eq
(
"mpnews"
)
expect
(
response
.
result
.
keys
).
to
eq
([
"type"
,
"msg_id"
,
"errmsg"
,
"errcode"
])
end
it
"#mass_with_openids with mpnews"
do
it
"#mass_with_openids with mpnews
and can delete message
"
do
response
=
$client
.
mass_with_openids
([
ENV
[
"OPENID"
]],
mass_media_id
)
expect
(
response
.
code
).
to
eq
(
WeixinAuthorize
::
OK_CODE
)
expect
(
response
.
result
[
"type"
]).
to
eq
(
"mpnews"
)
expect
(
response
.
result
.
keys
).
to
eq
([
"type"
,
"msg_id"
,
"errmsg"
,
"errcode"
])
expect
(
response
.
result
.
keys
).
to
eq
([
"msg_id"
])
delete_res
=
$client
.
mass_delete_with_msgid
(
response
.
result
[
"msg_id"
])
expect
(
delete_res
.
code
).
to
eq
(
WeixinAuthorize
::
OK_CODE
)
end
it
"#mass_preview can preview by openid"
do
response
=
$client
.
mass_preview
(
ENV
[
"OPENID"
],
"mass_text"
,
"text"
)
expect
(
response
.
code
).
to
eq
(
WeixinAuthorize
::
OK_CODE
)
end
end
spec/spec_helper.rb
View file @
f8c5a52f
...
...
@@ -55,7 +55,7 @@ redis_with_ns = Redis::Namespace.new("#{namespace}", :redis => redis)
WeixinAuthorize
.
configure
do
|
config
|
config
.
redis
=
redis_with_ns
config
.
rest_client_options
=
{
timeout:
1
,
open_timeout:
1
,
verify_ssl:
true
}
config
.
rest_client_options
=
{
timeout:
1
0
,
open_timeout:
10
,
verify_ssl:
true
}
end
$client
=
WeixinAuthorize
::
Client
.
new
(
ENV
[
"APPID"
],
ENV
[
"APPSECRET"
])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment