Commit 8e717992 by lanrion

添加客服接口创建会话接口

parent cc783b25
...@@ -3,6 +3,8 @@ module WeixinAuthorize ...@@ -3,6 +3,8 @@ module WeixinAuthorize
module Api module Api
module Custom module Custom
CUSTOM_SERVICE = "https://api.weixin.qq.com/customservice".freeze
# 发送文本消息 # 发送文本消息
# { # {
# "touser":"OPENID", # "touser":"OPENID",
...@@ -112,7 +114,7 @@ module WeixinAuthorize ...@@ -112,7 +114,7 @@ module WeixinAuthorize
# options: # options:
# page_index: 查询第几页,从1开始 # page_index: 查询第几页,从1开始
# page_size: 每页大小,每页最多拉取50条 # page_size: 每页大小,每页最多拉取50条
CUSTOM_RECORD_URL = "https://api.weixin.qq.com/customservice/msgrecord/getrecord".freeze CUSTOM_RECORD_URL = "#{CUSTOM_SERVICE}/msgrecord/getrecord".freeze
def get_custom_msg_record(start_time, end_time, options={}) def get_custom_msg_record(start_time, end_time, options={})
start_time, end_time = start_time.to_i, end_time.to_i start_time, end_time = start_time.to_i, end_time.to_i
page_index = options[:page_index] || 1 page_index = options[:page_index] || 1
...@@ -123,7 +125,24 @@ module WeixinAuthorize ...@@ -123,7 +125,24 @@ module WeixinAuthorize
pageindex: page_index, pageindex: page_index,
pagesize: page_size pagesize: page_size
} }
http_post(CUSTOM_RECORD_URL, option, {}, WeixinAuthorize::CUSTOM_ENDPOINT) http_post(CUSTOM_RECORD_URL, option, {}, CUSTOM_ENDPOINT)
end
# 客服接口创建会话
# POST数据示例如下:
# {
# "kf_account" : "test1@test",
# "openid" : "OPENID",
# "text" : "这是一段附加信息"
# }
KF_SESSION_URL = "#{CUSTOM_SERVICE}/kfsession/create".freeze
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 end
private private
......
...@@ -59,4 +59,9 @@ describe WeixinAuthorize::Api::Custom do ...@@ -59,4 +59,9 @@ describe WeixinAuthorize::Api::Custom do
expect(response.result.keys).to eq(["recordlist", "retcode"]) expect(response.result.keys).to eq(["recordlist", "retcode"])
end end
it "#create_kf_session" do
response = $client.create_kf_session("test1@test", ENV["APPID"], "test kfsession")
expect(response.code).to eq(WeixinAuthorize::OK_CODE)
end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment