uid = 2; } } private function connect() { Gateway::$registerAddress = 'dl.shemic.com:1238'; } # 初始化,绑定client_id public function init() { $this->connect(); $client_id = Dever::input('client_id'); if ($client_id) { Gateway::bindUid($client_id, $this->uid); } return 'ok'; } # 加入分组 public function joinGroup() { } # 发送消息 public function send() { $uid = Dever::input('uid'); $msg = Dever::input('msg'); $pic = Dever::input('pic'); if (!$uid || $uid == $this->uid) { Dever::alert('你要发给谁?'); } if (!$msg && !$pic) { Dever::alert('没有任何消息'); } Dever::load('community/lib/chat')->add($this->uid, $uid, $this->id, $msg, $pic, $this->day); $this->connect(); # 谁发给谁,发的什么 $this->push($this->uid, $uid, $msg, $pic); $data['msg'] = $this->msg($this->uid, $this->uid, $msg, $pic); return $data; } # 获取聊天记录 public function getList() { $uid = Dever::input('uid'); if (!$uid || $uid == $this->uid) { Dever::alert('你要发给谁?'); } $data = Dever::load('community/lib/chat')->getInfo($this->uid, $uid, $this->id, $this->times); $info = $this->checkInfo(); if ($info) { $button = $this->button($info); $data['bgcolor'] = $button['bgcolor']; } return $data; } # 发送消息给用户 public function push($from_uid, $uid, $msg, $pic) { if (Gateway::isUidOnline($uid)) { $send = $this->msg($from_uid, $uid, $msg, $pic); $send = Dever::json_encode($send); Gateway::sendToUid($uid, $send); } return $this; } # 获取消息体 public function msg($from_uid, $uid, $msg, $pic) { $self = false; if ($from_uid == $uid) { $self = true; } $send = array(); $send['uid'] = $from_uid; $send['self'] = $self; $send['type'] = 'msg'; $send['text'] = $msg; $send['pic'] = $pic; $send['date'] = Dever::load('collection/lib/times')->getDate($this->day, time(), $this->times); return $send; } }