예제 #1
0
 /**
  * 自动创建接口ID
  * @param $module_id
  * @param $interface_key
  * @return int
  * @throws \Exception
  */
 private function getInterfaceId($module_id, $interface_key)
 {
     $interface_key = \Swoole\Filter::escape($interface_key);
     $table = 'interface';
     $params['select'] = "id";
     $params['name'] = $interface_key;
     $params['module_id'] = $module_id;
     $data = table($table)->gets($params);
     if (!empty($data)) {
         return $data[0]['id'];
     } else {
         $put['name'] = $interface_key;
         $put['alias'] = $interface_key;
         $put['module_id'] = $module_id;
         $put['create_host'] = $this->clientInfo['remote_ip'];
         return table($table)->put($put);
     }
 }
예제 #2
0
 function onReceive($serv, $fd, $thread_id, $data)
 {
     $info = $this->serv->connection_info($fd, $thread_id, true);
     $parts = explode("\n", $data, 2);
     $put = array();
     list($put['module'], $put['level'], $put['type'], $put['subtype'], $put['uid']) = explode("|", $parts[0]);
     $put['content'] = Filter::escape(rtrim($parts[1]));
     $put['hour'] = date('H');
     $put['ip'] = $info['remote_ip'];
     if (!is_numeric($put['uid'])) {
         $put['ukey'] = $put['uid'];
         $put['uid'] = 0;
     }
     $table = $this->getTableName();
     if (!table($table)->put($put) and \Swoole::$php->db->errno() == 1146) {
         $this->createTable($table);
         table($table)->put($put);
     }
     \Swoole::$php->redis->sAdd('logs2:client:' . $put['module'], $put['ip']);
     \Swoole::$php->redis->sAdd('logs2:type:' . $put['module'], $put['type']);
     \Swoole::$php->redis->sAdd('logs2:subtype:' . $put['module'], $put['subtype']);
 }
예제 #3
0
파일: Server.php 프로젝트: fyee/php-webim
 /**
  * 登录
  * @param $client_id
  * @param $msg
  */
 function cmd_login($client_id, $msg)
 {
     $info['name'] = Filter::escape($msg['name']);
     $info['avatar'] = Filter::escape($msg['avatar']);
     //回复给登录用户
     $resMsg = array('cmd' => 'login', 'fd' => $client_id, 'name' => $msg['name'], 'avatar' => $msg['avatar']);
     //把会话存起来
     $this->users[$client_id] = $resMsg;
     $this->store->login($client_id, $resMsg);
     $this->sendJson($client_id, $resMsg);
     //广播给其它在线用户
     $resMsg['cmd'] = 'newUser';
     //将上线消息发送给所有人
     $this->broadcastJson($client_id, $resMsg);
     //用户登录消息
     $loginMsg = array('cmd' => 'fromMsg', 'from' => 0, 'channal' => 0, 'data' => $msg['name'] . "上线了");
     $this->broadcastJson($client_id, $loginMsg);
 }