Commit 1afe8f3b by lanrion

添加获取客服聊天记录接口

parent 1e7e29a7
...@@ -25,6 +25,7 @@ Support using [Redis](http://redis.io) to store `access_token` ...@@ -25,6 +25,7 @@ Support using [Redis](http://redis.io) to store `access_token`
* 群发消息 * 群发消息
* 多媒体管理 * 多媒体管理
* JS SDK(ticket支持缓存) * JS SDK(ticket支持缓存)
* 更多请查看测试例子
## V2.0开发中: ## V2.0开发中:
https://github.com/lanrion/weixin_authorize/milestones/v2.0-dev https://github.com/lanrion/weixin_authorize/milestones/v2.0-dev
......
...@@ -27,9 +27,12 @@ module WeixinAuthorize ...@@ -27,9 +27,12 @@ module WeixinAuthorize
autoload(:RedisStore, "weixin_authorize/js_ticket/redis_store") autoload(:RedisStore, "weixin_authorize/js_ticket/redis_store")
end end
OK_MSG = "ok" OK_MSG = "ok".freeze
OK_CODE = 0 OK_CODE = 0.freeze
GRANT_TYPE = "client_credential" GRANT_TYPE = "client_credential".freeze
# 用于标记endpoint可以直接使用url作为完整请求API
CUSTOM_ENDPOINT = "custom_endpoint".freeze
class << self class << self
...@@ -40,7 +43,10 @@ module WeixinAuthorize ...@@ -40,7 +43,10 @@ module WeixinAuthorize
def http_post_without_token(url, payload={}, headers={}, endpoint="plain") def http_post_without_token(url, payload={}, headers={}, endpoint="plain")
post_api_url = endpoint_url(endpoint, url) post_api_url = endpoint_url(endpoint, url)
payload = JSON.dump(payload) if endpoint == "plain" # to json if invoke "plain" # to json if invoke "plain"
if endpoint == "plain" || endpoint == CUSTOM_ENDPOINT
payload = JSON.dump(payload)
end
load_json(resource(post_api_url).post(payload, params: headers)) load_json(resource(post_api_url).post(payload, params: headers))
end end
...@@ -57,6 +63,8 @@ module WeixinAuthorize ...@@ -57,6 +63,8 @@ module WeixinAuthorize
end end
def endpoint_url(endpoint, url) def endpoint_url(endpoint, url)
# 此处为了应对第三方开发者如果自助对接接口时,URL不规范的情况下,可以直接使用URL当为endpoint
return url if endpoint == CUSTOM_ENDPOINT
send("#{endpoint}_endpoint") + url send("#{endpoint}_endpoint") + url
end end
......
...@@ -108,6 +108,24 @@ module WeixinAuthorize ...@@ -108,6 +108,24 @@ module WeixinAuthorize
http_post(custom_base_url, message) http_post(custom_base_url, message)
end end
# 官方示例:{endtime: 1439571890, pageindex: 1, pagesize: 10, starttime: 1438707864}
# options:
# page_index: 查询第几页,从1开始
# page_size: 每页大小,每页最多拉取50条
CUSTOM_RECORD_URL = "https://api.weixin.qq.com/customservice/msgrecord/getrecord".freeze
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, {}, WeixinAuthorize::CUSTOM_ENDPOINT)
end
private private
# https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=ACCESS_TOKEN # https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=ACCESS_TOKEN
......
...@@ -52,4 +52,11 @@ describe WeixinAuthorize::Api::Custom do ...@@ -52,4 +52,11 @@ describe WeixinAuthorize::Api::Custom do
pending("The test must have a media_id") pending("The test must have a media_id")
end end
it "#get_custom_msg_record" do
option = {pageindex: 1, pagesize: 10}
response = $client.get_custom_msg_record(Time.now - 10.days, Time.now, option)
expect(response.code).to eq(WeixinAuthorize::OK_CODE)
expect(response.result.keys).to eq(["recordlist", "retcode"])
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