nginx rtmp thinkphp6权限控制

11 篇文章 0 订阅

参考:Directives · arut/nginx-rtmp-module Wiki · GitHub
文档中描述了可以添加事件

    on_connect
    on_play
    on_publish
    on_done
    on_play_done
    on_publish_done
    on_record_done
    on_update
    notify_update_timeout
    notify_update_strict
    notify_relay_redirect
    notify_method

在/etc/nginx/nginx.conf配置文件中添加事件接收处理

rtmp {
    server {
       ....
        notify_method post;
        publish_notify on;
        on_publish http://127.0.0.1:8326/api/vedio;
        ......
    }
}

thinkphp6使用swoole作为服务,因此可以直接连接,要注意的是不要使用http://localhost:8326/… 这样的路径进行访问,这样会导致OBS客户端连接失败

thinkphp添加路径

    // 视频控制路由
    Route::any('vedio', 'VedioNotice/serve');

建立控制器

namespace app\controller;

class VedioNotice extends BaseController
{
    /**
     * @return Response
     * @throws InvalidArgumentException
     * @throws BadRequestException
     * @author xaboy
     * @day 2020-04-26
     */
    public function serve()
    {
        $param = $this->request->post();
        Log::debug('post param:' . var_export($param, true));
        // throw new \Exception('禁止连接!!');
        return app('json')->success([
            'code' => '200'
        ]);
    }
}

使用OBS连接,带下如下参数
在这里插入图片描述

检查PHP日志,查看接收到的数据

param:array (
  'param1' => '1111',
  'param2' => '2222',
  'call' => 'publish',
  'name' => '12345677',
  'type' => 'live',
  'app' => 'song',
  'flashver' => 'FMLE/3.0 (compatible; FMSc/1.0)',
  'swfurl' => 'rtmp://173.154.216.128:1935/song',
  'tcurl' => 'rtmp://173.154.216.128:1935/song',
  'addr' => '173.154.216.1',
  'clientid' => '9',
)

从返回数据中可以分析:param1和param2可以传到PHP控制器中,需要如何限制权限,如何查数据库自己处理吧

如果用户名和密码不正确,抛个异常就可以限制推送了 throw new \Exception

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值