Module: WeixinAuthorize::Api::Custom
- Included in:
- Client
- Defined in:
- lib/weixin_authorize/api/custom.rb
Constant Summary collapse
- CUSTOM_SERVICE =
"https://api.weixin.qq.com/customservice".freeze
- CUSTOM_RECORD_URL =
官方示例:1439571890, pageindex: 1, pagesize: 10, starttime: 1438707864 options: page_index: 查询第几页,从1开始page_size: 每页大小,每页最多拉取50条
"#{CUSTOM_SERVICE}/msgrecord/getrecord".freeze
- KF_SESSION_URL =
客服接口创建会话POST数据示例如下:
{ "kf_account" : "test1@test", "openid" : "OPENID", "text" : "这是一段附加信息" }
"#{CUSTOM_SERVICE}/kfsession/create".freeze
Instance Method Summary collapse
- #create_kf_session(account, open_id, text) ⇒ Object
- #get_custom_msg_record(start_time, end_time, options = {}) ⇒ Object
-
#send_image_custom(to_user, media_id) ⇒ Object
发送图片消息 { “touser”:“OPENID”, “msgtype”:“image”, “image”: { “media_id”:“MEDIA_ID” } }.
-
#send_mpnews_custom(to_user, media_id, options = {}) ⇒ Object
根据media_id发送图文消息 { “touser”:“OPENID”, “msgtype”:“mpnews”, “mpnews”: { “media_id”:“MEDIA_ID” } }.
-
#send_music_custom(to_user, media_id, musicurl, hqmusicurl, options = {}) ⇒ Object
发送音乐消息 { “touser”:“OPENID”, “msgtype”:“music”, “music”: { “title”:“MUSIC_TITLE”, “description”:“MUSIC_DESCRIPTION”, “musicurl”:“MUSIC_URL”, “hqmusicurl”:“HQ_MUSIC_URL”, “thumb_media_id”:“THUMB_MEDIA_ID” } }.
-
#send_news_custom(to_user, articles = []) ⇒ Object
发送图文消息 { “touser”:“OPENID”, “msgtype”:“news”, “news”:{ “articles”: [ { “title”:“Happy Day”, “description”:“Is Really A Happy Day”, “url”:“URL”, “picurl”:“PIC_URL” }, { “title”:“Happy Day”, “description”:“Is Really A Happy Day”, “url”:“URL”, “picurl”:“PIC_URL” } ] } }.
-
#send_text_custom(to_user, content) ⇒ Object
发送文本消息 { “touser”:“OPENID”, “msgtype”:“text”, “text”: { “content”:“Hello World” } }.
-
#send_video_custom(to_user, media_id, options = {}) ⇒ Object
发送视频消息 { “touser”:“OPENID”, “msgtype”:“video”, “video”: { “media_id”:“MEDIA_ID” } }.
-
#send_voice_custom(to_user, media_id) ⇒ Object
发送语音消息 { “touser”:“OPENID”, “msgtype”:“voice”, “voice”: { “media_id”:“MEDIA_ID” } }.
Instance Method Details
#create_kf_session(account, open_id, text) ⇒ Object
154 155 156 157 158 159 160 161 |
# File 'lib/weixin_authorize/api/custom.rb', line 154 def create_kf_session(account, open_id, text) post_body = { kf_account: account, openid: open_id, text: text } http_post(KF_SESSION_URL, post_body, {}, CUSTOM_ENDPOINT) end |
#get_custom_msg_record(start_time, end_time, options = {}) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/weixin_authorize/api/custom.rb', line 133 def get_custom_msg_record(start_time, end_time, ={}) start_time, end_time = start_time.to_i, end_time.to_i page_index = [:page_index] || 1 page_size = [:page_size] || 50 option = { endtime: end_time, starttime: start_time, pageindex: page_index, pagesize: page_size } http_post(CUSTOM_RECORD_URL, option, {}, CUSTOM_ENDPOINT) end |
#send_image_custom(to_user, media_id) ⇒ Object
发送图片消息{
"touser":"OPENID",
"msgtype":"image",
"image":
{
"media_id":"MEDIA_ID"
}
}
31 32 33 34 |
# File 'lib/weixin_authorize/api/custom.rb', line 31 def send_image_custom(to_user, media_id) = (to_user, "image").merge({image: {media_id: media_id}}) http_post(custom_base_url, ) end |
#send_mpnews_custom(to_user, media_id, options = {}) ⇒ Object
根据media_id发送图文消息{
"touser":"OPENID",
"msgtype":"mpnews",
"mpnews":
{
"media_id":"MEDIA_ID"
}
}
74 75 76 77 78 |
# File 'lib/weixin_authorize/api/custom.rb', line 74 def send_mpnews_custom(to_user, media_id, ={}) = {media_id: media_id}.merge() = (to_user, "mpnews").merge({mpnews: }) http_post(custom_base_url, ) end |
#send_music_custom(to_user, media_id, musicurl, hqmusicurl, options = {}) ⇒ Object
发送音乐消息{
"touser":"OPENID",
"msgtype":"music",
"music":
{
"title":"MUSIC_TITLE",
"description":"MUSIC_DESCRIPTION",
"musicurl":"MUSIC_URL",
"hqmusicurl":"HQ_MUSIC_URL",
"thumb_media_id":"THUMB_MEDIA_ID"
}
}
93 94 95 96 97 98 99 100 |
# File 'lib/weixin_authorize/api/custom.rb', line 93 def send_music_custom(to_user, media_id, musicurl, hqmusicurl, ={}) = { thumb_media_id: media_id, musicurl: musicurl, hqmusicurl: hqmusicurl }.merge() = (to_user, "music").merge({music: }) http_post(custom_base_url, ) end |
#send_news_custom(to_user, articles = []) ⇒ Object
发送图文消息{
"touser":"OPENID",
"msgtype":"news",
"news":{
"articles": [
{
"title":"Happy Day",
"description":"Is Really A Happy Day",
"url":"URL",
"picurl":"PIC_URL"
},
{
"title":"Happy Day",
"description":"Is Really A Happy Day",
"url":"URL",
"picurl":"PIC_URL"
}
]
}
}
123 124 125 126 |
# File 'lib/weixin_authorize/api/custom.rb', line 123 def send_news_custom(to_user, articles=[]) = (to_user, "news").merge({news: {articles: articles}}) http_post(custom_base_url, ) end |
#send_text_custom(to_user, content) ⇒ Object
发送文本消息{
"touser":"OPENID",
"msgtype":"text",
"text":
{
"content":"Hello World"
}
}
17 18 19 20 |
# File 'lib/weixin_authorize/api/custom.rb', line 17 def send_text_custom(to_user, content) = (to_user).merge({text: {content: content}}) http_post(custom_base_url, ) end |
#send_video_custom(to_user, media_id, options = {}) ⇒ Object
发送视频消息{
"touser":"OPENID",
"msgtype":"video",
"video":
{
"media_id":"MEDIA_ID"
}
}
59 60 61 62 63 |
# File 'lib/weixin_authorize/api/custom.rb', line 59 def send_video_custom(to_user, media_id, ={}) = {media_id: media_id}.merge() = (to_user, "video").merge({video: }) http_post(custom_base_url, ) end |
#send_voice_custom(to_user, media_id) ⇒ Object
发送语音消息{
"touser":"OPENID",
"msgtype":"voice",
"voice":
{
"media_id":"MEDIA_ID"
}
}
45 46 47 48 |
# File 'lib/weixin_authorize/api/custom.rb', line 45 def send_voice_custom(to_user, media_id) = (to_user, "voice").merge({voice: {media_id: media_id}}) http_post(custom_base_url, ) end |