# 服务端获取在线状态

# REST Host

香港: api.irealtime.cn

# RESTful API


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

Method:

  • POST

参数:

名称 必要 描述
appkey 您的 appkey
channel channel

返回值:


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

# 调用方式

irealtime 支持以下方式调用 restful API

# PHP

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


$post_data = array("appkey"=>"your_appkey","channel"=>$channel);

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 channel = 'my_channel'

var queryParams = 'appkey=' + appkey + '&channel=' + channel

var options = {
  hostname: '<REST Host>',
  path: '/rest/online_users',
  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"
channel = "my_channel"
data = {"appkey" : appkey, "channel" : channel}
url = "http(s)://<REST Host>/rest/online_users"
response = requests.post(url, data = data)


# C#


string postDataStr = "appkey=your_appkey&channel=your_channel";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http(s)://<REST Host>/rest/online_users");
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(channel)
    Thread.new {
      Net::HTTP.post_form(URI("http(s)://<REST Host>/rest/online_users"),
       {appkey: "your_appkey", channel: channel})
    }
  end
end