190 lines
6.9 KiB
PHP
190 lines
6.9 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Services;
|
||
|
|
use App\Utils\Str;
|
||
|
|
use AlibabaCloud\Client\AlibabaCloud;
|
||
|
|
use AlibabaCloud\Client\Exception\ClientException;
|
||
|
|
use AlibabaCloud\Client\Exception\ServerException;
|
||
|
|
use App\Http\Response\ResponseJson;
|
||
|
|
class AliyunService
|
||
|
|
{
|
||
|
|
use ResponseJson;
|
||
|
|
/**
|
||
|
|
* 实名认证
|
||
|
|
* @param [type] $user_id [description]
|
||
|
|
* @param [type] $name [description]
|
||
|
|
* @param [type] $card_num [description]
|
||
|
|
* @return [type] [description]
|
||
|
|
*/
|
||
|
|
public function aliCheckInfoV2($user_id, $name, $card_num)
|
||
|
|
{
|
||
|
|
$host = "https://safrvcert.market.alicloudapi.com";
|
||
|
|
$path = "/safrv_2meta_id_name/";
|
||
|
|
$method = "GET";
|
||
|
|
$appcode = "ad41385e76184cffab0a5dc7654f8db2";
|
||
|
|
$headers = array();
|
||
|
|
array_push($headers, "Authorization:APPCODE " . $appcode);
|
||
|
|
$__userId = "35102108";
|
||
|
|
$customerID = $user_id;
|
||
|
|
$identifyNum = $card_num;
|
||
|
|
$userName = Str::trimall($name);
|
||
|
|
$verifyKey = "IV9DIyZ52DsOUC";
|
||
|
|
$querys = "__userId=".$__userId."&customerID=".$customerID."&identifyNum=".$identifyNum."&userName=".$userName."&verifyKey=".$verifyKey;
|
||
|
|
$bodys = "";
|
||
|
|
$url = $host . $path . "?" . $querys;
|
||
|
|
|
||
|
|
$curl = curl_init();
|
||
|
|
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
|
||
|
|
curl_setopt($curl, CURLOPT_URL, $url);
|
||
|
|
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
||
|
|
curl_setopt($curl, CURLOPT_FAILONERROR, false);
|
||
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||
|
|
curl_setopt($curl, CURLOPT_HEADER, false);
|
||
|
|
if (1 == strpos("$".$host, "https://"))
|
||
|
|
{
|
||
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
||
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
||
|
|
}
|
||
|
|
return curl_exec($curl);
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 获取点播播放地址
|
||
|
|
* @param [type] $video_id [description]
|
||
|
|
* @return [type] [description]
|
||
|
|
*/
|
||
|
|
public function getPlayInfo($video_id, $play_domain = 'vod.ufutx.com')
|
||
|
|
{
|
||
|
|
if (empty($video_id) || $video_id == 'null') return false;
|
||
|
|
AlibabaCloud::accessKeyClient(env('ALIYUN_VOD_ACCESS_KEY_ID'), env('ALIYUN_VOD_ACCESS_KEY_SECRET'))
|
||
|
|
->regionId('cn-hangzhou')
|
||
|
|
->asDefaultClient();
|
||
|
|
try {
|
||
|
|
$result = AlibabaCloud::rpc()
|
||
|
|
->product('vod')
|
||
|
|
// ->scheme('https') // https | http
|
||
|
|
->version('2017-03-21')
|
||
|
|
->action('GetPlayInfo')
|
||
|
|
->method('POST')
|
||
|
|
->host('vod.cn-shanghai.aliyuncs.com')
|
||
|
|
->options([
|
||
|
|
'query' => [
|
||
|
|
'RegionId' => "cn-hangzhou",
|
||
|
|
'VideoId' => $video_id,
|
||
|
|
'PlayConfig' => '{"PlayDomain":"'.$play_domain.'"}',
|
||
|
|
],
|
||
|
|
'headers' =>[
|
||
|
|
'referer' => 'https://lova.ufutx.com'
|
||
|
|
]
|
||
|
|
])
|
||
|
|
->request();
|
||
|
|
$result = $result->toArray();
|
||
|
|
return $result;
|
||
|
|
} catch (ClientException $e) {
|
||
|
|
throw new \Exception($e->getMessage(),$e->getCode());
|
||
|
|
} catch (ServerException $e) {
|
||
|
|
throw new \Exception($e->getMessage(),$e->getCode());
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
throw new \Exception($e->getMessage(),$e->getCode());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
public function getLocalMobile()
|
||
|
|
{
|
||
|
|
AlibabaCloud::accessKeyClient(env('ALIYUN_MOBILE_ACCESS_KEY_ID'), env('ALIYUN_MOBILE_ACCESS_KEY_SECRET'))
|
||
|
|
->regionId('cn-hangzhou')
|
||
|
|
->asDefaultClient();
|
||
|
|
|
||
|
|
$token = request()->input('access_token');
|
||
|
|
if (empty($token)) return ['code'=>1, 'msg'=>'缺少参数'];
|
||
|
|
try {
|
||
|
|
$result = AlibabaCloud::rpc()
|
||
|
|
->product('Dypnsapi')
|
||
|
|
->scheme('https') // https | http
|
||
|
|
->version('2017-05-25')
|
||
|
|
->action('GetMobile')
|
||
|
|
->method('POST')
|
||
|
|
->host('dypnsapi.aliyuncs.com')
|
||
|
|
->options([
|
||
|
|
'query' => [
|
||
|
|
'RegionId' => "cn-hangzhou",
|
||
|
|
'AccessToken' => $token,
|
||
|
|
],
|
||
|
|
])
|
||
|
|
->request();
|
||
|
|
$result = $result->toArray();
|
||
|
|
if ($result['Code'] == 'OK') {
|
||
|
|
return $result['GetMobileResultDTO']['Mobile'];
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
} catch (ClientException $e) {
|
||
|
|
$this->getError($e);
|
||
|
|
return false;
|
||
|
|
} catch (ServerException $e) {
|
||
|
|
$this->getError($e);
|
||
|
|
return false;
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
$this->getError($e);
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 提交转码作业
|
||
|
|
* @param $video_id
|
||
|
|
* @return array
|
||
|
|
* @throws ClientException
|
||
|
|
*/
|
||
|
|
public function SubmitTranscodeJobs($video_id){
|
||
|
|
AlibabaCloud::accessKeyClient(env('ALIYUN_VOD_ACCESS_KEY_ID'), env('ALIYUN_VOD_ACCESS_KEY_SECRET'))
|
||
|
|
->regionId('cn-hangzhou')
|
||
|
|
->asDefaultClient();
|
||
|
|
try {
|
||
|
|
$result = AlibabaCloud::rpc()
|
||
|
|
->product('vod')
|
||
|
|
// ->scheme('https') // https | http
|
||
|
|
->version('2017-03-21')
|
||
|
|
->action('SubmitTranscodeJobs')
|
||
|
|
->method('POST')
|
||
|
|
->host('vod.cn-shanghai.aliyuncs.com')
|
||
|
|
->options([
|
||
|
|
'query' => [
|
||
|
|
'RegionId' => "cn-hangzhou",
|
||
|
|
'VideoId' => $video_id,
|
||
|
|
'TemplateGroupId' => '0945f5dd3a9372ce390cf41d6d35e96b'
|
||
|
|
],
|
||
|
|
])
|
||
|
|
->request();
|
||
|
|
$result = $result->toArray();
|
||
|
|
return $result;
|
||
|
|
} catch (ClientException $e) {
|
||
|
|
throw new \Exception($e->getMessage(),$e->getCode());
|
||
|
|
} catch (ServerException $e) {
|
||
|
|
throw new \Exception($e->getMessage(),$e->getCode());
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
throw new \Exception($e->getMessage(),$e->getCode());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* URL鉴权
|
||
|
|
* @param $filePath
|
||
|
|
* @param $key
|
||
|
|
* @param $domain
|
||
|
|
* @param $expireTime
|
||
|
|
* @return string
|
||
|
|
*/
|
||
|
|
static function Video_Url_Auth($url, $key, $expireTime)
|
||
|
|
{
|
||
|
|
$url = parse_url($url);
|
||
|
|
$timeStamp = time() + $expireTime;
|
||
|
|
$rand = md5(uniqid(microtime(true),true));
|
||
|
|
$sstring = $url['host'] . '-' . $timeStamp . '-'.$rand.'-0-' . $key;
|
||
|
|
$md5hash = md5($sstring);
|
||
|
|
$url = 'http://' . $url['host'] . $url['path'] . '?auth_key=' . $timeStamp . '-'.$rand.'-0-' . $md5hash;
|
||
|
|
return $url;
|
||
|
|
}
|
||
|
|
}
|