module WeixinAuthorize::Api::Custom
Constants
- CUSTOM_RECORD_URL
官方示例:{endtime: 1439571890, pageindex: 1, pagesize: 10, starttime: 1438707864} options: page_index: 查询第几页,从1开始 page_size: 每页大小,每页最多拉取50条
- CUSTOM_SERVICE
- KF_SESSION_URL
客服接口创建会话 POST数据示例如下:
{ "kf_account" : "test1@test", "openid" : "OPENID", "text" : "这是一段附加信息" }
Public Instance Methods
create_kf_session(account, open_id, text)
click to toggle source
# 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={})
click to toggle source
# File lib/weixin_authorize/api/custom.rb, line 133 def get_custom_msg_record(start_time, end_time, options={}) start_time, end_time = start_time.to_i, end_time.to_i page_index = options[:page_index] || 1 page_size = options[: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)
click to toggle source
发送图片消息 {
"touser":"OPENID", "msgtype":"image", "image": { "media_id":"MEDIA_ID" }
}
# File lib/weixin_authorize/api/custom.rb, line 31 def send_image_custom(to_user, media_id) message = default_options(to_user, "image").merge({image: {media_id: media_id}}) http_post(custom_base_url, message) end
send_mpnews_custom(to_user, media_id, options={})
click to toggle source
根据media_id发送图文消息 {
"touser":"OPENID", "msgtype":"mpnews", "mpnews": { "media_id":"MEDIA_ID" }
}
# File lib/weixin_authorize/api/custom.rb, line 74 def send_mpnews_custom(to_user, media_id, options={}) mpnews_options = {media_id: media_id}.merge(options) message = default_options(to_user, "mpnews").merge({mpnews: mpnews_options}) http_post(custom_base_url, message) end
send_music_custom(to_user, media_id, musicurl, hqmusicurl, options={})
click to toggle source
发送音乐消息 {
"touser":"OPENID", "msgtype":"music", "music": { "title":"MUSIC_TITLE", "description":"MUSIC_DESCRIPTION", "musicurl":"MUSIC_URL", "hqmusicurl":"HQ_MUSIC_URL", "thumb_media_id":"THUMB_MEDIA_ID" }
}
# File lib/weixin_authorize/api/custom.rb, line 93 def send_music_custom(to_user, media_id, musicurl, hqmusicurl, options={}) music_options = { thumb_media_id: media_id, musicurl: musicurl, hqmusicurl: hqmusicurl }.merge(options) message = default_options(to_user, "music").merge({music: music_options}) http_post(custom_base_url, message) end
send_news_custom(to_user, articles=[])
click to toggle source
发送图文消息 {
"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" } ] }
}
# File lib/weixin_authorize/api/custom.rb, line 123 def send_news_custom(to_user, articles=[]) message = default_options(to_user, "news").merge({news: {articles: articles}}) http_post(custom_base_url, message) end
send_text_custom(to_user, content)
click to toggle source
发送文本消息 {
"touser":"OPENID", "msgtype":"text", "text": { "content":"Hello World" }
}
# File lib/weixin_authorize/api/custom.rb, line 17 def send_text_custom(to_user, content) message = default_options(to_user).merge({text: {content: content}}) http_post(custom_base_url, message) end
send_video_custom(to_user, media_id, options={})
click to toggle source
发送视频消息 {
"touser":"OPENID", "msgtype":"video", "video": { "media_id":"MEDIA_ID" }
}
# File lib/weixin_authorize/api/custom.rb, line 59 def send_video_custom(to_user, media_id, options={}) video_options = {media_id: media_id}.merge(options) message = default_options(to_user, "video").merge({video: video_options}) http_post(custom_base_url, message) end
send_voice_custom(to_user, media_id)
click to toggle source
发送语音消息 {
"touser":"OPENID", "msgtype":"voice", "voice": { "media_id":"MEDIA_ID" }
}
# File lib/weixin_authorize/api/custom.rb, line 45 def send_voice_custom(to_user, media_id) message = default_options(to_user, "voice").merge({voice: {media_id: media_id}}) http_post(custom_base_url, message) end
Private Instance Methods
custom_base_url()
click to toggle source
api.weixin.qq.com/cgi-bin/message/custom/send?access_token=ACCESS_TOKEN
# File lib/weixin_authorize/api/custom.rb, line 166 def custom_base_url "/message/custom/send" end
default_options(to_user, msgtype="text")
click to toggle source
# File lib/weixin_authorize/api/custom.rb, line 170 def default_options(to_user, msgtype="text") {touser: to_user, msgtype: msgtype} end