xielin лет назад: 5
Родитель
Сommit
08bf1a818e

+ 95 - 0
app/Http/Controllers/V1/AliYunVodController.php

@@ -0,0 +1,95 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019-06-15
+ * Time: 10:53
+ */
+
+namespace App\Http\Controllers\V1;
+
+
+use Illuminate\Http\Request;
+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()
+    {
+
+    }
+
+    /**
+     * 获取视频上传凭证信息
+     * @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',
+            'cover_url' => 'url'
+        ]);
+        if ($validator->fails()) {
+            return jsonError($validator->errors()->first());
+        }
+        $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);  //获取视频上传地址和凭证
+//            $result = $instance->refreshUploadVideo($videoId);  //刷新视频上传凭证
+//            $result = $instance->uploadMediaByURL($url, $title);  //url 拉去视屏上传
+            return $this->jsonSuccess($result);
+        } catch (\Exception $e) {
+            return $this->jsonError('获取上传凭证失败' . $e->getMessage());
+        }
+    }
+
+    public function getPlayUrlByVideoId(Request $request)
+    {
+        $request = $request->all();
+        $validator = Validator::make($request, [
+            'video_id' => 'required'
+        ]);
+        if ($validator->fails()) {
+            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);
+    }
+}

+ 1 - 1
app/Http/Controllers/V1/Controller.php

@@ -14,7 +14,7 @@ class Controller extends BaseController
         $response = array(
             'code' => 0,
             'msg' => $msg,
-            'data' => []
+            'data' => new \stdClass()
         );
         if ($data) {
             if (is_array($data)) {

+ 38 - 35
app/Http/Controllers/V1/PostController.php

@@ -22,7 +22,6 @@ use App\Transformers\Topic\TopicDetailTransformer;
 use App\Transformers\Topic\TopicListTransformer;
 use App\Transformers\Topic\TopicPostTransformer;
 use Illuminate\Http\Request;
-use Illuminate\Support\Carbon;
 use Illuminate\Support\Facades\Log;
 use Illuminate\Support\Facades\Redis;
 use Illuminate\Support\Facades\Validator;
@@ -36,6 +35,7 @@ class PostController extends Controller
 {
     use UserTrait;
     use CmsTrait;
+
     public function __construct(PostRepositories $postRepositories)
     {
         $this->postRepositories = $postRepositories;
@@ -47,7 +47,7 @@ class PostController extends Controller
     public function create(Request $request)
     {
         $validator = Validator::make($request->all(), [
-            'type' => ['required',Rule::in('image', 'video', 'html')],
+            'type' => ['required', Rule::in('image', 'video', 'html')],
             'img' => 'required|url',
             'video' => 'required_if:type,video|string|url',
             'topic_ids' => 'required|string|max:64',
@@ -60,7 +60,7 @@ class PostController extends Controller
             return jsonError($validator->errors()->first());
         }
 
-        return  $this->postRepositories->create($request->all());
+        return $this->postRepositories->create($request->all());
     }
 
     /**
@@ -76,7 +76,7 @@ class PostController extends Controller
             return jsonError($validator->errors()->first());
         }
 
-        return  $this->postRepositories->comment($request->all());
+        return $this->postRepositories->comment($request->all());
     }
 
     /**
@@ -85,7 +85,7 @@ class PostController extends Controller
     public function index(Request $request)
     {
         $userInfo = $this->getUserInfo();
-        if(empty($userInfo)){
+        if (empty($userInfo)) {
             Log::info('获取用户信息失败');
             return jsonError('获取用户信息失败');
         }
@@ -104,7 +104,7 @@ class PostController extends Controller
     public function video(Request $request)
     {
         $userInfo = $this->getUserInfo();
-        if(empty($userInfo)){
+        if (empty($userInfo)) {
             Log::info('获取用户信息失败');
             return jsonError('获取用户信息失败');
         }
@@ -123,14 +123,14 @@ class PostController extends Controller
     public function myPost(Request $request)
     {
         $validator = Validator::make($request->all(), [
-            'type' => ['required',Rule::in('create', 'collect', 'share')],
+            'type' => ['required', Rule::in('create', 'collect', 'share')],
         ]);
         if ($validator->fails()) {
             return jsonError($validator->errors()->first());
         }
 
         $userInfo = $this->getUserInfo();
-        if(empty($userInfo)){
+        if (empty($userInfo)) {
             Log::info('获取用户信息失败');
             return jsonError('获取用户信息失败');
         }
@@ -149,7 +149,7 @@ class PostController extends Controller
     public function suggestPost(Request $request)
     {
         $userInfo = $this->getUserInfo();
-        if(empty($userInfo)){
+        if (empty($userInfo)) {
             Log::info('获取用户信息失败');
             return jsonError('获取用户信息失败');
         }
@@ -161,54 +161,54 @@ class PostController extends Controller
         $resource->setPaginator(new IlluminatePaginatorAdapter($list));
         $data = $fractal->createData($resource)->toArray();
 
-        if(!(isset($param['current_page']) && $param['current_page'] > 1)){
+        if (!(isset($param['current_page']) && $param['current_page'] > 1)) {
             $key = 'suggest_post_floor';
             $floor = Redis::get($key);
-            if(!$floor){
+            if (!$floor) {
                 $floor = $this->getFloorInfo();
-                if($floor){
+                if ($floor) {
                     Redis::set($key, json_encode($floor));
                     Redis::expire($key, 600);
                 }
 
-            }else{
+            } else {
                 $floor = json_decode($floor, true);
             }
 
-            if($floor){
+            if ($floor) {
                 $newData = [];
-                foreach($data['data'] as $key => $val){
-                    if(isset($floor[$key+1])){
-                        if($floor[$key+1]['show_type'] == 'banner'){
+                foreach ($data['data'] as $key => $val) {
+                    if (isset($floor[$key + 1])) {
+                        if ($floor[$key + 1]['show_type'] == 'banner') {
                             $newData[] = [
                                 'show_type' => 'banner',
-                                'data' => $floor[$key+1]['data'],
+                                'data' => $floor[$key + 1]['data'],
                             ];
-                        }elseif($floor[$key+1]['show_type'] == 'user'){
-                            $uidArray = array_column($floor[$key+1]['data'], 'uid');
+                        } elseif ($floor[$key + 1]['show_type'] == 'user') {
+                            $uidArray = array_column($floor[$key + 1]['data'], 'uid');
                             $followMembersStatus = $this->getFollowMembersStatus(implode(',', $uidArray));
-                            if($followMembersStatus){
+                            if ($followMembersStatus) {
                                 $userData = [];
-                                foreach($floor[$key+1]['data'] as $item){
-                                    if(!isset($followMembersStatus[$item['uid']])) continue;
+                                foreach ($floor[$key + 1]['data'] as $item) {
+                                    if (!isset($followMembersStatus[$item['uid']])) continue;
                                     $userData[] = array_merge($item, ['follow_status' => $followMembersStatus[$item['uid']]['follow_status']]);
                                 }
-                                if($userData){
+                                if ($userData) {
                                     $newData[] = [
                                         'show_type' => 'user',
                                         'data' => $userData,
                                     ];
                                 }
                             }
-                        }elseif($floor[$key+1]['show_type'] == 'video'){
+                        } elseif ($floor[$key + 1]['show_type'] == 'video') {
                             $newData[] = [
                                 'show_type' => 'video',
-                                'data' => $floor[$key+1]['data'],
+                                'data' => $floor[$key + 1]['data'],
                             ];
-                        }elseif($floor[$key+1]['show_type'] == 'topic'){
+                        } elseif ($floor[$key + 1]['show_type'] == 'topic') {
                             $newData[] = [
                                 'show_type' => 'topic',
-                                'data' => $floor[$key+1]['data'],
+                                'data' => $floor[$key + 1]['data'],
                             ];
                         }
                     }
@@ -232,12 +232,12 @@ class PostController extends Controller
             return jsonError($validator->errors()->first());
         }
         $userInfo = $this->getUserInfo();
-        if(empty($userInfo)){
+        if (empty($userInfo)) {
             Log::info('获取用户信息失败');
             return jsonError('获取用户信息失败');
         }
         $detail = $this->postRepositories->detail($request['id']);
-        if(!$detail){
+        if (!$detail) {
             return jsonError('获取内容信息失败');
         }
         $fractal = new Manager();
@@ -315,12 +315,12 @@ class PostController extends Controller
             return jsonError($validator->errors()->first());
         }
         $userInfo = $this->getUserInfo();
-        if(empty($userInfo)){
+        if (empty($userInfo)) {
             Log::info('获取用户信息失败');
             return jsonError('获取用户信息失败');
         }
         $detail = $this->postRepositories->topicDetail($request['id']);
-        if(!$detail){
+        if (!$detail) {
             return jsonError('获取话题信息失败');
         }
         $fractal = new Manager();
@@ -336,7 +336,7 @@ class PostController extends Controller
     public function topicPost(Request $request)
     {
         $userInfo = $this->getUserInfo();
-        if(empty($userInfo)){
+        if (empty($userInfo)) {
             Log::info('获取用户信息失败');
             return jsonError('获取用户信息失败');
         }
@@ -380,8 +380,11 @@ class PostController extends Controller
         $data = $this->postRepositories->getPostVideo($request['ids']);
         return jsonSuccess($data);
     }
+
     //用户内容数统计
-    public function memberPostStatistics(Request $request){
-       return $this->postRepositories->memberPostStatistics();
+    public function memberPostStatistics(Request $request)
+    {
+        return $this->postRepositories->memberPostStatistics();
     }
+
 }

+ 1 - 0
bootstrap/app.php

@@ -33,6 +33,7 @@ $app->configure('jwt');
 $app->configure('database');
 $app->configure('elasticsearch');
 $app->configure('aliyun');
+$app->configure('aliyunvod');
 /*
 |--------------------------------------------------------------------------
 | Register Container Bindings

+ 6 - 5
composer.json

@@ -7,18 +7,19 @@
     "require": {
         "php": ">=7.1.3",
         "cviebrock/laravel-elasticsearch": "^3.5",
-        "php-amqplib/php-amqplib": "^2.9",
         "dingo/api": "^2.2",
         "guzzlehttp/guzzle": "^6.3",
         "illuminate/redis": "^5.8",
         "laravel/lumen-framework": "5.8.*",
         "league/fractal": "^0.17.0",
-        "predis/predis": "^1.1",
-        "tymon/jwt-auth": "1.0.0-rc.4.1",
-        "vlucas/phpdotenv": "^3.3",
         "moontoast/math": "^1.1",
+        "multilinguals/apollo-client": "^0.1.2",
+        "php-amqplib/php-amqplib": "^2.9",
+        "predis/predis": "^1.1",
+        "shaozeming/aliyun-vod": "^2.0",
         "tomcao/aliyuncs-green": "^1.1",
-        "multilinguals/apollo-client": "^0.1.2"
+        "tymon/jwt-auth": "1.0.0-rc.4.1",
+        "vlucas/phpdotenv": "^3.3"
     },
     "require-dev": {
         "fzaninotto/faker": "^1.4",

+ 20 - 0
config/aliyunvod.php

@@ -0,0 +1,20 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: shaozeming
+ * Date: 2019/3/9
+ * Time: 11:57 AM
+ */
+
+return [
+
+    /*点播配置*/
+    'vod' => [
+        'AccessKeyID' => 'LTAINdryz1AB0KpO',
+        'AccessKeySecret' => 'xjKm6yWIewMBQdJYC3H8CnuIOvBv8l',
+        'regionId' => 'cn-shanghai',   // 点播服务接入区域
+        'timeout' => '3600',  // 如果是获取签名有效时间为多少
+        'type' => 'access',  //类型:access|sts 如果是sts 实例化对象时候需要传入$securityToken
+        'acceptFormat' => 'JSON',  //返回数据格式
+    ],
+];

+ 2 - 0
routes/api.php

@@ -18,6 +18,8 @@ $api->version('v1', [
 ], function ($api) {
     //根据行为标识查询行为
     $api->get('getBehaviorByIdentify', 'BehaviorController@getBehaviorByIdentify');
+    $api->get('getVodUploadAuth', 'AliYunVodController@getVodUploadAuth');
+    $api->get('getPlayUrlByVideoId', 'AliYunVodController@getPlayUrlByVideoId');
     //登录+验签
     $api->group(['middleware' => ['chxq_jwt_auth']], function ($api) {
         //发布内容