...
|
...
|
@@ -5,6 +5,8 @@ namespace app\index\controller; |
|
|
use app\common\controller\Frontend;
|
|
|
use RongCloud\Lib\Utils;
|
|
|
use RongCloud\RongCloud;
|
|
|
use think\Db;
|
|
|
use think\Log;
|
|
|
|
|
|
class Index extends Frontend
|
|
|
{
|
...
|
...
|
@@ -24,32 +26,57 @@ class Index extends Frontend |
|
|
return jsonp(['newslist' => $newslist, 'new' => count($newslist), 'url' => 'https://www.fastadmin.net?ref=news']);
|
|
|
}
|
|
|
|
|
|
// 融云创建用户
|
|
|
// 融云创建用户、群组
|
|
|
public function test() {
|
|
|
// 应用配置参数
|
|
|
$config = [
|
|
|
'appkey' => '3argexb63q3he',
|
|
|
'appsecret' => '1nb2RBxREmTICB',
|
|
|
];
|
|
|
$user_ids = '3,4';
|
|
|
$config = config('rongyun.config'); // 应用配置参数
|
|
|
$RongSDK = new RongCloud($config['appkey'],$config['appsecret']);
|
|
|
$portrait = "http://7xogjk.com1.z0.glb.clouddn.com/IuDkFprSQ1493563384017406982"; // 头像
|
|
|
$User = $RongSDK->getUser();
|
|
|
|
|
|
$params = [
|
|
|
'id'=> 'xiaowei_master',//用户id
|
|
|
'name'=> 'xiaowei_admin',//用户名称
|
|
|
'portrait'=> $portrait //用户头像
|
|
|
];
|
|
|
Utils::dump("用户注册成功",$User->register($params));
|
|
|
$users = Db::name('user')->whereIn('id',$user_ids)->column('id,nickname,avatar,rongyun_id,is_create'); // 获取用户信息
|
|
|
if($users) {
|
|
|
$user_rongyun_ids = [];
|
|
|
$User = $RongSDK->getUser();
|
|
|
foreach ($users as $k=>$v) {
|
|
|
$user_rongyun_ids[] = [
|
|
|
'id' => $v['rongyun_id']
|
|
|
];
|
|
|
if($v['is_create'] == 0) {
|
|
|
// 创建新用户
|
|
|
$portrait = $v['avatar']; // 头像
|
|
|
$user_params = [
|
|
|
'id'=> $v['rongyun_id'],//用户id
|
|
|
'name'=> $v['nickname'],//用户名称
|
|
|
'portrait'=> $portrait //用户头像
|
|
|
];
|
|
|
$user_return = $User->register($user_params);
|
|
|
if($user_return['code'] == 200) {
|
|
|
Db::name('user')->where('id',$v['id'])->update(['is_create'=>1,'rongyun_token'=>$user_return['token']]); // 融云账号状态更新为已创建
|
|
|
}
|
|
|
Log::write(date('Y-m-d H:i') . '用户注册成功,返回结果:' . json_encode($user_return, JSON_UNESCAPED_UNICODE), 'rongyun_log');
|
|
|
}
|
|
|
}
|
|
|
// 创建群组
|
|
|
$chat_id = '';
|
|
|
$chat_name = '';
|
|
|
$Group = $RongSDK->getGroup();
|
|
|
$group_params = [
|
|
|
'id'=> $chat_id,//群组 id
|
|
|
'name'=> $chat_name,//群组名称
|
|
|
'members'=> $user_rongyun_ids //群成员 列表
|
|
|
];
|
|
|
$group_return = $Group->create($group_params);
|
|
|
Log::write(date('Y-m-d H:i') . '创建群组成功,返回结果:' . json_encode($group_return, JSON_UNESCAPED_UNICODE), 'rongyun_log');
|
|
|
return [
|
|
|
'chat_id' => $chat_id,
|
|
|
'chat_name' => $chat_name
|
|
|
];
|
|
|
}
|
|
|
return [];
|
|
|
}
|
|
|
|
|
|
// 创建群组
|
|
|
public function group() {
|
|
|
// 应用配置参数
|
|
|
$config = [
|
|
|
'appkey' => '3argexb63q3he',
|
|
|
'appsecret' => '1nb2RBxREmTICB',
|
|
|
];
|
|
|
$config = config('rongyun.config');
|
|
|
$RongSDK = new RongCloud($config['appkey'],$config['appsecret']);
|
|
|
$Group = $RongSDK->getGroup();
|
|
|
|
...
|
...
|
@@ -66,10 +93,7 @@ class Index extends Frontend |
|
|
// 群组用户禁言
|
|
|
public function group_dump_add() {
|
|
|
// 应用配置参数
|
|
|
$config = [
|
|
|
'appkey' => '3argexb63q3he',
|
|
|
'appsecret' => '1nb2RBxREmTICB',
|
|
|
];
|
|
|
$config = config('rongyun.config');
|
|
|
$RongSDK = new RongCloud($config['appkey'],$config['appsecret']);
|
|
|
$Group = $RongSDK->getGroup()->Gag();
|
|
|
$params = [
|
...
|
...
|
@@ -85,10 +109,7 @@ class Index extends Frontend |
|
|
// 解除群组用户禁言
|
|
|
public function group_dump_remove() {
|
|
|
// 应用配置参数
|
|
|
$config = [
|
|
|
'appkey' => '3argexb63q3he',
|
|
|
'appsecret' => '1nb2RBxREmTICB',
|
|
|
];
|
|
|
$config = config('rongyun.config');
|
|
|
$RongSDK = new RongCloud($config['appkey'],$config['appsecret']);
|
|
|
$Group = $RongSDK->getGroup()->Gag();
|
|
|
$params = [
|
...
|
...
|
@@ -99,4 +120,21 @@ class Index extends Frontend |
|
|
];
|
|
|
Utils::dump("解除禁言成功",$Group->remove($params));
|
|
|
}
|
|
|
|
|
|
// 指定群组用户全部禁言
|
|
|
public function group_mute() {
|
|
|
// 应用配置参数
|
|
|
$config = config('rongyun.config');
|
|
|
$RongSDK = new RongCloud($config['appkey'],$config['appsecret']);
|
|
|
$time = time();
|
|
|
$orders = Db::name('order')->whereBetween('expirationtime',[$time-60,$time])->select(); // 查询已经过期的群聊
|
|
|
$Group = $RongSDK->getGroup()->MuteAllMembers();
|
|
|
foreach ($orders as $k=>$v) {
|
|
|
$params = [
|
|
|
'id'=> $v['chat_id'],//群组 id
|
|
|
];
|
|
|
$return = $Group->add($params);
|
|
|
Log::write(date('Y-m-d H:i') . '添加指定群组全部禁言成功,返回结果:' . json_encode($return, JSON_UNESCAPED_UNICODE), 'rongyun_log');
|
|
|
}
|
|
|
}
|
|
|
} |
...
|
...
|
|