8000 Dev by Qsnh · Pull Request #90 · Qsnh/meedu · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Dev #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 31, 2020
Merged

Dev #90

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ DB_USERNAME=root
DB_PASSWORD=root

BROADCAST_DRIVER=log
CACHE_DRIVER=file
CACHE_DRIVER=database
SESSION_DRIVER=file
SESSION_LIFETIME=120
QUEUE_DRIVER=database
Expand Down
8 changes: 6 additions & 2 deletions app/Constant/ApiV2Constant.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class ApiV2Constant
const MOBILE_OR_PASSWORD_ERROR = 'mobile not exists or password error';
const MOBILE_CODE_ERROR = 'mobile code error';

const VIDEO_NO_AUTH = 'please buy this video before see';

const SMS_CODE_EXPIRE = 60;
const MOBILE_CODE_CACHE_KEY = 'm:%s';

Expand Down Expand Up @@ -144,11 +146,12 @@ class ApiV2Constant
* @OA\Property(property="id",type="integer",description="id"),
* @OA\Property(property="user_id",type="integer",description="用户id"),
* @OA\Property(property="render_content",type="string",description="评论内容"),
* @OA\Property(property="created_at",type="string",description="时间"),
* ),
* )
*/
const MODEL_COURSE_COMMENT_FIELD = [
'id', 'user_id', 'render_content',
'id', 'user_id', 'render_content', 'created_at',
];
/**
* @OpenApi\Annotations\Schemas(
Expand All @@ -159,11 +162,12 @@ class ApiV2Constant
* @OA\Property(property="id",type="integer",description="id"),
* @OA\Property(property="user_id",type="integer",description="用户id"),
* @OA\Property(property="render_content",type="string",description="评论内容"),
* @OA\Property(property="created_at",type="string",description="时间"),
* ),
* )
*/
const MODEL_VIDEO_COMMENT_FIELD = [
'id', 'user_id', 'render_content',
'id', 'user_id', 'render_content', 'created_at',
];
const MODEL_ORDER_FIELD = [
'user_id', 'charge', 'order_id', 'payment_method', 'status_text', 'payment_text', 'continue_pay',
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Api/V2/CourseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function detail($id)
$chapters = $this->courseService->chapters($course['id']);
$chapters = arr2_clear($chapters, ApiV2Constant::MODEL_COURSE_CHAPTER_FIELD);
$videos = $this->videoService->courseVideos($course['id']);
$videos = arr2_clear($videos, ApiV2Constant::MODEL_VIDEO_FIELD);
$videos = arr2_clear($videos, ApiV2Constant::MODEL_VIDEO_FIELD, true);

return $this->data(compact('course', 'chapters', 'videos'));
}
Expand Down
61 changes: 56 additions & 5 deletions app/Http/Controllers/Api/V2/VideoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@
/**
* @OpenApi\Annotations\Schemas(
* @OA\Schema(
* schema="VideoPlay",
* schema="PlayUrlItem",
* type="object",
* title="视频播放地址",
* @OA\Property(property="url",type="string",description="视频播放地址"),
* @OA\Property(property="extension",type="string",description="视频格式"),
* @OA\Property(property="format",type="string",description="视频格式"),
* @OA\Property(property="duration",type="integer",description="时长,秒"),
* ),
* )
*/
Expand Down Expand Up @@ -160,7 +161,7 @@ public function detail($id)
$chapters = $this->courseService->chapters($video['course_id']);
$chapters = arr2_clear($chapters, ApiV2Constant::MODEL_COURSE_CHAPTER_FIELD);
$videos = $this->videoService->courseVideos($video['course_id']);
$videos = arr2_clear($videos, ApiV2Constant::MODEL_VIDEO_FIELD);
$videos = arr2_clear($videos, ApiV2Constant::MODEL_VIDEO_FIELD, true);

return $this->data([
'video' => $video,
Expand Down Expand Up @@ -235,8 +236,58 @@ public function comments($id)
]);
}

public function playInfo()
/**
* @OA\Get(
* path="/video/{id}/playinfo",
* @OA\Parameter(in="path",name="id",description="视频id",required=true,@OA\Schema(type="integer")),
* summary="视频播放地址",
* tags={"视频"},
* @OA\Response(
* description="",response=200,
* @OA\JsonContent(
* @OA\Property(property="code",type="integer",description="状态码"),
* @OA\Property(property="message",type="string",description="消息"),
* @OA\Property(property="data",type="object",description="",
* @OA\Property(property="urls",type="array",description="播放地址",@OA\Items(ref="#/components/schemas/PlayUrlItem")),
* ),
* )
* )
* )
* @param $id
* @return \Illuminate\Http\JsonResponse
*/
public function playInfo($id)
{
// todo 视频播放信息
$video = $this->videoService->find($id);
$course = $this->courseService->find($video['course_id']);
if (!$this->businessState->canSeeVideo($this->user(), $course, $video)) {
return $this->error(__(ApiV2Constant::VIDEO_NO_AUTH));
}

$urls = [];

if ($video['url']) {
// 直链
$pathinfo = @pathinfo($video['url']);
$urls = [
[
'format' => $pathinfo['extension'] ?? '',
'url' => $video['url'],
'duration' => $video['duration'],
]
];
} elseif ($video['aliyun_video_id']) {
// 阿里云点播
$urls = aliyun_play_url($video['aliyun_video_id']);
} elseif ($video['tencent_video_id']) {
// 腾讯云点播
$urls = get_tencent_play_url($video['tencent_video_id']);
}

if (!$urls) {
return $this->error(__('error'));
}

return $this->data(compact('urls'));
}
}
38 changes: 0 additions & 38 deletions app/Models/Video.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,42 +176,4 @@ public function commentHandler(string $content)

return $comment;
}

/**
* 获取视频的播放地址[阿里云|本地].
*
* @return array
*/
public function getPlayInfo()
{
if ($this->aliyun_video_id != '') {
$playInfo = aliyun_play_url($this);
Log::info(json_encode($playInfo));

return $playInfo;
}

return [
[
'format' => pathinfo($this->url, PATHINFO_EXTENSION),
'url' => $this->url,
'duration' => 0,
],
];
}

/**
* 获取视频播放地址
*
* @return mixed
*/
public function getPlayUrl()
{
if ($this->url) {
return $this->url;
}
$playInfo = aliyun_play_url($this);

return isset($playInfo[0]) ? $playInfo[0]['url'] : '';
}
}
8 changes: 8 additions & 0 deletions app/Services/Base/Services/ConfigService.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,12 @@ public function getMemberInviteConfig(): array
{
return config('meedu.member.invite');
}

/**
* @return array
*/
public function getTencentVodConfig(): array
{
return config('tencent.vod');
}
}
63 changes: 52 additions & 11 deletions app/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,20 +184,15 @@ function aliyun_play_auth($video)
if (!function_exists('aliyun_play_url')) {
/**
* 获取阿里云的视频播放地址
*
* @param \App\Models\Video $video
*
* @param $vid
* @return array
*/
function aliyun_play_url(\App\Models\Video $video)
function aliyun_play_url($vid)
{
if (!$video->aliyun_video_id) {
return [];
}
try {
$client = aliyun_sdk_client();
$request = new \vod\Request\V20170321\GetPlayInfoRequest();
$request->setVideoId($video->aliyun_video_id);
$request->setVideoId($vid);
$request->setAuthTimeout(3600 * 3);
$request->setAcceptFormat('JSON');
$response = $client->getAcsResponse($request);
Expand Down Expand Up @@ -445,12 +440,58 @@ function arr1_clear($arr, $columns)
/**
* @param $arr
* @param $columns
* @param bool $rec
* @return array
*/
function arr2_clear($arr, $columns)
function arr2_clear($arr, $columns, $rec = false)
{
return array_map(function ($item) use ($columns) {
return \Illuminate\Support\Arr::only($item, $columns);
return array_map(function ($item) use ($columns, $rec) {
if (!$rec) {
return \Illuminate\Support\Arr::only($item, $columns);
}
return array_map(function ($item) use ($columns) {
return \Illuminate\Support\Arr::only($item, $columns);
}, $item);
}, $arr);
}
}

if (!function_exists('get_tencent_play_url')) {
function get_tencent_play_url(string $vid): array
{
try {
/**
* @var $configService \App\Services\Base\Services\ConfigService
*/
$configService = app()->make(\App\Services\Base\Interfaces\ConfigServiceInterface::class);
$config = $configService->getTencentVodConfig();
$credential = new \TencentCloud\Common\Credential($config['secret_id'], $config['secret_key']);
$client = new \TencentCloud\Vod\V20180717\VodClient($credential, '');
$req = new \TencentCloud\Vod\V20180717\Models\DescribeMediaInfosRequest();
$req->FileIds[] = $vid;
$req->Filters = ['basicInfo'];
/**
* @var $response \TencentCloud\Vod\V20180717\Models\DescribeMediaInfosResponse
*/
$response = $client->DescribeMediaInfos($req);
if (!$response->MediaInfoSet) {
return [];
}
/**
* @var $mediaBasicInfo \TencentCloud\Vod\V20180717\Models\MediaBasicInfo
*/
$mediaBasicInfo = $response->MediaInfoSet[0]->BasicInfo;
return [
[
'format' => $mediaBasicInfo->Type,
'url' => $mediaBasicInfo->MediaUrl,
'duration' => 0,
]
];
} catch (Exception $exception) {
exception_record($exception);

return [];
}
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"socialiteproviders/qq": "^3.0",
"socialiteproviders/weixin-web": "dev-master",
"spatie/laravel-backup": "5.10.1",
"tencentcloud/tencentcloud-sdk-php": "^3.0",
"tymon/jwt-auth": "1.0.0-rc.5",
"yansongda/laravel-pay": "^2.0",
"zgldh/qiniu-laravel-storage": "^0.10.3"
Expand Down
62 changes: 56 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
0