瀏覽代碼

异常退出麦序问题

zhangxiaobin 1 年之前
父節點
當前提交
64be9a3f05
共有 2 個文件被更改,包括 106 次插入7 次删除
  1. 43 7
      application/api/controller/Tenim.php
  2. 63 0
      application/common/service/TenimService.php

+ 43 - 7
application/api/controller/Tenim.php

@@ -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;
@@ -587,7 +588,7 @@ exit;
     public function trtc_callback(){
 
         $input = file_get_contents("php://input");
-        filePut('start:'.$input,'callback.txt');
+        //filePut('start:'.$input,'callback.txt');
 
         /*$input = '{
             "EventGroupId":	1,
@@ -602,7 +603,19 @@ exit;
                 "Reason":	1
             }
         }';*/
-
+        $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'];
         //房间事件组
@@ -625,7 +638,7 @@ exit;
                 }
                 $userId = $input['EventInfo']['UserId'];
                 $redis->hSet("online_" . $roomId, $userId, $userId);
-
+                $redis->zAdd("party_user_".$roomId,$userId,0); //新加的
                 // 记录在线用户在房间情况
                 $redis->hSet("livingUser",$userId,$roomId);
 
@@ -648,7 +661,7 @@ exit;
                         $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_livebc'=>1]);
+                        $rs_user = Db::name('user')->where('id',$userId)->update(['is_live'=>1]);
                     }
                 }
 
@@ -665,7 +678,7 @@ exit;
                 }
                 $userId = $input['EventInfo']['UserId'];
                 $redis->HDel("online_" . $roomId, $userId);
-
+                $redis->zRem("party_user_".$roomId,$userId); //新加的
                 // 扣除在线用户在房间情况
                 $redis->hDel("livingUser",$userId);
 
@@ -688,10 +701,33 @@ exit;
                         $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_livebc'=>0]);
+                        $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']) && $tempData['user'] == $userId) {
+                                    $tempData['status'] = 0;
+                                    $tempData['user'] = "0";
+                                }
+                                $imVal['value'] = json_encode($tempData);
+                            }
+                        }
+                        $imAttrParams = [
+                            'party_id' => $roomId,
+                            'party_attr' => $imRes['data'],
+                        ];
+                        $tenimService->getGroupAttrEdit($imAttrParams);
                     }
                 }
-
             }
         }elseif($input['EventGroupId'] == 2){
 

+ 63 - 0
application/common/service/TenimService.php

@@ -78,4 +78,67 @@ class TenimService
         }
         return $result;
     }
+
+    /**
+     * 获取房间自定义属性
+     */
+    public function getGroupAttr($params=[])
+    {
+        $result = [
+            'status' => 1,
+            'msg' => '获取成功',
+            'data' => [],
+        ];
+        try {
+            $partyId = isset($params['party_id']) ? $params['party_id'] : [];
+            $url = "https://console.tim.qq.com/v4/group_open_attr_http_svc/get_group_attr".$this->url;
+            $tencentObj = new tencentim($url);
+            $imResult = [];
+            if(!empty($partyId)) {
+                $data["GroupId"] = $partyId;
+                $imRes = $tencentObj->toSend($data);
+                if (isset($imRes['ActionStatus']) && $imRes['ActionStatus'] != 'OK') {
+                    $errorInfo = isset($imRes['ErrorInfo']) ? $imRes['ErrorInfo'] : [];
+                    throw new Exception(json_encode($errorInfo));
+                }
+                $imResult = isset($imRes['GroupAttrAry']) ? $imRes['GroupAttrAry'] : [];
+            }
+            $result['data'] = $imResult;
+        } catch (\Exception $e) {
+            $result['status'] = 0;
+            $result['msg'] = $e->getMessage();
+        }
+        return $result;
+    }
+
+    /**
+     * 更新房间属性
+     */
+    public function getGroupAttrEdit($params=[])
+    {
+        $result = [
+            'status' => 1,
+            'msg' => '获取成功',
+            'data' => [],
+        ];
+        try {
+            $partyId = isset($params['party_id']) ? $params['party_id'] : [];
+            $partyAttr = isset($params['party_attr']) ? $params['party_attr'] : [];
+            $url = "https://console.tim.qq.com/v4/group_open_http_svc/modify_group_attr".$this->url;
+            $tencentObj = new tencentim($url);
+            if(!empty($partyId)) {
+                $data["GroupId"] = $partyId;
+                $data["GroupAttr"] = $partyAttr;
+                $imRes = $tencentObj->toSend($data);
+                if (isset($imRes['ActionStatus']) && $imRes['ActionStatus'] != 'OK') {
+                    $errorInfo = isset($imRes['ErrorInfo']) ? $imRes['ErrorInfo'] : [];
+                    throw new Exception(json_encode($errorInfo));
+                }
+            }
+        } catch (\Exception $e) {
+            $result['status'] = 0;
+            $result['msg'] = $e->getMessage();
+        }
+        return $result;
+    }
 }