赞
踩
<?php /** * Created by PhpStorm. * User: chentaohua * Date: 2020/3/14 * Time: 15:40 */ namespace App\Http\Lib; class AliVod{ protected $regionId = 'cn-shanghai'; /** * 获取播放凭证 * @param string $videoId * @throws \ClientException * @throws \ServerException * @return object */ public function getPlayAuth($videoId){ // 初始化 $client = $this -> initClient(); // 获取播放凭证 $request = new \vod\Request\V20170321\GetVideoPlayAuthRequest(); // 获取播放信息 加密视频不可用 //$request = new \vod\Request\V20170321\GetPlayInfoRequest(); // 设置返回格式和地区 $request->setAcceptFormat('JSON'); $request->setRegionId($this -> regionId); $request->setVideoId($videoId); $response = $client->getAcsResponse($request); return json_decode(json_encode($response),true); } /** * 初始化客户端 */ protected function initClient(){ // 引入配置文件 require_once dirname(__DIR__) . '/Lib/voduploadsdk/aliyun-php-sdk-core/Config.php'; date_default_timezone_set('PRC'); $profile = \DefaultProfile::getProfile($this -> regionId, config('app.ALI_ACCESS_KEY_ID_VOD'), config('app.ALI_ACCESS_KEY_SECRET_VOD')); return new \DefaultAcsClient($profile); } }
use App\Http\Lib\AliVod;
$vodObj = new AliVod();
$res = $vodObj -> getPlayAuth($ali_video_id);
if(!isset($res['PlayAuth'])){
throw new \Exception('获取播放凭证失败!');
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。