TaskSystem/app/api/controller/ZhiboController.php

86 lines
2.8 KiB
PHP
Raw Normal View History

2023-10-16 14:09:55 +08:00
<?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;
2023-10-16 19:28:42 +08:00
use GuzzleHttp\Client;
2023-10-16 14:09:55 +08:00
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Exception\GuzzleException;
use Guzzle\Http\Exception\RequestException;
2023-10-16 19:28:42 +08:00
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;
2023-10-16 14:09:55 +08:00
/**
2023-10-16 19:28:42 +08:00
* 阿里云直播
2023-10-16 14:09:55 +08:00
* Class ZhiboController
*/
class ZhiboController extends BaseApiController
{
2023-10-16 19:28:42 +08:00
public array $notNeedLogin = ['createPushUrl', 'getPullUrl'];
2023-10-16 14:09:55 +08:00
2023-10-16 19:28:42 +08:00
// 推流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';
2023-10-16 14:09:55 +08:00
2023-10-16 19:28:42 +08:00
public function createPushUrl()
2023-10-16 14:09:55 +08:00
{
2023-10-16 19:28:42 +08:00
$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);
2023-10-16 14:09:55 +08:00
}
}