DemoController
namespace Api\Controller;
use Think\Controller;
class DemoController extends Controller{
private $model;
private $AppKey = ''; // key
private $AppSecret = ''; // secret
public function _initialize(){
// 实例云信的库
$this->model = new \Org\Util\Netease($this->AppKey,$this->AppSecret,'curl');
}
/**
* 创建云信ID
*
*/
public function createUserId($userid)
{
$data = M('user')->field('id accid,username,nickname name,headimgurl icon')->where('is_del = 0 AND id='.$userid)->find();
$token = md5($data['accid'].'abc');
// 写入到云信服务器
$accid = 'abc'.$data['accid'];
$name = $data['name'];
$icon = $data['icon'];
$info = $this->model->createUserIds($accid,$name,'{}',$icon,$token);
return $info;
}
public function updateUinfos($accid,$name,$icon,$sign,$email,$birth,$mobile,$gender,$ex){
$info = $this->model->updateUinfo($accid,$name,$icon,$sign,$email,$birth,$mobile,$gender,$ex);
return $info;
}
// 获取指定用户的云信ID
public function getUinfos(){
$accid = I('request.id');
$accid = array($accid);
$info = $this->model->getUinfoss($accid);
print_r($info);
return $info;
}
// 创建聊天室
/**
* @param $accid 聊天室的ID
* @param $name 聊天室的名称
*/
public function chatroomCreate($accid,$name){
$info = $this->model->chatroomCreates($accid,$name);
return $info;
}
// 查询聊天室
public function chatroomget(){
$roomid = I('request.id');
$info = $this->model->chatroomgets($roomid);
print_r($info);
return $info;
}
/**
* 更新聊天室
* @param $roomid 聊天室ID
* @param $name 聊天室名称
* @return array
*/
public function chatroomUpdate($roomid,$name){
$info = $this->model->chatroomUpdates($roomid,$name);
return $info;
}
//Your Code ...
}