Beispiel #1
0
 public function run($fid, $start = 0, $size = 5)
 {
     $this->controller->pageTitle = 'Messages';
     $this->controller->bodyCss = 'messageshow';
     //检查是否已互为好友并将消息全部置为已读
     EasemobHelper::addAFriend($fid);
     EasemobHelper::readAll($fid);
     //在页面上倒序添加到dom中即使得聊天记录按时间顺序正确显示
     $data = EasemobHelper::getAllMessage($fid, $start, $size);
     if (Yii::app()->request->isAjaxRequest) {
         // $list = array_map(function($record){return $record->attributes;}, $data['data']);
         // $list = (array)$data['data'];
         // $list = json_decode(CJSON::encode($data['data']), true);
         // $user = $data['user']->attributes;
         echo CJSON::encode(array('code' => 200, 'data' => array('list' => array_reverse($data['data']), 'user' => $data['user'])));
     } else {
         $friend = User::model()->findByPk($fid);
         $friendDetail = Yii::app()->db->createCommand('select b.name as companyName,a.title,c.name as locationName from user a left join company b on a.company=b.id left join hub c on c.id=a.location where a.status!=0 and a.id=' . $fid)->queryRow();
         $data['friendCompany'] = $friendDetail['companyName'];
         $data['friendTitle'] = $friendDetail['title'];
         $data['friendLocation'] = $friendDetail['locationName'];
         $data['friendId'] = $fid;
         $data['fportrait'] = $friend ? $friend->portrait : '';
         $this->controller->render('show', $data);
     }
 }
Beispiel #2
0
 public static function getInstance($options = array())
 {
     if (!self::$_instance instanceof self) {
         self::$_instance = new self($options);
     }
     return self::$_instance;
 }
Beispiel #3
0
 public function run()
 {
     if (Yii::app()->request->isAjaxRequest) {
         echo CJSON::encode(array('code' => 200, 'data' => EasemobHelper::hasNewMessage()));
     } else {
         throw new CHttpException('403', '请求格式错误!');
     }
 }
Beispiel #4
0
 public function run($fid)
 {
     if (Yii::app()->request->isAjaxRequest) {
         EasemobHelper::addMessage(Yii::app()->user->id, $fid, Yii::app()->request->getParam('content'));
         echo CJSON::encode(array('code' => 200, 'data' => true));
     } else {
         throw new CHttpException('403', '请求格式错误!');
     }
 }
Beispiel #5
0
 public function run($fid)
 {
     if (Yii::app()->request->isAjaxRequest) {
         EasemobHelper::getInstance()->addFriend(Yii::app()->user->id, $fid);
         echo CJSON::encode(array('code' => 200, 'data' => true));
     } else {
         throw new CHttpException('403', '请求格式错误!');
     }
 }
 public function run()
 {
     if (Yii::app()->request->isAjaxRequest) {
         try {
             $name = Yii::app()->request->getParam('name');
             $mobile = Yii::app()->request->getParam('mobile');
             $code = Yii::app()->request->getParam('code');
             $email = Yii::app()->request->getParam('email');
             $password = Yii::app()->request->getParam('password');
             $_code = Yii::app()->session['regist_code' . $mobile];
             if ($_code && $_code == $code) {
                 $item = Yii::app()->db->createCommand('select * from user where mobile=' . $mobile . ' and status=0')->queryRow();
                 if (!$item) {
                     $user = new User();
                     $user->nickName = $name;
                     $user->mobile = $mobile;
                     $user->email = $email;
                     $user->status = 0;
                     if ($password) {
                         $user->password = md5($password);
                     }
                     $wechat = Yii::app()->session['wechat'];
                     if ($wechat) {
                         // $user->nickName = $wechat['nickname'];
                         $user->portrait = $wechat['headimgurl'];
                         $user->gender = $wechat['sex'];
                     }
                     $user->insert();
                     //消息系统初始化
                     EasemobHelper::initIM($user->id, array('username' => $user->id, 'password' => 'nakedim', 'nickname' => $name));
                     $user->isBindIM = 1;
                     $user->type = 3;
                     $user->save();
                     Yii::app()->session['user'] = $user;
                 } else {
                     Yii::log(print_r($item, 1), CLogger::LEVEL_ERROR, 'info');
                     Yii::app()->session['user'] = $item;
                 }
                 //如果用户注册过了,没付款不生成新的用户,读取数据库里的用户信息
                 // $identity = new UserIdentity();
                 // $identity->registAuth($user);
                 // $duration = Yii::app()->getComponent('session')->getTimeout();
                 // Yii::app()->user->login($identity, $duration);
                 echo CJSON::encode(array('code' => 200, 'message' => 'success'));
             } else {
                 echo CJSON::encode(array('code' => 500, 'message' => '验证码错误'));
             }
         } catch (CException $e) {
             Yii::log($e->getMessage(), CLogger::LEVEL_ERROR);
             echo CJSON::encode(array('code' => 500, 'message' => '注册失败'));
         }
     }
 }
Beispiel #7
0
 public function run($page = 1, $size = 15)
 {
     $this->controller->pageTitle = "Messages";
     $this->controller->bodyCss = 'messagelist';
     //检查user->isBindIM如未绑定环信则注册环信并绑定
     if (!Yii::app()->user->isBindIM) {
         EasemobHelper::initIM(Yii::app()->user->id, array('username' => Yii::app()->user->id, 'password' => 'nakedim', 'nickname' => Yii::app()->user->nickName));
         Yii::app()->user->isBindIM = 1;
         User::model()->updateByPk(Yii::app()->user->id, array('isBindIM' => 1));
     }
     $data = EasemobHelper::getAll($page, $size);
     if (Yii::app()->request->isAjaxRequest) {
         echo CJSON::encode(array('code' => 200, 'data' => array('list' => $data)));
     } else {
         $this->controller->render('index', array('data' => $data));
     }
 }