From fcfb84e6c6d07c945e8306dd7cd64ea2a0e7f021 Mon Sep 17 00:00:00 2001 From: wucongxing <815046773@qq.com> Date: Wed, 31 Jan 2024 09:12:27 +0800 Subject: [PATCH] 1 --- app/Controller/CallBackController.php | 41 ++++++++++++++++++--------- extend/TencentVideo/Safe.php | 4 ++- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/app/Controller/CallBackController.php b/app/Controller/CallBackController.php index cb592d8..3b68ddc 100644 --- a/app/Controller/CallBackController.php +++ b/app/Controller/CallBackController.php @@ -1711,10 +1711,9 @@ class CallBackController extends AbstractController */ public function trtcRoomCallBack(): ResponseInterface { - $request_params = $this->request->all(); + $request_params = $this->request->getBody()->getContents(); $SdkAppId = $this->request->header("SdkAppId"); $Sign = $this->request->header("Sign"); - try { Log::getInstance("CallBackController-trtcRoomCallBack")->info(json_encode($request_params, JSON_UNESCAPED_UNICODE)); Log::getInstance("CallBackController-trtcRoomCallBack")->info(json_encode($SdkAppId, JSON_UNESCAPED_UNICODE)); @@ -1728,15 +1727,19 @@ class CallBackController extends AbstractController return $this->TrtcErrorReturn("缺少签名字段"); } -// // 鉴定回调签名 -// $VideoSafe = new VideoSafe(); -// $result = $VideoSafe->validateSign($request_params,$Sign); + // 鉴定回调签名 + $VideoSafe = new VideoSafe(); + $result = $VideoSafe->validateSign($request_params,$Sign); + dump($result); // if (!$result) { -// return $this->ImErrorReturn("回调签名不匹配"); +// return $this->TrtcErrorReturn("回调签名不匹配"); // } + + $request_params = json_decode($request_params,true); + die; - if (empty($request_params['CallbackCommand'])){ + if (empty($request_params['EventGroupId'])){ return $this->ImErrorReturn("回调事件为空"); } @@ -1767,14 +1770,14 @@ class CallBackController extends AbstractController } /** - * 音视频回调-房间 + * 音视频回调-媒体 * @return ResponseInterface * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ public function trtcMediaCallBack(): ResponseInterface { - $request_params = $this->request->all(); + $request_params = $this->request->getBody()->getContents(); $SdkAppId = $this->request->header("SdkAppId"); $Sign = $this->request->header("Sign"); @@ -1791,12 +1794,24 @@ class CallBackController extends AbstractController return $this->TrtcErrorReturn("缺少签名字段"); } -// // 鉴定回调签名 -// $VideoSafe = new VideoSafe(); -// $result = $VideoSafe->validateSign($request_params,$Sign); + // 鉴定回调签名 + $VideoSafe = new VideoSafe(); + $result = $VideoSafe->validateSign($request_params,$Sign); + dump($result); // if (!$result) { -// return $this->ImErrorReturn("回调签名不匹配"); +// return $this->TrtcErrorReturn("回调签名不匹配"); // } + + $request_params = json_decode($request_params,true); + + die; + + // 鉴定回调签名 + $VideoSafe = new VideoSafe(); + $result = $VideoSafe->validateSign($request_params,$Sign); + if (!$result) { + return $this->TrtcErrorReturn("回调签名不匹配"); + } die; if (empty($request_params['CallbackCommand'])){ diff --git a/extend/TencentVideo/Safe.php b/extend/TencentVideo/Safe.php index 6210644..3f54464 100644 --- a/extend/TencentVideo/Safe.php +++ b/extend/TencentVideo/Safe.php @@ -29,9 +29,11 @@ class Safe extends Base throw new BusinessException("Video Token Config Error"); } - $hash = hash_hmac( 'sha256', $body, $token, true ); + $hash = hash_hmac( 'sha256', $body, "123654", true ); $sys_sign = base64_encode($hash); + dump($sign); + dump($sys_sign); if ($sign != $sys_sign) { return false; }