You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
131 lines
5.1 KiB
131 lines
5.1 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | 天诚科技 [ 刘海东 17600099397赋能开发者,助力企业发展 ]
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2016~2020 https://www.tczxkj.com All rights reserved.
|
|
// +----------------------------------------------------------------------
|
|
// | Licensed 该系统并不是自由软件,未经许可不能去掉相关版权
|
|
// +----------------------------------------------------------------------
|
|
// | Author:甘肃天诚志信电子商务有限公司 刘海东 联系电话维系17600099397
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace service;
|
|
|
|
use think\Request;
|
|
use service\JsonService;
|
|
|
|
class VodService
|
|
{
|
|
|
|
protected static $method = 'GET'; //获取方式
|
|
|
|
protected static $AccessKeyId = ''; //阿里云AccessKeyId
|
|
|
|
protected static $accessKeySecret = ''; //阿里云AccessKeySecret
|
|
|
|
|
|
final static function init()
|
|
{
|
|
self::$AccessKeyId = SystemConfigService::get('accessKeyId');//阿里云AccessKeyId
|
|
self::$accessKeySecret = SystemConfigService::get('accessKeySecret');//阿里云AccessKeySecret
|
|
if (self::$AccessKeyId == '' || self::$accessKeySecret == '') return JsonService::fail('阿里云AccessKeyId或阿里云AccessKeySecret没有配置');
|
|
}
|
|
|
|
/**获取视频上传地址和凭证
|
|
* @param string $videoId
|
|
* @param string $FileName
|
|
* @param string $type 1=获取视频上传凭证 2=获取视频播放凭证 3=获取视频播放地址 4=删除完整视频
|
|
*/
|
|
public static function videoUploadAddressVoucher($FileName = '', $type = 1, $videoId = '', $image = '')
|
|
{
|
|
self::init();
|
|
$apiParams = [];
|
|
$site_url = SystemConfigService::get('site_url');
|
|
$region = SystemConfigService::get('configuration_item_region');
|
|
$cate_id = SystemConfigService::get('cate_id');
|
|
if ($site_url) {
|
|
$arr = parse_url($site_url);
|
|
if ($arr['scheme']) {
|
|
$scheme = $arr['scheme'];
|
|
} else {
|
|
$scheme = 'http';
|
|
}
|
|
} else {
|
|
$scheme = 'http';
|
|
}
|
|
$requestUrl = $scheme . '://vod.' . $region . '.aliyuncs.com/?';
|
|
if ($videoId != '' && $type == 1) {
|
|
$apiParams['Action'] = 'RefreshUploadVideo';
|
|
$apiParams['VideoId'] = $videoId;
|
|
} else if ($videoId != '' && $type == 2) {
|
|
$apiParams['Action'] = 'GetVideoPlayAuth';
|
|
$apiParams['VideoId'] = $videoId;
|
|
} else if ($videoId != '' && $type == 3) {
|
|
$apiParams['Action'] = 'GetPlayInfo';
|
|
$apiParams['VideoId'] = $videoId;
|
|
} else if ($videoId != '' && $type == 4) {
|
|
$apiParams['Action'] = 'DeleteVideo';
|
|
$apiParams['VideoIds'] = $videoId;
|
|
} else if ($videoId == '' && $type == 1) {
|
|
$apiParams['Action'] = 'CreateUploadVideo';
|
|
$apiParams['Title'] = self::video_name($FileName);
|
|
$apiParams['FileName'] = $FileName;
|
|
$apiParams['CoverURL'] = $image;
|
|
$apiParams['CateId'] = $cate_id;
|
|
}
|
|
$apiParams['AccessKeyId'] = self::$AccessKeyId;
|
|
$apiParams['Format'] = 'JSON';
|
|
$apiParams['SignatureMethod'] = 'HMAC-SHA1';
|
|
$apiParams['SignatureVersion'] = '1.0';
|
|
$apiParams['SignatureNonce'] = md5(uniqid(mt_rand(), true));
|
|
$apiParams['Timestamp'] = gmdate('Y-m-d\TH:i:s\Z');
|
|
$apiParams['Version'] = '2017-03-21';
|
|
$apiParams['Signature'] = self::computeSignature($apiParams, self::$accessKeySecret);
|
|
foreach ($apiParams as $apiParamKey => $apiParamValue) {
|
|
$requestUrl .= "$apiParamKey=" . urlencode($apiParamValue) . '&';
|
|
}
|
|
return substr($requestUrl, 0, -1);
|
|
}
|
|
|
|
public static function signString($source, $accessSecret)
|
|
{
|
|
return base64_encode(hash_hmac('sha1', $source, $accessSecret, true));
|
|
}
|
|
|
|
/**
|
|
* 视频名称
|
|
*/
|
|
public static function video_name($FileName)
|
|
{
|
|
return mb_substr(substr($FileName, strrpos($FileName, '.') + 1), 0, 128, 'utf8');
|
|
}
|
|
|
|
/**签名机制
|
|
* @param $parameters
|
|
* @param $accessKeySecret
|
|
* @return mixed
|
|
*/
|
|
public static function computeSignature($parameters, $accessKeySecret)
|
|
{
|
|
ksort($parameters);
|
|
$canonicalizedQueryString = '';
|
|
foreach ($parameters as $key => $value) {
|
|
$canonicalizedQueryString .= '&' . self::percentEncode($key) . '=' . self::percentEncode($value);
|
|
}
|
|
$stringToBeSigned =
|
|
self::$method . '&%2F&' . self::percentEncode(substr($canonicalizedQueryString, 1));
|
|
return self::signString($stringToBeSigned, $accessKeySecret . '&');
|
|
}
|
|
|
|
/**
|
|
* @param $str
|
|
* @return string|string[]|null
|
|
*/
|
|
public static function percentEncode($str)
|
|
{
|
|
$res = urlencode($str);
|
|
$res = str_replace(array('+', '*'), array('%20', '%2A'), $res);
|
|
$res = preg_replace('/%7E/', '~', $res);
|
|
return $res;
|
|
}
|
|
}
|
|
|