增加回调log
This commit is contained in:
@@ -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)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user