|
@@ -10,6 +10,7 @@ namespace App\Http\Controllers\V1;
|
|
|
|
|
|
|
|
|
use App\Repositories\FeedRepositories;
|
|
|
+use App\Service\AliYunVodService;
|
|
|
use Illuminate\Http\Request;
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
use Illuminate\Support\Facades\Validator;
|
|
@@ -20,9 +21,10 @@ use ShaoZeMing\Aliyun\Core\Profile\DefaultProfile;
|
|
|
|
|
|
class AliYunVodController extends Controller
|
|
|
{
|
|
|
- public function __construct(FeedRepositories $feedRepositories)
|
|
|
+ public function __construct(FeedRepositories $feedRepositories,AliYunVodService $aliYunVodService)
|
|
|
{
|
|
|
$this->feedRepositories = $feedRepositories;
|
|
|
+ $this->aliYunVodService = $aliYunVodService;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -66,30 +68,7 @@ class AliYunVodController extends Controller
|
|
|
return jsonError($validator->errors()->first());
|
|
|
}
|
|
|
$videoId = $request['video_id'];
|
|
|
- try {
|
|
|
- $client = $this->initVodClient(config('aliyunvod.vod.AccessKeyID'), config('aliyunvod.vod.AccessKeySecret'));
|
|
|
- $playInfo = $this->getPlayInfo($client, $videoId);
|
|
|
- return $this->jsonSuccess($playInfo);
|
|
|
- } catch (\Exception $e) {
|
|
|
- Log::debug('获取视频地址失败:' . $e->getMessage());
|
|
|
- return $this->jsonError('获取视频地址失败');
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- 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);
|
|
|
+ $url = $this->aliYunVodService->getPlayUrlByVideoId($videoId);
|
|
|
+ return $this->jsonSuccess(['url'=>$url]);
|
|
|
}
|
|
|
}
|