|
@@ -3,6 +3,7 @@
|
|
|
namespace app\api\controller;
|
|
|
|
|
|
use app\common\controller\Api;
|
|
|
+use app\common\service\TenimService;
|
|
|
use think\Request;
|
|
|
use getusersig\getusersig;
|
|
|
use tencentim\tencentim;
|
|
@@ -14,7 +15,7 @@ use think\Db;
|
|
|
*/
|
|
|
class Tenim extends Api
|
|
|
{
|
|
|
- protected $noNeedLogin = ["callback",'test','createIMGroup','updateRoomInfo','setImManage','sendMessageToUser','outMemberFromRoom',
|
|
|
+ protected $noNeedLogin = ['trtc_callback',"callback",'test','createIMGroup','updateRoomInfo','setImManage','sendMessageToUser','outMemberFromRoom',
|
|
|
'autoUserLine','getRoomUser','getGroupList','getGroupInfo'];
|
|
|
protected $noNeedRight = ['*'];
|
|
|
|
|
@@ -199,7 +200,7 @@ exit;
|
|
|
$url .= "&contenttype=json";
|
|
|
$tencentObj = new tencentim($url);
|
|
|
$data = [];
|
|
|
- $data["GroupIdList"] = [$party_id];
|
|
|
+ $data["GroupIdList"] = [(string)$party_id];
|
|
|
$data["ResponseFilter"] = [
|
|
|
"GroupBaseInfoFilter" => ["GroupId","Type","Name","FaceUrl","Owner_Account","MemberNum"],
|
|
|
"MemberInfoFilter" => ["Account","Role"],
|
|
@@ -584,6 +585,151 @@ exit;
|
|
|
|
|
|
}
|
|
|
|
|
|
+ public function trtc_callback(){
|
|
|
+
|
|
|
+ $input = file_get_contents("php://input");
|
|
|
+ //filePut('start:'.$input,'callback.txt');
|
|
|
+
|
|
|
+ /*$input = '{
|
|
|
+ "EventGroupId": 1,
|
|
|
+ "EventType": 104,
|
|
|
+ "CallbackTs": 1640331295244,
|
|
|
+ "EventInfo": {
|
|
|
+ "RoomId": 140,
|
|
|
+ "EventTs": 1640331295,
|
|
|
+ "EventMsTs": 1640331295239,
|
|
|
+ "UserId": "179",
|
|
|
+ "Role": 21,
|
|
|
+ "Reason": 5
|
|
|
+ }
|
|
|
+ }';*/
|
|
|
+ $input = json_decode($input,true);
|
|
|
+ $roomId = $input['EventInfo']['RoomId'];
|
|
|
+ //房间事件组
|
|
|
+ if($input['EventGroupId'] == 1){
|
|
|
+ if($input['EventType'] == 101){
|
|
|
+ //创建房间,第一个进来的
|
|
|
+ }elseif($input['EventType'] == 102){
|
|
|
+ //解散房间,最后一个走的
|
|
|
+ //没有UserId
|
|
|
+ }elseif($input['EventType'] == 103){
|
|
|
+ //进入房间,主播role=20 观众role=21
|
|
|
+ $redis = new Redis();
|
|
|
+ $redisconfig = config("redis");
|
|
|
+ $redis->connect($redisconfig["host"], $redisconfig["port"]);
|
|
|
+ if ($redisconfig['redis_pwd']) {
|
|
|
+ $redis->auth($redisconfig['redis_pwd']);
|
|
|
+ }
|
|
|
+ if($redisconfig['redis_selectdb'] > 0){
|
|
|
+ $redis->select($redisconfig['redis_selectdb']);
|
|
|
+ }
|
|
|
+ $userId = $input['EventInfo']['UserId'];
|
|
|
+ $redis->hSet("online_" . $roomId, $userId, $userId);
|
|
|
+ $redis->zAdd("party_user_".$roomId,$userId,0); //新加的
|
|
|
+ // 记录在线用户在房间情况
|
|
|
+ $redis->hSet("livingUser",$userId,$roomId);
|
|
|
+
|
|
|
+ // 更新房间在线状态
|
|
|
+ $partyInfo = $redis->get("party_" . $roomId);
|
|
|
+ if ($partyInfo) {
|
|
|
+ $partyInfo = json_decode($partyInfo, true);
|
|
|
+ if ($partyInfo["is_online"] != 1) {
|
|
|
+ $partyInfo["is_online"] = 1;
|
|
|
+ $redis->set("party_" . $roomId, json_encode($partyInfo));
|
|
|
+ \app\common\model\Party::update(["is_online" => 1], ["id" => $roomId]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新房间在线状态
|
|
|
+ $liveInfo = $redis->get("live_" . $roomId);
|
|
|
+ if ($liveInfo) {
|
|
|
+ $liveInfo = json_decode($liveInfo, true);
|
|
|
+ if ($input['EventInfo']['Role'] == 20) {
|
|
|
+ $liveInfo["is_online"] = 1;
|
|
|
+ $redis->set("live_" . $roomId, json_encode($liveInfo));
|
|
|
+ \app\common\model\Party::update(["is_online" => 1], ["id" => $roomId]);
|
|
|
+ $rs_user = Db::name('user')->where('id',$userId)->update(['is_live'=>1]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }elseif($input['EventType'] == 104){
|
|
|
+ //退出房间,主播role=20 观众role=21
|
|
|
+ $redis = new Redis();
|
|
|
+ $redisconfig = config("redis");
|
|
|
+ $redis->connect($redisconfig["host"], $redisconfig["port"]);
|
|
|
+ if ($redisconfig['redis_pwd']) {
|
|
|
+ $redis->auth($redisconfig['redis_pwd']);
|
|
|
+ }
|
|
|
+ if($redisconfig['redis_selectdb'] > 0){
|
|
|
+ $redis->select($redisconfig['redis_selectdb']);
|
|
|
+ }
|
|
|
+ $userId = $input['EventInfo']['UserId'];
|
|
|
+ $redis->HDel("online_" . $roomId, $userId);
|
|
|
+ $redis->zRem("party_user_".$roomId,$userId); //新加的
|
|
|
+ // 扣除在线用户在房间情况
|
|
|
+ $redis->hDel("livingUser",$userId);
|
|
|
+
|
|
|
+ // 更新房间在线状态
|
|
|
+ $partyInfo = $redis->get("party_" . $roomId);
|
|
|
+ if ($partyInfo) {
|
|
|
+ $partyInfo = json_decode($partyInfo, true);
|
|
|
+ $memCount = count($redis->hGetAll("online_" . $roomId));
|
|
|
+ if ($memCount <= 0) {
|
|
|
+ $partyInfo["is_online"] = 0;
|
|
|
+ $redis->set("party_" . $roomId, json_encode($partyInfo));
|
|
|
+ \app\common\model\Party::update(["is_online" => 0], ["id" => $roomId]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //
|
|
|
+ $liveInfo = $redis->get("live_" . $roomId);
|
|
|
+ if ($liveInfo) {
|
|
|
+ $liveInfo = json_decode($liveInfo, true);
|
|
|
+ if($input['EventInfo']['Role'] == 20){
|
|
|
+ $liveInfo["is_online"] = 0;
|
|
|
+ $redis->set("live_" . $roomId, json_encode($liveInfo));
|
|
|
+ \app\common\model\Party::update(["is_online" => 0], ["id" => $roomId]);
|
|
|
+ $rs_user = Db::name('user')->where('id',$userId)->update(['is_live'=>0]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //退出房间获取房间自定义属性
|
|
|
+ $tenimService = new TenimService();
|
|
|
+ $imParams = ['party_id' => (string)$roomId];
|
|
|
+ $imRes = $tenimService->getGroupAttr($imParams);
|
|
|
+ if ($imRes['status'] == 1) {
|
|
|
+ if (isset($imRes['data']) && !empty($imRes['data'])) {
|
|
|
+ $imFieldArr = ['seat0','seat1','seat2','seat3','seat4','seat5','seat6','seat7','seat8','seat9'];
|
|
|
+ foreach ($imRes['data'] as $imKey => &$imVal) {
|
|
|
+ if (in_array($imVal['key'],$imFieldArr)) {
|
|
|
+ $tempData = json_decode($imVal['value'],true);
|
|
|
+ if (isset($tempData['user'])) {
|
|
|
+ if ($tempData['user'] == $userId) {//找到用户清理麦序
|
|
|
+ $tempData['status'] = 0;
|
|
|
+ $tempData['user'] = "";
|
|
|
+ } else {
|
|
|
+ if (empty($tempData['user']) && $tempData['status'] == 1) {
|
|
|
+ $tempData['status'] = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $imVal['value'] = json_encode($tempData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $imAttrParams = [
|
|
|
+ 'party_id' => $roomId,
|
|
|
+ 'party_attr' => $imRes['data'],
|
|
|
+ ];
|
|
|
+ $tenimService->getGroupAttrEdit($imAttrParams);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }elseif($input['EventGroupId'] == 2){
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //结束
|
|
|
+ echo json_encode(['code' => 0]);exit;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 回调
|
|
|
*/
|
|
@@ -1062,4 +1208,32 @@ exit;
|
|
|
$result = $memberList;
|
|
|
$this->success('操作成功',$result);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取房间用户
|
|
|
+ */
|
|
|
+ public function getGroupAttr() {
|
|
|
+ $partyId = $this->request->param('party_id','');
|
|
|
+ if (!empty($partyIds)) {
|
|
|
+ $this->error('参数错误');
|
|
|
+ }
|
|
|
+ $random = rand(10000000,99999999);
|
|
|
+ $usersig = $this->usersig("administrator");
|
|
|
+ // 获取配置信息
|
|
|
+ $config = config("tencent_im");
|
|
|
+ $url = "https://console.tim.qq.com/v4/group_open_attr_http_svc/get_group_attr";
|
|
|
+ $url .= "?sdkappid=".$config["sdkappid"];
|
|
|
+ $url .= "&identifier=administrator";
|
|
|
+ $url .= "&usersig=".$usersig;
|
|
|
+ $url .= "&random=".$random;
|
|
|
+ $url .= "&contenttype=json";
|
|
|
+ $tencentObj = new tencentim($url);
|
|
|
+
|
|
|
+ $result = [];
|
|
|
+ if(!empty($partyId)) {
|
|
|
+ $data["GroupId"] = $partyId;
|
|
|
+ $result = $tencentObj->toSend($data);
|
|
|
+ }
|
|
|
+ $this->success('操作成功',$result);
|
|
|
+ }
|
|
|
}
|