86 lines
2.8 KiB
PHP
86 lines
2.8 KiB
PHP
<?php
|
||
// +----------------------------------------------------------------------
|
||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||
// +----------------------------------------------------------------------
|
||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||
// | 开源版本可自由商用,可去除界面版权logo
|
||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||
// | 访问官网:https://www.likeadmin.cn
|
||
// | likeadmin团队 版权所有 拥有最终解释权
|
||
// +----------------------------------------------------------------------
|
||
// | author: likeadminTeam
|
||
// +----------------------------------------------------------------------
|
||
|
||
namespace app\api\controller;
|
||
|
||
use think\facade\Db;
|
||
use GuzzleHttp\Client;
|
||
use GuzzleHttp\Psr7\Request;
|
||
use GuzzleHttp\Exception\GuzzleException;
|
||
use Guzzle\Http\Exception\RequestException;
|
||
|
||
use Darabonba\OpenApi\OpenApiClient;
|
||
use AlibabaCloud\OpenApiUtil\OpenApiUtilClient;
|
||
use Darabonba\OpenApi\Models\Config;
|
||
use Darabonba\OpenApi\Models\Params;
|
||
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
|
||
use Darabonba\OpenApi\Models\OpenApiRequest;
|
||
use AlibabaCloud\SDK\Live\V20161101\Live;
|
||
|
||
|
||
/**
|
||
* 阿里云直播
|
||
* Class ZhiboController
|
||
*/
|
||
class ZhiboController extends BaseApiController
|
||
{
|
||
public array $notNeedLogin = ['createPushUrl', 'getPullUrl'];
|
||
|
||
// 推流host
|
||
private $push_host = 'rtmp://push-live.lihaink.cn';
|
||
// 拉流host
|
||
private $pull_host = 'rtmp://live.lihaink.cn';
|
||
// URL推流鉴权key
|
||
private $push_auth_key = '5WRlJV0QxK731AJe';
|
||
// URL拉流鉴权key
|
||
private $pull_auth_key = '59YEMIXP9260MZBe';
|
||
|
||
public function createPushUrl()
|
||
{
|
||
$uri = $this->push_host . '/app/ceshi';
|
||
$key = $this->push_auth_key;
|
||
$exp = time() + 3600;
|
||
$authuri = $this->authKey($uri, $key, $exp);
|
||
return $this->data([$authuri]);
|
||
}
|
||
|
||
public function getPullUrl()
|
||
{
|
||
$uri = $this->pull_host . '/app/ceshi';
|
||
$key = $this->pull_auth_key;
|
||
$exp = time() + 3600;
|
||
$authuri = $this->authKey($uri, $key, $exp);
|
||
return $this->data([$authuri]);
|
||
}
|
||
|
||
private function authKey($uri, $key, $exp) {
|
||
preg_match("/^(rtmp:\/\/)?([^\/?]+)?(\/[^?]*)?(\\?.*)?$/", $uri, $matches);
|
||
$scheme = $matches[1] ?? '';
|
||
$host = $matches[2] ?? '';
|
||
$path = $matches[3] ?? '';
|
||
if (empty($scheme)) {
|
||
$scheme ="rtmp://";
|
||
}
|
||
if (empty($path)) {
|
||
$path ="/";
|
||
}
|
||
$uid = $rand = "0";
|
||
$string = sprintf("%s-%u-%s-%s-%s", $path, $exp, $rand, $uid, $key);
|
||
$hashvalue = md5($string);
|
||
$auth_key = sprintf("%u-%s-%s-%s", $exp, $rand, $uid, $hashvalue);
|
||
return sprintf("%s%s%s?auth_key=%s", $scheme, $host, $path, $auth_key);
|
||
}
|
||
|
||
}
|