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
bce2a6e5
Commit
bce2a6e5
authored
May 02, 2014
by
lanrion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
renamed broadcast.rb to mass.rb
parent
9b2bf127
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
8 deletions
+66
-8
lib/weixin_authorize/api/broadcast.rb
+0
-8
lib/weixin_authorize/api/mass.rb
+66
-0
No files found.
lib/weixin_authorize/api/broadcast.rb
deleted
100644 → 0
View file @
9b2bf127
# encoding: utf-8
module
WeixinAuthorize
module
Api
module
Broadcast
end
end
end
lib/weixin_authorize/api/mass.rb
0 → 100644
View file @
bce2a6e5
# encoding: utf-8
module
WeixinAuthorize
module
Api
module
Mass
MSG_TYPE
=
[
"mpnews"
,
"image"
,
"text"
,
"voice"
,
"mpvideo"
].
freeze
# media_info= {"media_id" media_id}
# https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_token=ACCESS_TOKEN
def
mass_with_group
(
group_id
,
media_info
,
msgtype
=
"mpnews"
)
group_option
=
{
"filter"
=>
{
"group_id"
=>
group_id
.
to_s
}}
media
=
generate_media
(
msgtype
,
media_info
,
group_option
)
mass_url
=
"
#{
mass_base_url
}
/sendall"
http_post
(
mass_url
,
media
)
end
# https://api.weixin.qq.com/cgi-bin/message/mass/send?access_token=ACCESS_TOKEN
# if mpvideo,
# media_info= {"media_id" => media_id, "title" => "title", "description" => "description"}
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
# 请注意,只有已经发送成功的消息才能删除删除消息只是将消息的图文详情页失效,已经收到的用户,还是能在其本地看到消息卡片。
# 另外,删除群发消息只能删除图文消息和视频消息,其他类型的消息一经发送,无法删除。
def
mass_delete_with_msgid
(
msg_id
)
mass_url
=
"
#{
mass_base_url
}
/delete"
http_post
(
mass_url
,
{
"msgid"
=>
msg_id
})
end
private
def
mass_base_url
"/message/mass"
end
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
}.
merge
(
option
)
end
# 如果用户填写的media信息,是字符串,则转换来符合的数据结构,如果 是hash,则直接使用用户的结构。
def
convert_media_info
(
msgtype
,
media_info
)
if
media_info
.
is_a?
(
String
)
if
msgtype
==
"text"
return
{
"content"
=>
media_info
}
else
return
{
"media_id"
=>
media_info
}
end
end
media_info
end
end
end
end
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