# 服务端获取历史消息

# REST Host

香港: api.irealtime.cn

# RESTful API


URL: http(s)://<REST Host>/rest/history

Method:

  • POST

参数:

名称 必要 描述 默认值
appkey 您的 appkey
curPage 当前第几页 1
pageSize 一页多少条记录 10
start 开始时间
end 结束时间

返回值:


{
"code" : 200,
"content" : "OK"
}

# 调用方式

irealtime 支持以下方式调用 restful API

# PHP

$url = 'http(s)://<REST Host>/rest/history';

$your_appkey = 'c7ggg8yfvfk0....' //your appkey
$curPage = 1
$pageSize = 10
$start = '2020-10-1'
$end = '2021-2-1'
$post_data = array("appkey"=>$your_appkey,"curPage"=>$curPage,"pageSize"=>$pageSize,"start"=>$start,"end"=>$end);

echo php_ajax($url,$post_data);


function php_ajax($url, $post_data) {
  $postdata = http_build_query($post_data);
  $options = array(
    'http' => array(
      'method' => 'POST',
      'header' => 'Content-type:application/x-www-form-urlencoded',
      'content' => $postdata,
      'timeout' => 15 * 60
    )
  );
  $context = stream_context_create($options);
  $result = file_get_contents($url, false, $context);

  return $result;
}


# NodeJS

var http = require('http')

var appkey = 'Your appkey'
var curPage = 1
var pageSize = 10
var start = '2020-10-1'
var end = '2021-2-1'

var queryParams =
  'appkey=' +
  appkey +
  '&curPage=' +
  curPage +
  '&pageSize=' +
  pageSize +
  '&start=' +
  start +
  '&end=' +
  end

var options = {
  hostname: '<REST Host>',
  path: '/rest/history',
  method: 'POST',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded',
  },
}

var req = http.request(options, (res) => {
  res.setEncoding('utf8')
  res.on('data', (result) => {
    console.log(`响应结果: ${result}`)
  })
})

req.on('error', (e) => {
  console.error(e)
})

req.write(queryParams)
req.end()

# Python


appkey = "your_appkey"
curPage = 1
pageSize = 10
start = '2020-10-1'
end = '2021-2-1'

data = {"appkey" : appkey, "curPage" : curPage, "pageSize" : pageSize, "start" : start, "end" : end}
url = "http(s)://<REST Host>/rest/history"
response = requests.post(url, data = data)


# C#


string postDataStr = "appkey=your_appkey&curPage=curPage&pageSize=pageSize&start=start&end=end";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http(s)://<REST Host>/rest/history");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
request.ContentLength = Encoding.UTF8.GetByteCount(postDataStr);
Stream myRequestStream = request.GetRequestStream();
byte[] data = Encoding.UTF8.GetBytes(postDataStr);
myRequestStream.Write(data, 0, data.Length);

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream myResponseStream = response.GetResponseStream();
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
string retString = myStreamReader.ReadToEnd();
myStreamReader.Close();
myResponseStream.Close();

# Ruby


require 'net/http'

class Client
  def self.send(curPage, pageSize,start,_end)
    Thread.new {
      Net::HTTP.post_form(URI("http(s)://<REST Host>/rest/history"),
       {appkey: "your_appkey", curPage: curPage, pageSize: pageSize, start: start, end: _end})
    }
  end
end