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

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(, open_id, text)
  post_body = {
    kf_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, 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) ⇒ 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)
  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 = {}) ⇒ 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, 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 = {}) ⇒ 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, 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 = []) ⇒ 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=[])
  message = default_options(to_user, "news").merge({news: {articles: articles}})
  http_post(custom_base_url, message)
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)
  message = default_options(to_user).merge({text: {content: content}})
  http_post(custom_base_url, message)
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, 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) ⇒ 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)
  message = default_options(to_user, "voice").merge({voice: {media_id: media_id}})
  http_post(custom_base_url, message)
end