增加回调log

This commit is contained in:
2024-01-30 11:03:40 +08:00
parent 2005b6eefc
commit a065f5e3a5
10 changed files with 866 additions and 8 deletions
+169
View File
@@ -61,6 +61,7 @@ use Hyperf\Utils\ApplicationContext;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\ResponseInterface;
use Extend\TencentVideo\Safe as VideoSafe;
class CallBackController extends AbstractController
{
@@ -1702,4 +1703,172 @@ class CallBackController extends AbstractController
);
}
/**
* 音视频回调-房间
* @return ResponseInterface
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function trtcRoomCallBack(): ResponseInterface
{
$request_params = $this->request->all();
$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));
Log::getInstance("CallBackController-trtcRoomCallBack")->info(json_encode($Sign, JSON_UNESCAPED_UNICODE));
if (empty($SdkAppId)) {
return $this->TrtcErrorReturn("缺少SdkAppId字段");
}
if (empty($Sign)) {
return $this->TrtcErrorReturn("缺少签名字段");
}
// // 鉴定回调签名
// $VideoSafe = new VideoSafe();
// $result = $VideoSafe->validateSign($request_params,$Sign);
// if (!$result) {
// return $this->ImErrorReturn("回调签名不匹配");
// }
die;
if (empty($request_params['CallbackCommand'])){
return $this->ImErrorReturn("回调事件为空");
}
$userService = new UserService();
if ($request_params['CallbackCommand'] == "State.StateChange"){
// 用户状态变更
$result = $userService->userImLoginStatus($request_params);
if ($result['code'] == 0){
return $this->ImErrorReturn($result['message']);
}
}elseif ($request_params['CallbackCommand'] == "C2C.CallbackAfterSendMsg"){
// 用户im消息发送后回调
$result = $userService->userImAfterSendMsg($request_params);
if ($result['code'] == 0){
return $this->ImErrorReturn($result['message']);
}
}else{
return $this->ImErrorReturn("非法事件");
}
} catch (\Exception $e) {
// 验证失败
return $this->ImErrorReturn($e->getMessage());
}
Log::getInstance()->info("Im回调数据处理成功");
return $this->ImSuccessReturn();
}
/**
* 音视频回调-房间
* @return ResponseInterface
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function trtcMediaCallBack(): ResponseInterface
{
$request_params = $this->request->all();
$SdkAppId = $this->request->header("SdkAppId");
$Sign = $this->request->header("Sign");
try {
Log::getInstance("CallBackController-trtcMediaCallBack")->info(json_encode($request_params, JSON_UNESCAPED_UNICODE));
Log::getInstance("CallBackController-trtcMediaCallBack")->info(json_encode($SdkAppId, JSON_UNESCAPED_UNICODE));
Log::getInstance("CallBackController-trtcMediaCallBack")->info(json_encode($Sign, JSON_UNESCAPED_UNICODE));
if (empty($SdkAppId)) {
return $this->TrtcErrorReturn("缺少SdkAppId字段");
}
if (empty($Sign)) {
return $this->TrtcErrorReturn("缺少签名字段");
}
// // 鉴定回调签名
// $VideoSafe = new VideoSafe();
// $result = $VideoSafe->validateSign($request_params,$Sign);
// if (!$result) {
// return $this->ImErrorReturn("回调签名不匹配");
// }
die;
if (empty($request_params['CallbackCommand'])){
return $this->ImErrorReturn("回调事件为空");
}
$userService = new UserService();
if ($request_params['CallbackCommand'] == "State.StateChange"){
// 用户状态变更
$result = $userService->userImLoginStatus($request_params);
if ($result['code'] == 0){
return $this->ImErrorReturn($result['message']);
}
}elseif ($request_params['CallbackCommand'] == "C2C.CallbackAfterSendMsg"){
// 用户im消息发送后回调
$result = $userService->userImAfterSendMsg($request_params);
if ($result['code'] == 0){
return $this->ImErrorReturn($result['message']);
}
}else{
return $this->ImErrorReturn("非法事件");
}
} catch (\Exception $e) {
// 验证失败
return $this->ImErrorReturn($e->getMessage());
}
Log::getInstance()->info("Im回调数据处理成功");
return $this->ImSuccessReturn();
}
/**
* 音视频返回错误响应
* @param string $message
* @return ResponseInterface
*/
protected function TrtcErrorReturn(string $message): ResponseInterface
{
Log::getInstance("CallBackController-trtcRoomCallBack")->error($message);
return $this->response
->withStatus(200)
->withBody(
new SwooleStream(
strval(
json_encode([
'code' => 0,
'ErrorInfo' => $message,
], JSON_UNESCAPED_UNICODE)
)
)
);
}
/**
* 音视频返回正确响应
* @return ResponseInterface
*/
protected function TrtcSuccessReturn(): ResponseInterface
{
return $this->response
->withStatus(200)
->withBody(
new SwooleStream(
strval(
json_encode([
'code' => 0,
'ErrorInfo' => "",
], JSON_UNESCAPED_UNICODE)
)
)
);
}
}
+11 -2
View File
@@ -29,8 +29,6 @@ class SafeController extends AbstractController
/**
* 获取im签名数据
* @return ResponseInterface
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function getImSign(): ResponseInterface
{
@@ -38,4 +36,15 @@ class SafeController extends AbstractController
$data = $SafeService->getImSign();
return $this->response->json($data);
}
/**
* 获取音视频签名数据
* @return ResponseInterface
*/
public function getVideoSign(): ResponseInterface
{
$SafeService = new SafeService();
$data = $SafeService->getVideoSign();
return $this->response->json($data);
}
}
+32 -2
View File
@@ -10,7 +10,8 @@ use App\Model\UserPatient;
use App\Model\UserPharmacist;
use Extend\Alibaba\Oss;
use Extend\TencentIm\Account;
use Extend\TencentIm\Safe;
use Extend\TencentIm\Safe as ImSafe;
use Extend\TencentVideo\Safe as VideoSafe;
/**
* 安全服务
@@ -99,7 +100,36 @@ class SafeService extends BaseService
return success();
}
$safe = new Safe();
$safe = new ImSafe();
$sign = $safe->getUserSign($user['user_id']);
if (empty($sign)){
return success();
}
return success($sign);
}
/**
* 获取音视频签名数据
* @return array
*/
public function getVideoSign(): array
{
$user_info = $this->request->getAttribute("userInfo") ?? [];
if (empty($user_info)){
return success();
}
// 验证用户数据
$params = array();
$params['user_id'] = $user_info['user_id'];
$user = User::getOne($params);
if (empty($user)){
return success();
}
$safe = new VideoSafe();
$sign = $safe->getUserSign($user['user_id']);
if (empty($sign)){
return success();
+10
View File
@@ -0,0 +1,10 @@
<?php
namespace App\Services;
use App\Exception\BusinessException;
use Extend\TencentVideo\Safe as VideoSafe;
class VideoService extends BaseService
{
}