|
@@ -0,0 +1,81 @@
|
|
|
|
+<?php
|
|
|
|
+/**
|
|
|
|
+ * Created by PhpStorm.
|
|
|
|
+ * User: Administrator
|
|
|
|
+ * Date: 2019-06-15
|
|
|
|
+ * Time: 10:53
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+namespace App\Http\Controllers;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+use App\Service\AliYunVodService;
|
|
|
|
+use function GuzzleHttp\Psr7\str;
|
|
|
|
+use Illuminate\Http\Request;
|
|
|
|
+use Illuminate\Http\Response;
|
|
|
|
+use Illuminate\Support\Facades\Log;
|
|
|
|
+use Illuminate\Support\Facades\Validator;
|
|
|
|
+use ShaoZeMing\AliVod\SDK\GetPlayInfoRequest;
|
|
|
|
+use ShaoZeMing\AliVod\Services\UploadService;
|
|
|
|
+use ShaoZeMing\Aliyun\Core\DefaultAcsClient;
|
|
|
|
+use ShaoZeMing\Aliyun\Core\Profile\DefaultProfile;
|
|
|
|
+
|
|
|
|
+class AliYunVodController extends Controller
|
|
|
|
+{
|
|
|
|
+ public function __construct(AliYunVodService $aliYunVodService)
|
|
|
|
+ {
|
|
|
|
+ $this->aliYunVodService = $aliYunVodService;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取视频上传凭证信息
|
|
|
|
+ * @param Request $request
|
|
|
|
+ * @return array
|
|
|
|
+ * @throws \ShaoZeMing\Aliyun\Core\Exception\ClientException
|
|
|
|
+ * @throws \ShaoZeMing\Aliyun\Core\Exception\ServerException
|
|
|
|
+ */
|
|
|
|
+ public function getVodUploadAuth(Request $request)
|
|
|
|
+ {
|
|
|
|
+ $request = $request->all();
|
|
|
|
+ $validator = Validator::make($request, [
|
|
|
|
+ 'title' => 'required',
|
|
|
|
+ 'filename' => 'required'
|
|
|
|
+ ]);
|
|
|
|
+ if ($validator->fails()) {
|
|
|
|
+ return $this->response->error($validator->errors()->first(),500);
|
|
|
|
+ }
|
|
|
|
+ $instance = new UploadService(config('aliyunvod'));
|
|
|
|
+ $title = $request['title'];
|
|
|
|
+ $filename = $request['filename'];
|
|
|
|
+ $coverUrl = isset($request['cover_url']) ?$request['cover_url']:'';
|
|
|
|
+ try {
|
|
|
|
+ $result = $instance->createUploadVideo($title, $filename, '', $coverUrl); //获取视频上传地址和凭证
|
|
|
|
+ $authInfo['UploadAddress'] = $result->UploadAddress;
|
|
|
|
+ $authInfo['VideoId'] = $result->VideoId;
|
|
|
|
+ $authInfo['RequestId'] = $result->RequestId;
|
|
|
|
+ $authInfo['UploadAuth'] = $result->UploadAuth;
|
|
|
|
+ return $authInfo;
|
|
|
|
+ } catch (\Exception $e) {
|
|
|
|
+ return $this->response->error('获取上传凭证失败' . $e->getMessage(),500);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * //根据videoId获取播放地址
|
|
|
|
+ * @param Request $request
|
|
|
|
+ * @return array|void
|
|
|
|
+ */
|
|
|
|
+ public function getPlayUrlByVideoId(Request $request)
|
|
|
|
+ {
|
|
|
|
+ $request = $request->all();
|
|
|
|
+ $validator = Validator::make($request, [
|
|
|
|
+ 'video_id' => 'required'
|
|
|
|
+ ]);
|
|
|
|
+ if ($validator->fails()) {
|
|
|
|
+ return $this->response->error($validator->errors()->first(),500);
|
|
|
|
+ }
|
|
|
|
+ $videoId = $request['video_id'];
|
|
|
|
+ $url = $this->aliYunVodService->getPlayUrlByVideoId($videoId);
|
|
|
|
+ return ['url'=>$url];
|
|
|
|
+ }
|
|
|
|
+}
|