259 lines
8.0 KiB
PHP
259 lines
8.0 KiB
PHP
<?php
|
|
|
|
namespace app\api\model;
|
|
|
|
use think\Db;
|
|
use think\Model;
|
|
use RongCloud;
|
|
|
|
class Rongyun extends Model
|
|
{
|
|
|
|
//融云
|
|
protected function reg_rongyun($type, $ry_uid, $nickname = '', $headimg = '')
|
|
{
|
|
|
|
$config = model('admin/Config')->get_system_config();
|
|
$AppKey = $config['ry_app_key'];
|
|
$AppSecret = $config['ry_app_secret'];
|
|
$RongSDK = new \RongCloud\RongCloud($AppKey, $AppSecret);
|
|
$user = [
|
|
'id' => $ry_uid,
|
|
'name' => $nickname, //用户名称
|
|
'portrait' => $headimg //用户头像
|
|
];
|
|
if ($type == 1) {
|
|
$res = $RongSDK->getUser()->register($user);
|
|
} elseif ($type == 2) {
|
|
$res = $RongSDK->getUser()->register($user);
|
|
} else {
|
|
return ['code' => 0, 'info' => 'not found type'];
|
|
}
|
|
|
|
return $res;
|
|
}
|
|
|
|
//获取融云黑名单
|
|
public function get_blacklist($uid){
|
|
$reslut = $this->reg_blacklist($uid);
|
|
$map = [];
|
|
$map[] = ['uid', 'in', $reslut['users']];
|
|
$user_info = db::name('user')->field('uid,base64_nick_name,head_pic')->where($map)->select();
|
|
foreach ($user_info as $k => &$v) {
|
|
$v['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
|
|
$v['head_pic'] = localpath_to_netpath($v['head_pic']);
|
|
}
|
|
if($reslut['code'] == 200){
|
|
return ['code' => 200, 'msg' => '获取成功', 'data' => $user_info];
|
|
}else{
|
|
return ['code' => 201, 'msg' => '获取失败', 'data' => null];
|
|
}
|
|
}
|
|
|
|
//添加融云黑名单
|
|
public function add_blacklist($uid,$user_id){
|
|
$user_id = explode(',',$user_id);
|
|
$reslut = $this->reg_add_blacklist($uid,$user_id);
|
|
if($reslut['code'] == 200){
|
|
return ['code' => 200, 'msg' => '添加成功', 'data' => null];
|
|
}else{
|
|
return ['code' => 201, 'msg' => '添加失败', 'data' => null];
|
|
}
|
|
}
|
|
|
|
//删除融云黑名单
|
|
public function remove_blacklist($uid,$user_id){
|
|
$user_id = explode(',',$user_id);
|
|
$reslut = $this->reg_remove_blacklist($uid,$user_id);
|
|
if($reslut['code'] == 200){
|
|
return ['code' => 200, 'msg' => '移除成功', 'data' => null];
|
|
}else{
|
|
return ['code' => 201, 'msg' => '移除失败', 'data' => null];
|
|
}
|
|
}
|
|
|
|
//获取黑名单
|
|
public function blacklist($uid){
|
|
$reslut = $this->reg_blacklist($uid);
|
|
if($reslut['code'] == 200){
|
|
return ['code' => 200, 'msg' => '获取成功', 'data' => $reslut['users']];
|
|
}else{
|
|
return ['code' => 201, 'msg' => '获取失败', 'data' => null];
|
|
}
|
|
}
|
|
|
|
//融云查询黑名单
|
|
protected function reg_blacklist($uid){
|
|
$config = model('admin/Config')->get_system_config();
|
|
$AppKey = $config['ry_app_key'];
|
|
$AppSecret = $config['ry_app_secret'];
|
|
$RongSDK = new \RongCloud\RongCloud($AppKey, $AppSecret);
|
|
$user = [
|
|
'id' => $uid
|
|
];
|
|
|
|
if($uid){
|
|
$res = $RongSDK->getUser()->Blacklist()->getList($user);
|
|
}else{
|
|
return ['code' => 0, 'info' => 'not found uid'];
|
|
}
|
|
|
|
return $res;
|
|
}
|
|
|
|
//融云添加用户黑名单
|
|
protected function reg_add_blacklist($uid,$user_id){
|
|
$config = model('admin/Config')->get_system_config();
|
|
$AppKey = $config['ry_app_key'];
|
|
$AppSecret = $config['ry_app_secret'];
|
|
$RongSDK = new \RongCloud\RongCloud($AppKey, $AppSecret);
|
|
$user = [
|
|
'id' => $uid,
|
|
'blacklist' => $user_id
|
|
];
|
|
|
|
if($uid){
|
|
$res = $RongSDK->getUser()->Blacklist()->add($user);
|
|
}else{
|
|
return ['code' => 0, 'info' => 'not found uid'];
|
|
}
|
|
return $res;
|
|
}
|
|
|
|
//融云添加用户黑名单
|
|
protected function reg_remove_blacklist($uid,$user_id){
|
|
$config = model('admin/Config')->get_system_config();
|
|
$AppKey = $config['ry_app_key'];
|
|
$AppSecret = $config['ry_app_secret'];
|
|
$RongSDK = new \RongCloud\RongCloud($AppKey, $AppSecret);
|
|
$user = [
|
|
'id' => $uid,
|
|
'blacklist' => $user_id
|
|
];
|
|
|
|
if($uid){
|
|
$res = $RongSDK->getUser()->Blacklist()->remove($user);
|
|
}else{
|
|
return ['code' => 0, 'info' => 'not found uid'];
|
|
}
|
|
return $res;
|
|
}
|
|
|
|
/*
|
|
//融云 检查用户在线状态
|
|
public function checkOnline($id)
|
|
{
|
|
|
|
die();
|
|
$user = [
|
|
'id' => $id
|
|
];
|
|
require_once Env::get('root_path') . "/vendor/RongCloud/RongCloud.php";
|
|
$config = model('admin/Config')->get_system_config();
|
|
$AppKey = $config['ry_app_key'];
|
|
$AppSecret = $config['ry_app_secret'];
|
|
$RongSDK = new \RongCloud\RongCloud($AppKey, $AppSecret);
|
|
$result = $RongSDK->checkuser()->check($user);
|
|
// $update = $RongSDK->getUser()->update($user);
|
|
// $res = $RongSDK->getUser()->MuteGroups()->getList(['test1']);
|
|
return $res;
|
|
}
|
|
*/
|
|
|
|
//创建融云群组
|
|
public function create_rongyun_group(){
|
|
$config = model('admin/Config')->get_system_config();
|
|
$AppKey = $config['ry_app_key'];
|
|
$AppSecret = $config['ry_app_secret'];
|
|
$RongSDK = new \RongCloud\RongCloud($AppKey, $AppSecret);
|
|
|
|
$group = [
|
|
'id'=> '7777',//群组 id
|
|
'name'=> 'admin',//群组名称
|
|
'members'=>[ //群成员 列表
|
|
['id'=> '9999']
|
|
// ['id'=> 'uPj70HUrRSUk-ixtt7iIGc'],['id'=>'Vu-oC0_LQ6kgPqltm_zYtI']
|
|
]
|
|
];
|
|
|
|
$res = $RongSDK->getGroup()->create($group);
|
|
|
|
return $res;
|
|
}
|
|
|
|
//获取融云群组信息
|
|
public function get_rongyun_group(){
|
|
$config = model('admin/Config')->get_system_config();
|
|
$AppKey = $config['ry_app_key'];
|
|
$AppSecret = $config['ry_app_secret'];
|
|
$RongSDK = new \RongCloud\RongCloud($AppKey, $AppSecret);
|
|
|
|
$group = [
|
|
'id'=> '7777',//群组 id
|
|
];
|
|
|
|
$res = $RongSDK->getGroup()->get($group);
|
|
|
|
return $res;
|
|
}
|
|
|
|
//加入融云群组
|
|
public function join_rongyun_group($uid){
|
|
$config = model('admin/Config')->get_system_config();
|
|
$AppKey = $config['ry_app_key'];
|
|
$AppSecret = $config['ry_app_secret'];
|
|
$RongSDK = new \RongCloud\RongCloud($AppKey, $AppSecret);
|
|
|
|
$group = [
|
|
'id'=> '7777',//群组 id
|
|
'name'=> "admin",//群组名称
|
|
'member'=>['id'=> $uid],//群成员信息
|
|
];
|
|
|
|
if($uid){
|
|
$res = $RongSDK->getGroup()->joins($group);
|
|
}else{
|
|
return ['code' => 0, 'info' => 'not found uid'];
|
|
}
|
|
return $res;
|
|
}
|
|
|
|
//退出群组
|
|
public function quit_rongyun_group($uid){
|
|
$config = model('admin/Config')->get_system_config();
|
|
$AppKey = $config['ry_app_key'];
|
|
$AppSecret = $config['ry_app_secret'];
|
|
$RongSDK = new \RongCloud\RongCloud($AppKey, $AppSecret);
|
|
|
|
$group = [
|
|
'id'=> '7777',//群组 id
|
|
'member'=>['id'=> $uid],//群成员信息
|
|
];
|
|
|
|
if($uid){
|
|
$res = $RongSDK->getGroup()->quit($group);
|
|
}else{
|
|
return ['code' => 0, 'info' => 'not found uid'];
|
|
}
|
|
return $res;
|
|
}
|
|
|
|
//解散融云群组
|
|
public function dismiss_rongyun_group(){
|
|
$config = model('admin/Config')->get_system_config();
|
|
$AppKey = $config['ry_app_key'];
|
|
$AppSecret = $config['ry_app_secret'];
|
|
$RongSDK = new \RongCloud\RongCloud($AppKey, $AppSecret);
|
|
|
|
$group = [
|
|
'id'=> '7777',//群组 id
|
|
'member'=>['id'=> '9999']//管理员信息
|
|
];
|
|
|
|
$res = $RongSDK->getGroup()->dismiss($group);
|
|
|
|
return $res;
|
|
}
|
|
|
|
}
|