Browse Source

trtc回调

lizhen_gitee 3 years ago
parent
commit
4644747c55
1 changed files with 90 additions and 8 deletions
  1. 90 8
      application/api/controller/Tenim.php

+ 90 - 8
application/api/controller/Tenim.php

@@ -583,18 +583,100 @@ exit;
     }
 
     //trtc_callback,直播callback
+    //https://cloud.tencent.com/document/product/647/51586#eventId
+    /*
+     2021-12-24 15:34:22 start2:{
+            "EventGroupId":	1,
+            "EventType":	103,
+            "CallbackTs":	1640331262241,
+            "EventInfo":	{
+                "RoomId":	1604,
+                "EventTs":	1640331262,
+                "EventMsTs":	1640331262238,
+                "UserId":	"26",
+                "Role":	20,
+                "TerminalType":	2,
+                "UserType":	3,
+                "Reason":	1
+            }
+        }
+        2021-12-24 15:34:22 start2:{
+            "EventGroupId":	1,
+            "EventType":	101,
+            "CallbackTs":	1640331262247,
+            "EventInfo":	{
+                "RoomId":	1604,
+                "EventTs":	1640331262,
+                "EventMsTs":	1640331262238,
+                "UserId":	"26"
+            }
+        }
+        2021-12-24 15:34:55 start2:{
+            "EventGroupId":	1,
+            "EventType":	102,
+            "CallbackTs":	1640331295244,
+            "EventInfo":	{
+                "RoomId":	1604,
+                "EventTs":	1640331295,
+                "EventMsTs":	1640331295239
+            }
+        }
+        2021-12-24 15:34:55 start2:{
+            "EventGroupId":	1,
+            "EventType":	104,
+            "CallbackTs":	1640331295244,
+            "EventInfo":	{
+                "RoomId":	1604,
+                "EventTs":	1640331295,
+                "EventMsTs":	1640331295239,
+                "UserId":	"26",
+                "Role":	20,
+                "Reason":	1
+            }
+        }
+     */
     public function trtc_callback(){
 
-        $_REQUEST = isset($_REQUEST) ? $_REQUEST : array();
-        if($_REQUEST) {
-            filePut('start:'.json_encode($_REQUEST),'callback.txt');
-        } else {
-            $xml = file_get_contents("php://input");
-            filePut('start:'.$xml,'callback.txt');
-            $xmlObj = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
-            filePut('start:'.$xmlObj,'callback.txt');
+        $input = file_get_contents("php://input");
+        filePut('start:'.$input,'callback.txt');
+
+        /*$input = '{
+            "EventGroupId":	1,
+            "EventType":	104,
+            "CallbackTs":	1640331295244,
+            "EventInfo":	{
+                "RoomId":	1604,
+                "EventTs":	1640331295,
+                "EventMsTs":	1640331295239,
+                "UserId":	"26",
+                "Role":	20,
+                "Reason":	1
+            }
+        }';*/
+
+        $input = json_decode($input,true);
+        //房间事件组
+        if($input['EventGroupId'] == 1){
+            if($input['EventType'] == 101){
+                //创建房间,第一个进来的
+            }elseif($input['EventType'] == 102){
+                //解散房间,最后一个走的
+                //没有UserId
+            }elseif($input['EventType'] == 103){
+                //进入房间,主播role=20 观众role=21
+            }elseif($input['EventType'] == 104){
+                //退出房间,主播role=20 观众role=21
+                if($input['EventInfo']['Role'] == 20){
+                    $live_bc = Db::name('livebc')->where('user_id',$input['EventInfo']['UserId'])->update(['is_online'=>0]);
+                    $rs_user = Db::name('user')->where('id',$input['EventInfo']['UserId'])->update(['is_livebc'=>0]);
+                }
+            }
+        }elseif($input['EventGroupId'] == 2){
+
         }
 
+        //结束
+        echo json_encode(['code' => 0]);exit;
     }
 
     /**