Index.php
5.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
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
{
protected $noNeedLogin = '*';
protected $noNeedRight = '*';
protected $layout = '';
public function index()
{
return $this->view->fetch();
}
public function news()
{
$newslist = [];
return jsonp(['newslist' => $newslist, 'new' => count($newslist), 'url' => 'https://www.fastadmin.net?ref=news']);
}
// 融云创建用户、群组
public function test() {
$user_ids = '3,4';
$config = config('rongyun.config'); // 应用配置参数
$RongSDK = new RongCloud($config['appkey'],$config['appsecret']);
$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 = config('rongyun.config');
$RongSDK = new RongCloud($config['appkey'],$config['appsecret']);
$Group = $RongSDK->getGroup();
$params = [
'id'=> 'xiaowei_group1',//群组 id
'name'=> 'xiaowei_group1',//群组名称
'members'=>[ //群成员 列表
['id'=> 'xiaowei_master']
]
];
Utils::dump("创建群组成功",$Group->create($params));
}
// 群组用户禁言
public function group_dump_add() {
// 应用配置参数
$config = config('rongyun.config');
$RongSDK = new RongCloud($config['appkey'],$config['appsecret']);
$Group = $RongSDK->getGroup()->Gag();
$params = [
'id'=> 'xiaowei_group1',//群组 id
'members'=>[ //禁言人员列表
['id'=> 'xiaowei_master']
],
'minute'=>0 // 禁言时长
];
Utils::dump("添加群组禁言成功",$Group->add($params));
}
// 解除群组用户禁言
public function group_dump_remove() {
// 应用配置参数
$config = config('rongyun.config');
$RongSDK = new RongCloud($config['appkey'],$config['appsecret']);
$Group = $RongSDK->getGroup()->Gag();
$params = [
'id'=> 'xiaowei_group1',//群组 id
'members'=>[ //禁言人员列表
['id'=> 'xiaowei_master']
]
];
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');
}
}
public function callback() {
$param = $this->request->param();
Log::write(date('Y-m-d H:i') . '成功,返回结果:' . json_encode($param, JSON_UNESCAPED_UNICODE), 'rongyun_msg');
return json_encode(['code'=>200,'msg'=>'成功']);exit;
}
}