新增处理音视频回调-云端录制
This commit is contained in:
parent
f04137c472
commit
22c8dc21e0
@ -1720,54 +1720,74 @@ class CallBackController extends AbstractController
|
|||||||
Log::getInstance("CallBackController-videoTrtcCallBack")->info(json_encode($request_params, JSON_UNESCAPED_UNICODE));
|
Log::getInstance("CallBackController-videoTrtcCallBack")->info(json_encode($request_params, JSON_UNESCAPED_UNICODE));
|
||||||
|
|
||||||
if (empty($SdkAppId)) {
|
if (empty($SdkAppId)) {
|
||||||
return $this->TrtcErrorReturn("缺少SdkAppId字段");
|
return $this->videoTrtcErrorReturn("缺少SdkAppId字段");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($Sign)) {
|
if (empty($Sign)) {
|
||||||
return $this->TrtcErrorReturn("缺少签名字段");
|
return $this->videoTrtcErrorReturn("缺少签名字段");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 鉴定回调签名
|
// 鉴定回调签名
|
||||||
$VideoSafe = new VideoSafe();
|
$VideoSafe = new VideoSafe();
|
||||||
$result = $VideoSafe->validateSign($request_params,$Sign);
|
$result = $VideoSafe->validateSign($request_params,$Sign);
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
return $this->TrtcErrorReturn("回调签名不匹配");
|
return $this->videoTrtcErrorReturn("回调签名不匹配");
|
||||||
}
|
}
|
||||||
|
|
||||||
$request_params = json_decode($request_params,true);
|
$request_params = json_decode($request_params,true);
|
||||||
|
|
||||||
// 验证参数
|
// 验证参数
|
||||||
|
if (!isset($request_params['EventGroupId'])){
|
||||||
|
return $this->videoTrtcErrorReturn("缺少回调事件组");
|
||||||
|
}
|
||||||
|
|
||||||
if (empty($request_params['EventGroupId'])){
|
if (empty($request_params['EventGroupId'])){
|
||||||
return $this->TrtcErrorReturn("回调事件组为空");
|
return $this->videoTrtcErrorReturn("回调事件组为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($request_params['EventType'])){
|
||||||
|
return $this->videoTrtcErrorReturn("回调事件类型");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($request_params['EventType'])){
|
if (empty($request_params['EventType'])){
|
||||||
return $this->TrtcErrorReturn("回调事件类型为空");
|
return $this->videoTrtcErrorReturn("回调事件类型为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($request_params['EventInfo'])){
|
||||||
|
return $this->videoTrtcErrorReturn("缺少回调事件信息");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($request_params['EventInfo'])){
|
if (empty($request_params['EventInfo'])){
|
||||||
return $this->TrtcErrorReturn("回调事件信息为空");
|
return $this->videoTrtcErrorReturn("回调事件信息为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($request_params['EventInfo']['RoomId'])){
|
||||||
|
return $this->videoTrtcErrorReturn("缺少房间id");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($request_params['EventInfo']['RoomId'])){
|
if (empty($request_params['EventInfo']['RoomId'])){
|
||||||
return $this->TrtcErrorReturn("缺少房间id");
|
return $this->videoTrtcErrorReturn("房间id为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($request_params['EventInfo']['EventMsTs'])){
|
||||||
|
return $this->videoTrtcErrorReturn("缺少时间戳");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($request_params['EventInfo']['EventMsTs'])){
|
if (empty($request_params['EventInfo']['EventMsTs'])){
|
||||||
return $this->TrtcErrorReturn("缺少时间戳");
|
return $this->videoTrtcErrorReturn("时间戳为空");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 排除数据
|
// 排除数据
|
||||||
if ($request_params['EventGroupId'] != 1 && $request_params['EventGroupId'] != 2){
|
if ($request_params['EventGroupId'] != 1 && $request_params['EventGroupId'] != 2){
|
||||||
return $this->TrtcErrorReturn("回调地址推送错误");
|
return $this->videoTrtcErrorReturn("回调地址推送错误");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!in_array($request_params['EventType'],[102,103,201,203])){
|
if (!in_array($request_params['EventType'],[102,103,201,203])){
|
||||||
return $this->TrtcSuccessReturn();
|
return $this->videoTrtcSuccessReturn();
|
||||||
}
|
}
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
// 验证失败
|
// 验证失败
|
||||||
return $this->TrtcErrorReturn($e->getMessage());
|
return $this->videoTrtcErrorReturn($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理业务逻辑
|
// 处理业务逻辑
|
||||||
@ -1777,7 +1797,7 @@ class CallBackController extends AbstractController
|
|||||||
$params['room_id'] = $request_params['EventInfo']['RoomId'];
|
$params['room_id'] = $request_params['EventInfo']['RoomId'];
|
||||||
$order_inquiry_video_reservation = OrderInquiryVideoReservation::getLastOne($params);
|
$order_inquiry_video_reservation = OrderInquiryVideoReservation::getLastOne($params);
|
||||||
if (empty($order_inquiry_video_reservation)){
|
if (empty($order_inquiry_video_reservation)){
|
||||||
return $this->TrtcErrorReturn("未查询到该房间号,此条数据不接收");
|
return $this->videoTrtcErrorReturn("未查询到该房间号,此条数据不接收");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取视频记录
|
// 获取视频记录
|
||||||
@ -1786,12 +1806,12 @@ class CallBackController extends AbstractController
|
|||||||
$params['order_inquiry_id'] = $order_inquiry_video_reservation['order_inquiry_id'];
|
$params['order_inquiry_id'] = $order_inquiry_video_reservation['order_inquiry_id'];
|
||||||
$order_inquiry_video_record = OrderInquiryVideoRecord::getLastOne($params);
|
$order_inquiry_video_record = OrderInquiryVideoRecord::getLastOne($params);
|
||||||
if (empty($order_inquiry_video_record)){
|
if (empty($order_inquiry_video_record)){
|
||||||
return $this->TrtcErrorReturn("缺少视频开启记录");
|
return $this->videoTrtcErrorReturn("缺少视频开启记录");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检测缓存-只允许同时处理同一房间的一个请求,防止数据库冲突
|
// 检测缓存-只允许同时处理同一房间的一个请求,防止数据库冲突
|
||||||
$redis = $this->container->get(Redis::class);
|
$redis = $this->container->get(Redis::class);
|
||||||
$redis_key = "trtcCallBack_" . $request_params['EventInfo']['RoomId'];
|
$redis_key = "videoTrtcCallBack_" . $request_params['EventInfo']['RoomId'];
|
||||||
$redis_value = $redis->get($redis_key);
|
$redis_value = $redis->get($redis_key);
|
||||||
|
|
||||||
// 加入缓存
|
// 加入缓存
|
||||||
@ -1799,25 +1819,25 @@ class CallBackController extends AbstractController
|
|||||||
if (!empty($redis_value)){
|
if (!empty($redis_value)){
|
||||||
if ($redis_value == $request_params['EventType']){
|
if ($redis_value == $request_params['EventType']){
|
||||||
// 存在正在执行的相同事件,此次事件不处理
|
// 存在正在执行的相同事件,此次事件不处理
|
||||||
return $this->TrtcSuccessReturn();
|
return $this->videoTrtcSuccessReturn();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 解散房间
|
// 解散房间
|
||||||
if ($redis_value == 102){
|
if ($redis_value == 102){
|
||||||
// 正在处理结束通话事件,此次事件不处理
|
// 正在处理结束通话事件,此次事件不处理
|
||||||
return $this->TrtcSuccessReturn();
|
return $this->videoTrtcSuccessReturn();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 视频推流
|
// 视频推流
|
||||||
if ($redis_value == 201){
|
if ($redis_value == 201){
|
||||||
if ($request_params['EventType'] == 103){
|
if ($request_params['EventType'] == 103){
|
||||||
// 正在处理视频推流事件,进入房间事件不处理
|
// 正在处理视频推流事件,进入房间事件不处理
|
||||||
return $this->TrtcSuccessReturn();
|
return $this->videoTrtcSuccessReturn();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request_params['EventType'] == 203){
|
if ($request_params['EventType'] == 203){
|
||||||
// 正在处理视频推流事件,音频推流事件不处理
|
// 正在处理视频推流事件,音频推流事件不处理
|
||||||
return $this->TrtcSuccessReturn();
|
return $this->videoTrtcSuccessReturn();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1825,12 +1845,12 @@ class CallBackController extends AbstractController
|
|||||||
if ($redis_value == 203){
|
if ($redis_value == 203){
|
||||||
if ($request_params['EventType'] == 103){
|
if ($request_params['EventType'] == 103){
|
||||||
// 正在处理视频推流事件,进入房间事件不处理
|
// 正在处理视频推流事件,进入房间事件不处理
|
||||||
return $this->TrtcSuccessReturn();
|
return $this->videoTrtcSuccessReturn();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request_params['EventType'] == 201){
|
if ($request_params['EventType'] == 201){
|
||||||
// 正在处理视频推流事件,视频推流事件不处理
|
// 正在处理视频推流事件,视频推流事件不处理
|
||||||
return $this->TrtcSuccessReturn();
|
return $this->videoTrtcSuccessReturn();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1839,7 +1859,7 @@ class CallBackController extends AbstractController
|
|||||||
switch ($request_params['EventType']) {
|
switch ($request_params['EventType']) {
|
||||||
case '103': // 进入房间
|
case '103': // 进入房间
|
||||||
if (empty($request_params['EventInfo']['UserId'])){
|
if (empty($request_params['EventInfo']['UserId'])){
|
||||||
return $this->TrtcErrorReturn("缺少用户id");
|
return $this->videoTrtcErrorReturn("缺少用户id");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取用户数据
|
// 获取用户数据
|
||||||
@ -1847,17 +1867,17 @@ class CallBackController extends AbstractController
|
|||||||
$params['user_id'] = $request_params['EventInfo']['UserId'];
|
$params['user_id'] = $request_params['EventInfo']['UserId'];
|
||||||
$user = User::getOne($params);
|
$user = User::getOne($params);
|
||||||
if (empty($user)){
|
if (empty($user)){
|
||||||
return $this->TrtcErrorReturn("非法用户");
|
return $this->videoTrtcErrorReturn("非法用户");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($user['user_type'] != 1){
|
if ($user['user_type'] != 1){
|
||||||
return $this->TrtcSuccessReturn();
|
return $this->videoTrtcSuccessReturn();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检测视频状态
|
// 检测视频状态
|
||||||
if ($order_inquiry_video_record['video_status'] == 3 || $order_inquiry_video_record['video_status'] == 4){
|
if ($order_inquiry_video_record['video_status'] == 3 || $order_inquiry_video_record['video_status'] == 4){
|
||||||
// 已开始/结束通话,进入房间动作不做处理
|
// 已开始/结束通话,进入房间动作不做处理
|
||||||
return $this->TrtcSuccessReturn();
|
return $this->videoTrtcSuccessReturn();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改视频状态
|
// 修改视频状态
|
||||||
@ -1868,7 +1888,7 @@ class CallBackController extends AbstractController
|
|||||||
$data['video_status'] = 2;
|
$data['video_status'] = 2;
|
||||||
$res = OrderInquiryVideoRecord::edit($params,$data);
|
$res = OrderInquiryVideoRecord::edit($params,$data);
|
||||||
if (!$res){
|
if (!$res){
|
||||||
return $this->TrtcErrorReturn("修改视频状态失败");
|
return $this->videoTrtcErrorReturn("修改视频状态失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -1876,7 +1896,7 @@ class CallBackController extends AbstractController
|
|||||||
// 检测视频状态
|
// 检测视频状态
|
||||||
if ($order_inquiry_video_record['video_status'] == 4){
|
if ($order_inquiry_video_record['video_status'] == 4){
|
||||||
// 已结束通话,解散房间动作不做处理
|
// 已结束通话,解散房间动作不做处理
|
||||||
return $this->TrtcSuccessReturn();
|
return $this->videoTrtcSuccessReturn();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改视频状态
|
// 修改视频状态
|
||||||
@ -1888,7 +1908,7 @@ class CallBackController extends AbstractController
|
|||||||
$data['stop_video_time'] = date('Y-m-d H:i:s',$request_params['EventInfo']['EventMsTs']);
|
$data['stop_video_time'] = date('Y-m-d H:i:s',$request_params['EventInfo']['EventMsTs']);
|
||||||
$res = OrderInquiryVideoRecord::edit($params,$data);
|
$res = OrderInquiryVideoRecord::edit($params,$data);
|
||||||
if (!$res){
|
if (!$res){
|
||||||
return $this->TrtcErrorReturn("修改视频状态失败");
|
return $this->videoTrtcErrorReturn("修改视频状态失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -1896,12 +1916,12 @@ class CallBackController extends AbstractController
|
|||||||
// 检测视频状态
|
// 检测视频状态
|
||||||
if ($order_inquiry_video_record['video_status'] == 4){
|
if ($order_inquiry_video_record['video_status'] == 4){
|
||||||
// 已结束通话,视频推流动作不做处理
|
// 已结束通话,视频推流动作不做处理
|
||||||
return $this->TrtcSuccessReturn();
|
return $this->videoTrtcSuccessReturn();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($order_inquiry_video_record['video_status'] == 3){
|
if ($order_inquiry_video_record['video_status'] == 3){
|
||||||
// 已开始通话,视频推流动作不做处理
|
// 已开始通话,视频推流动作不做处理
|
||||||
return $this->TrtcSuccessReturn();
|
return $this->videoTrtcSuccessReturn();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改视频状态
|
// 修改视频状态
|
||||||
@ -1913,7 +1933,7 @@ class CallBackController extends AbstractController
|
|||||||
$data['stop_video_time'] = date('Y-m-d H:i:s',$request_params['EventInfo']['EventMsTs']);
|
$data['stop_video_time'] = date('Y-m-d H:i:s',$request_params['EventInfo']['EventMsTs']);
|
||||||
$res = OrderInquiryVideoRecord::edit($params,$data);
|
$res = OrderInquiryVideoRecord::edit($params,$data);
|
||||||
if (!$res){
|
if (!$res){
|
||||||
return $this->TrtcErrorReturn("修改视频状态失败");
|
return $this->videoTrtcErrorReturn("修改视频状态失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -1921,12 +1941,12 @@ class CallBackController extends AbstractController
|
|||||||
// 检测视频状态
|
// 检测视频状态
|
||||||
if ($order_inquiry_video_record['video_status'] == 4){
|
if ($order_inquiry_video_record['video_status'] == 4){
|
||||||
// 已结束通话,音频推流动作不做处理
|
// 已结束通话,音频推流动作不做处理
|
||||||
return $this->TrtcSuccessReturn();
|
return $this->videoTrtcSuccessReturn();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($order_inquiry_video_record['video_status'] == 3){
|
if ($order_inquiry_video_record['video_status'] == 3){
|
||||||
// 已开始通话,音频推流动作不做处理
|
// 已开始通话,音频推流动作不做处理
|
||||||
return $this->TrtcSuccessReturn();
|
return $this->videoTrtcSuccessReturn();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改视频状态
|
// 修改视频状态
|
||||||
@ -1938,23 +1958,23 @@ class CallBackController extends AbstractController
|
|||||||
$data['stop_video_time'] = date('Y-m-d H:i:s',$request_params['EventInfo']['EventMsTs']);
|
$data['stop_video_time'] = date('Y-m-d H:i:s',$request_params['EventInfo']['EventMsTs']);
|
||||||
$res = OrderInquiryVideoRecord::edit($params,$data);
|
$res = OrderInquiryVideoRecord::edit($params,$data);
|
||||||
if (!$res){
|
if (!$res){
|
||||||
return $this->TrtcErrorReturn("修改视频状态失败");
|
return $this->videoTrtcErrorReturn("修改视频状态失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return $this->TrtcErrorReturn("未知事件");
|
return $this->videoTrtcErrorReturn("未知事件");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除缓存
|
// 删除缓存
|
||||||
$redis->del($redis_key);
|
$redis->del($redis_key);
|
||||||
}catch (\Throwable $e){
|
}catch (\Throwable $e){
|
||||||
return $this->TrtcErrorReturn($e->getMessage());
|
return $this->videoTrtcErrorReturn($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
Log::getInstance("CallBackController-videoTrtcCallBack")->info("音视频回调-房间与媒体处理成功");
|
Log::getInstance("CallBackController-videoTrtcCallBack")->info("音视频回调-房间与媒体处理成功");
|
||||||
return $this->TrtcSuccessReturn();
|
return $this->videoTrtcSuccessReturn();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1962,7 +1982,7 @@ class CallBackController extends AbstractController
|
|||||||
* @param string $message
|
* @param string $message
|
||||||
* @return ResponseInterface
|
* @return ResponseInterface
|
||||||
*/
|
*/
|
||||||
protected function TrtcErrorReturn(string $message): ResponseInterface
|
protected function videoTrtcErrorReturn(string $message): ResponseInterface
|
||||||
{
|
{
|
||||||
Log::getInstance("CallBackController-videoTrtcCallBack")->error($message);
|
Log::getInstance("CallBackController-videoTrtcCallBack")->error($message);
|
||||||
return $this->response
|
return $this->response
|
||||||
@ -1983,7 +2003,7 @@ class CallBackController extends AbstractController
|
|||||||
* 音视频返回正确响应
|
* 音视频返回正确响应
|
||||||
* @return ResponseInterface
|
* @return ResponseInterface
|
||||||
*/
|
*/
|
||||||
protected function TrtcSuccessReturn(): ResponseInterface
|
protected function videoTrtcSuccessReturn(): ResponseInterface
|
||||||
{
|
{
|
||||||
return $this->response
|
return $this->response
|
||||||
->withStatus(200)
|
->withStatus(200)
|
||||||
@ -2014,55 +2034,79 @@ class CallBackController extends AbstractController
|
|||||||
Log::getInstance("CallBackController-videoRecordingCallBack")->info(json_encode($request_params, JSON_UNESCAPED_UNICODE));
|
Log::getInstance("CallBackController-videoRecordingCallBack")->info(json_encode($request_params, JSON_UNESCAPED_UNICODE));
|
||||||
|
|
||||||
if (empty($SdkAppId)) {
|
if (empty($SdkAppId)) {
|
||||||
return $this->recordingErrorReturn("缺少SdkAppId字段");
|
return $this->videoRecordingErrorReturn("缺少SdkAppId字段");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($Sign)) {
|
if (empty($Sign)) {
|
||||||
return $this->recordingErrorReturn("缺少签名字段");
|
return $this->videoRecordingErrorReturn("缺少签名字段");
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->recordingSuccessReturn();
|
|
||||||
// 鉴定回调签名
|
// 鉴定回调签名
|
||||||
$VideoSafe = new VideoSafe();
|
$VideoSafe = new VideoSafe();
|
||||||
$result = $VideoSafe->validateSign($request_params,$Sign);
|
$result = $VideoSafe->validateSign($request_params,$Sign);
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
return $this->recordingErrorReturn("回调签名不匹配");
|
return $this->videoRecordingErrorReturn("回调签名不匹配");
|
||||||
}
|
}
|
||||||
|
|
||||||
$request_params = json_decode($request_params,true);
|
$request_params = json_decode($request_params,true);
|
||||||
|
|
||||||
// 验证参数
|
// 验证参数
|
||||||
|
if (!isset($request_params['EventGroupId'])){
|
||||||
|
return $this->videoRecordingErrorReturn("缺少回调事件组");
|
||||||
|
}
|
||||||
|
|
||||||
if (empty($request_params['EventGroupId'])){
|
if (empty($request_params['EventGroupId'])){
|
||||||
return $this->recordingErrorReturn("回调事件组为空");
|
return $this->videoRecordingErrorReturn("回调事件组为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($request_params['EventType'])){
|
||||||
|
return $this->videoRecordingErrorReturn("缺少回调事件类型");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($request_params['EventType'])){
|
if (empty($request_params['EventType'])){
|
||||||
return $this->recordingErrorReturn("回调事件类型为空");
|
return $this->videoRecordingErrorReturn("回调事件类型为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($request_params['EventInfo'])){
|
||||||
|
return $this->videoRecordingErrorReturn("缺少回调事件信息");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($request_params['EventInfo'])){
|
if (empty($request_params['EventInfo'])){
|
||||||
return $this->recordingErrorReturn("回调事件信息为空");
|
return $this->videoRecordingErrorReturn("回调事件信息为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($request_params['EventInfo']['RoomId'])){
|
||||||
|
return $this->videoRecordingErrorReturn("缺少房间id");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($request_params['EventInfo']['RoomId'])){
|
if (empty($request_params['EventInfo']['RoomId'])){
|
||||||
return $this->recordingErrorReturn("缺少房间id");
|
return $this->videoRecordingErrorReturn("房间id为空");
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($request_params['EventInfo']['EventMsTs'])){
|
|
||||||
return $this->recordingErrorReturn("缺少时间戳");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 排除数据
|
// 排除数据
|
||||||
if ($request_params['EventGroupId'] != 3){
|
if ($request_params['EventGroupId'] != 3){
|
||||||
return $this->recordingErrorReturn("回调地址推送错误");
|
return $this->videoRecordingErrorReturn("回调地址推送错误");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!in_array($request_params['EventType'],[301,312])){
|
if (!in_array($request_params['EventType'],[311])){
|
||||||
return $this->recordingSuccessReturn();
|
return $this->videoRecordingSuccessReturn();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isset($request_params['EventInfo']['Payload'])){
|
||||||
|
return $this->videoRecordingErrorReturn("缺少有效载荷");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($request_params['EventInfo']['Payload'])){
|
||||||
|
return $this->videoRecordingErrorReturn("有效载荷为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($request_params['EventInfo']['Payload']['Status'])){
|
||||||
|
return $this->videoRecordingErrorReturn("缺少录制状态");
|
||||||
|
}
|
||||||
|
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
// 验证失败
|
// 验证失败
|
||||||
return $this->recordingErrorReturn($e->getMessage());
|
return $this->videoRecordingErrorReturn($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理业务逻辑
|
// 处理业务逻辑
|
||||||
@ -2070,186 +2114,125 @@ class CallBackController extends AbstractController
|
|||||||
// 获取视频预约记录
|
// 获取视频预约记录
|
||||||
$params = array();
|
$params = array();
|
||||||
$params['room_id'] = $request_params['EventInfo']['RoomId'];
|
$params['room_id'] = $request_params['EventInfo']['RoomId'];
|
||||||
$video_reservation = VideoReservation::getLastOne($params);
|
$order_inquiry_video_reservation = OrderInquiryVideoReservation::getLastOne($params);
|
||||||
if (empty($video_reservation)){
|
if (empty($order_inquiry_video_reservation)){
|
||||||
return $this->recordingErrorReturn("未查询到该房间号,此条数据不接收");
|
return $this->videoRecordingErrorReturn("未查询到该房间号,此条数据不接收");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取视频记录
|
// 获取视频记录
|
||||||
$params = array();
|
$params = array();
|
||||||
$params['room_id'] = $request_params['EventInfo']['RoomId'];
|
$params['room_id'] = $request_params['EventInfo']['RoomId'];
|
||||||
$params['order_inquiry_id'] = $video_reservation['order_inquiry_id'];
|
$params['order_inquiry_id'] = $order_inquiry_video_reservation['order_inquiry_id'];
|
||||||
$order_inquiry_video_records = OrderInquiryVideoRecord::getLastOne($params);
|
$order_inquiry_video_record = OrderInquiryVideoRecord::getLastOne($params);
|
||||||
if (empty($order_inquiry_video_records)){
|
if (empty($order_inquiry_video_record)){
|
||||||
return $this->recordingErrorReturn("缺少视频开启记录");
|
return $this->videoRecordingErrorReturn("缺少视频开启记录");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($order_inquiry_video_record['doctor_vod_path']) && !empty($order_inquiry_video_record['patient_vod_path'])){
|
||||||
|
// 已存在点播路径,此次请求无需处理
|
||||||
|
return $this->videoRecordingSuccessReturn();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检测缓存-只允许同时处理同一房间的一个请求,防止数据库冲突
|
// 检测缓存-只允许同时处理同一房间的一个请求,防止数据库冲突
|
||||||
$redis = $this->container->get(Redis::class);
|
$redis = $this->container->get(Redis::class);
|
||||||
$redis_key = "trtcCallBack_" . $request_params['EventInfo']['RoomId'];
|
$redis_key = "videoRecordingCallBack_" . $request_params['EventInfo']['RoomId'] . $order_inquiry_video_reservation['patient_user_id'];
|
||||||
$redis_value = $redis->get($redis_key);
|
$redis_value = $redis->get($redis_key);
|
||||||
|
|
||||||
// 加入缓存
|
// 加入缓存
|
||||||
$redis->set($redis_key, $request_params['EventType'], 20);
|
$redis->set($redis_key, $request_params['EventType'], 20);
|
||||||
if (!empty($redis_value)){
|
if (!empty($redis_value)){
|
||||||
if ($redis_value == $request_params['EventType']){
|
// 事件正在处理,重复请求不处理
|
||||||
// 存在正在执行的相同事件,此次事件不处理
|
return $this->videoRecordingSuccessReturn();
|
||||||
return $this->recordingSuccessReturn();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 解散房间
|
|
||||||
if ($redis_value == 102){
|
|
||||||
// 正在处理结束通话事件,此次事件不处理
|
|
||||||
return $this->recordingSuccessReturn();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 视频推流
|
|
||||||
if ($redis_value == 201){
|
|
||||||
if ($request_params['EventType'] == 103){
|
|
||||||
// 正在处理视频推流事件,进入房间事件不处理
|
|
||||||
return $this->recordingSuccessReturn();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request_params['EventType'] == 203){
|
|
||||||
// 正在处理视频推流事件,音频推流事件不处理
|
|
||||||
return $this->recordingSuccessReturn();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 音频推流
|
|
||||||
if ($redis_value == 203){
|
|
||||||
if ($request_params['EventType'] == 103){
|
|
||||||
// 正在处理视频推流事件,进入房间事件不处理
|
|
||||||
return $this->recordingSuccessReturn();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request_params['EventType'] == 201){
|
|
||||||
// 正在处理视频推流事件,视频推流事件不处理
|
|
||||||
return $this->recordingSuccessReturn();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理业务逻辑
|
// 处理业务逻辑
|
||||||
switch ($request_params['EventType']) {
|
if ($request_params['EventInfo']['Payload']['Status'] == 0){
|
||||||
case '103': // 进入房间
|
// 录制上传成功
|
||||||
if (empty($request_params['EventInfo']['UserId'])){
|
if (!isset($request_params['EventInfo']['Payload']['TencentVod'])){
|
||||||
return $this->recordingErrorReturn("缺少用户id");
|
return $this->videoRecordingErrorReturn("缺少关键参数");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取用户数据
|
if (empty($request_params['EventInfo']['Payload']['TencentVod'])){
|
||||||
$params = array();
|
return $this->videoRecordingErrorReturn("缺少关键参数");
|
||||||
$params['user_id'] = $request_params['EventInfo']['UserId'];
|
}
|
||||||
$user = User::getOne($params);
|
|
||||||
if (empty($user)){
|
|
||||||
return $this->recordingErrorReturn("非法用户");
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($user['user_type'] != 1){
|
if (!isset($request_params['EventInfo']['Payload']['TencentVod']['UserId'])){
|
||||||
return $this->recordingSuccessReturn();
|
return $this->videoRecordingErrorReturn("缺少用户id参数");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检测视频状态
|
if (empty($request_params['EventInfo']['Payload']['TencentVod']['UserId'])){
|
||||||
if ($video_record['video_status'] == 3 || $video_record['video_status'] == 4){
|
return $this->videoRecordingErrorReturn("缺少用户id参数");
|
||||||
// 已开始/结束通话,进入房间动作不做处理
|
}
|
||||||
return $this->recordingSuccessReturn();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 修改视频状态
|
if (!isset($request_params['EventInfo']['Payload']['TencentVod']['VideoUrl'])){
|
||||||
$params = array();
|
return $this->videoRecordingErrorReturn("缺少播放地址参数");
|
||||||
$params['records_id'] = $video_record['records_id'];
|
}
|
||||||
|
|
||||||
|
if (empty($request_params['EventInfo']['Payload']['TencentVod']['VideoUrl'])){
|
||||||
|
return $this->videoRecordingErrorReturn("缺少播放地址参数");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取用户数据
|
||||||
|
$params = array();
|
||||||
|
$params['user_id'] = $request_params['EventInfo']['UserId'];
|
||||||
|
$user = User::getOne($params);
|
||||||
|
if (empty($user)){
|
||||||
|
return $this->videoRecordingErrorReturn("非法用户");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修改视频状态
|
||||||
|
$params = array();
|
||||||
|
$params['records_id'] = $order_inquiry_video_record['records_id'];
|
||||||
|
|
||||||
|
if ($user['user_type'] == 1){
|
||||||
$data = array();
|
$data = array();
|
||||||
$data['video_status'] = 2;
|
$data['vod_path_patient'] = $request_params['EventInfo']['Payload']['TencentVod']['VideoUrl'];
|
||||||
|
$data['vod_save_status'] = 1;
|
||||||
$res = OrderInquiryVideoRecord::edit($params,$data);
|
$res = OrderInquiryVideoRecord::edit($params,$data);
|
||||||
if (!$res){
|
if (!$res){
|
||||||
return $this->recordingErrorReturn("修改视频状态失败");
|
return $this->videoRecordingErrorReturn("播放地址存储失败");
|
||||||
}
|
}
|
||||||
|
}elseif($user['user_type'] == 2){
|
||||||
break;
|
|
||||||
case '102': // 解散房间
|
|
||||||
// 检测视频状态
|
|
||||||
if ($video_record['video_status'] == 4){
|
|
||||||
// 已结束通话,解散房间动作不做处理
|
|
||||||
return $this->recordingSuccessReturn();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 修改视频状态
|
|
||||||
$params = array();
|
|
||||||
$params['records_id'] = $video_record['records_id'];
|
|
||||||
|
|
||||||
$data = array();
|
$data = array();
|
||||||
$data['video_status'] = 4;
|
$data['vod_path_doctor'] = $request_params['EventInfo']['Payload']['TencentVod']['VideoUrl'];
|
||||||
$data['stop_video_time'] = date('Y-m-d H:i:s',$request_params['EventInfo']['EventMsTs']);
|
|
||||||
$res = OrderInquiryVideoRecord::edit($params,$data);
|
$res = OrderInquiryVideoRecord::edit($params,$data);
|
||||||
if (!$res){
|
if (!$res){
|
||||||
return $this->recordingErrorReturn("修改视频状态失败");
|
return $this->videoRecordingErrorReturn("播放地址存储失败");
|
||||||
}
|
}
|
||||||
|
}else{
|
||||||
|
return $this->videoRecordingErrorReturn("非法用户类型");
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
// 录制上传失败
|
||||||
|
if (!isset($request_params['EventInfo']['Payload']['Errmsg'])){
|
||||||
|
return $this->videoRecordingErrorReturn("录制上传失败但缺少错误描述");
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
if (empty($request_params['EventInfo']['Payload']['Errmsg'])){
|
||||||
case '201': // 视频推流
|
return $this->videoRecordingErrorReturn("录制上传失败但错误描述为空");
|
||||||
// 检测视频状态
|
}
|
||||||
if ($video_record['video_status'] == 4){
|
|
||||||
// 已结束通话,视频推流动作不做处理
|
|
||||||
return $this->recordingSuccessReturn();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($video_record['video_status'] == 3){
|
// 修改视频状态
|
||||||
// 已开始通话,视频推流动作不做处理
|
$params = array();
|
||||||
return $this->recordingSuccessReturn();
|
$params['records_id'] = $order_inquiry_video_record['records_id'];
|
||||||
}
|
|
||||||
|
|
||||||
// 修改视频状态
|
$data = array();
|
||||||
$params = array();
|
$data['vod_save_status'] = 2;
|
||||||
$params['records_id'] = $video_record['records_id'];
|
$data['vod_err_message'] = $request_params['EventInfo']['Payload']['Errmsg'];
|
||||||
|
$res = OrderInquiryVideoRecord::edit($params,$data);
|
||||||
$data = array();
|
if (!$res){
|
||||||
$data['video_status'] = 3;
|
return $this->videoRecordingErrorReturn("播放地址存储失败");
|
||||||
$data['stop_video_time'] = date('Y-m-d H:i:s',$request_params['EventInfo']['EventMsTs']);
|
}
|
||||||
$res = OrderInquiryVideoRecord::edit($params,$data);
|
|
||||||
if (!$res){
|
|
||||||
return $this->recordingErrorReturn("修改视频状态失败");
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
case '203': // 音频推流
|
|
||||||
// 检测视频状态
|
|
||||||
if ($video_record['video_status'] == 4){
|
|
||||||
// 已结束通话,音频推流动作不做处理
|
|
||||||
return $this->recordingSuccessReturn();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($video_record['video_status'] == 3){
|
|
||||||
// 已开始通话,音频推流动作不做处理
|
|
||||||
return $this->TrtcSuccessReturn();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 修改视频状态
|
|
||||||
$params = array();
|
|
||||||
$params['records_id'] = $video_record['records_id'];
|
|
||||||
|
|
||||||
$data = array();
|
|
||||||
$data['video_status'] = 3;
|
|
||||||
$data['stop_video_time'] = date('Y-m-d H:i:s',$request_params['EventInfo']['EventMsTs']);
|
|
||||||
$res = OrderInquiryVideoRecord::edit($params,$data);
|
|
||||||
if (!$res){
|
|
||||||
return $this->recordingErrorReturn("修改视频状态失败");
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return $this->recordingErrorReturn("未知事件");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除缓存
|
// 删除缓存
|
||||||
$redis->del($redis_key);
|
$redis->del($redis_key);
|
||||||
}catch (\Throwable $e){
|
}catch (\Throwable $e){
|
||||||
return $this->recordingErrorReturn($e->getMessage());
|
return $this->videoRecordingErrorReturn($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
Log::getInstance("CallBackController-videoTrtcCallBack")->info("音视频回调-房间数据处理成功");
|
Log::getInstance("CallBackController-videoRecordingCallBack")->info("音视频回调-云端录制处理成功");
|
||||||
return $this->TrtcSuccessReturn();
|
return $this->videoTrtcSuccessReturn();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2257,9 +2240,9 @@ class CallBackController extends AbstractController
|
|||||||
* @param string $message
|
* @param string $message
|
||||||
* @return ResponseInterface
|
* @return ResponseInterface
|
||||||
*/
|
*/
|
||||||
protected function recordingErrorReturn(string $message): ResponseInterface
|
protected function videoRecordingErrorReturn(string $message): ResponseInterface
|
||||||
{
|
{
|
||||||
Log::getInstance("CallBackController-videoTrtcCallBack")->error($message);
|
Log::getInstance("CallBackController-videoRecordingCallBack")->error($message);
|
||||||
return $this->response
|
return $this->response
|
||||||
->withStatus(200)
|
->withStatus(200)
|
||||||
->withBody(
|
->withBody(
|
||||||
@ -2278,7 +2261,7 @@ class CallBackController extends AbstractController
|
|||||||
* 音视频回调-云端录制-返回正确响应
|
* 音视频回调-云端录制-返回正确响应
|
||||||
* @return ResponseInterface
|
* @return ResponseInterface
|
||||||
*/
|
*/
|
||||||
protected function recordingSuccessReturn(): ResponseInterface
|
protected function videoRecordingSuccessReturn(): ResponseInterface
|
||||||
{
|
{
|
||||||
return $this->response
|
return $this->response
|
||||||
->withStatus(200)
|
->withStatus(200)
|
||||||
|
|||||||
@ -16,8 +16,12 @@ use Hyperf\Snowflake\Concern\Snowflake;
|
|||||||
* @property int $video_status 视频状态(1:已发起 2:患者进入房间 3:开始通话 4:结束)
|
* @property int $video_status 视频状态(1:已发起 2:患者进入房间 3:开始通话 4:结束)
|
||||||
* @property string $start_video_time 开始视频时间
|
* @property string $start_video_time 开始视频时间
|
||||||
* @property string $stop_video_time 结束视频时间
|
* @property string $stop_video_time 结束视频时间
|
||||||
* @property Carbon $created_at 创建时间
|
* @property string $vod_path_doctor 医生云点播路径
|
||||||
* @property Carbon $updated_at 修改时间
|
* @property string $vod_path_patient 患者云点播路径
|
||||||
|
* @property int $vod_save_status 云点播存储状态(0:未开始存储 1:成功 2:存储失败)
|
||||||
|
* @property string $vod_err_message 云点播存储失败原因
|
||||||
|
* @property \Carbon\Carbon $created_at 创建时间
|
||||||
|
* @property \Carbon\Carbon $updated_at 修改时间
|
||||||
*/
|
*/
|
||||||
class OrderInquiryVideoRecord extends Model
|
class OrderInquiryVideoRecord extends Model
|
||||||
{
|
{
|
||||||
@ -31,7 +35,7 @@ class OrderInquiryVideoRecord extends Model
|
|||||||
/**
|
/**
|
||||||
* The attributes that are mass assignable.
|
* The attributes that are mass assignable.
|
||||||
*/
|
*/
|
||||||
protected array $fillable = ['records_id', 'order_inquiry_id', 'room_id', 'video_status', 'start_video_time', 'stop_video_time', 'created_at', 'updated_at'];
|
protected array $fillable = ['records_id', 'order_inquiry_id', 'room_id', 'video_status', 'start_video_time', 'stop_video_time', 'vod_path_doctor', 'vod_path_patient', 'vod_save_status', 'vod_err_message', 'created_at', 'updated_at'];
|
||||||
|
|
||||||
protected string $primaryKey = "records_id";
|
protected string $primaryKey = "records_id";
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user