1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <?php
- namespace App\Service;
- use Illuminate\Support\Facades\Log;
- use ShaoZeMing\AliVod\SDK\GetPlayInfoRequest;
- use ShaoZeMing\Aliyun\Core\DefaultAcsClient;
- use ShaoZeMing\Aliyun\Core\Profile\DefaultProfile;
- class AliYunVodService
- {
- public function getPlayUrlByVideoId($videoId)
- {
- try {
- $client = $this->initVodClient(config('aliyunvod.vod.AccessKeyID'), config('aliyunvod.vod.AccessKeySecret'));
- $playInfo = $this->getPlayInfo($client, $videoId);
- if($playInfo && is_object($playInfo)){
- return $playInfo->PlayInfoList->PlayInfo[0]->PlayURL;
- }else{
- return '';
- }
- } catch (\Exception $e) {
- Log::debug('获取视频地址失败:' . $e->getMessage());
- return '';
- }
- }
- private function initVodClient($accessKeyId, $accessKeySecret)
- {
- $regionId = 'cn-shanghai'; // 点播服务接入区域
- $profile = DefaultProfile::getProfile($regionId, $accessKeyId, $accessKeySecret);
- return new DefaultAcsClient($profile);
- }
- private function getPlayInfo($client, $videoId)
- {
- $request = new GetPlayInfoRequest();
- $request->setVideoId($videoId);
- $request->setAcceptFormat('JSON');
- $playConfig = ['PlayDomain' => 'http://oss.caihongxingqiu.net/'];
- $request->setPlayConfig(json_encode($playConfig));
- return $client->getAcsResponse($request);
- }
- }
|