/** * chat handler, keys: show, send | params: message * @param string $key * @param mixed $params * @return mixed * */ function chatHandler($key, $params) { $var = null; switch ($key) { case 'show': $var = getChatHistory($_SESSION['chat']); break; case 'send': //$username = getUsername(); $var = sendChat($_SESSION['user'], $params); break; default: break; } return $var; }
function showChat() { $users = getJsonFromFile('users.json'); if (isset($users->{$_SESSION}['user']->chat)) { $_SESSION['status'] = 2; $_SESSION['chat'] = $users->{$_SESSION}['user']->chat; return getChatHistory($_SESSION['chat']); } return false; }
$signature_ts = time(); $str = sprintf('%s:%s:%s:%s:%s', APPID, $peerid, $convid, $nonce, $signature_ts); $signature = sha1sign($str); $param = array('convid' => $convid, 'peerid' => $peerid, 'nonce' => $nonce, 'signature_ts' => $signature_ts, 'signature' => $signature, 'limit' => 10); $url = 'https://leancloud.cn/1.1/rtm/messages/logs?' . http_build_query($param); // $url = 'https://leancloud.cn/1.1/rtm/messages/logs?convid=552119bbe4b043f1c84c0b7a'; $chatHistory = sendRequest($url, 'GET', $param); header("Content-Type: application/json; charset=utf-8"); return json_decode($chatHistory, 1); } $a = queryConv(); if (empty($a["results"])) { die("no conversation found"); } foreach ($a["results"] as $v) { if (!empty($v["objectId"])) { echo $v["objectId"]; } } header("Content-Type: application/json; charset=utf-8"); //echo json_encode($a); //sendMessage (); header("Content-Type: application/json; charset=utf-8"); // createUpdateInfo(); //$his = getChatHistory (); $from = $_GET['from']; $to = $_GET['to']; $his = getChatHistory($from, $to); echo json_encode($his); //pushMessageToUserName ( '2dong' ); //userReg();
startChatSession(); } if ($_GET['action'] == "logoutfromchat") { logoutFromChat(); } if ($_GET['action'] == "logintochat") { loginToChat(); } if ($_GET['action'] == "getchatheartbeat") { getChatHeartbeat(); } if ($_GET['action'] == "getrefreshrate") { getRefresh_rate(); } if ($_GET['action'] == "getchathistory") { getChatHistory(); } function getChatHeartbeat() { $rate = eF_getTableData("module_chat_config", "chatHeartbeatTime", "1"); foreach ($rate as $r) { echo $r['chatHeartbeatTime']; } } function getRefresh_rate() { $rate = eF_getTableData("module_chat_config", "refresh_rate", "1"); foreach ($rate as $r) { echo $r['refresh_rate']; } }