public function catchPic(){
$stream = '';
$param = [
'Action' => 'CreateStreamSnapshot',
'Id' => $stream
];
$pic = $this->getSignature($param);
$data = json_decode($pic,true);
if(isset($data['OssObject'])){
$res = $this->signedUrl($data['OssObject'],$data['OssBucket']);
$url = str_replace("http://rtmp321.oss-cn-shenzhen.aliyuncs.com","XXX(OSS链接)",$res);
}
return app('json')->success();
}
function getSignature($data = [])
{
$key = '';
$secret = '';
$publicParams = array(
"Format" => "JSON",
"Version" => "2018-12-12",
"AccessKeyId" => $key,
"Timestamp" => date('Y-m-d\TH:i:s\Z', time() - date('Z')),
"SignatureMethod" => "HMAC-SHA1",
"SignatureVersion" => "1.0",
"SignatureNonce" => substr(md5(rand(1, 99999999)), rand(1, 9), 14),
$params = array_merge($publicParams,$data);
$params['Signature'] = $this->sign($params, $secret);
$uri = http_build_query($params);
$url = 'https://vs.cn-shenzhen.aliyuncs.com/?'.$uri;
$res = $this->curlGetAndPostl($url);
return $res;
}
function sign($params, $accessSecret, $method = "GET")
{
ksort($params);
$stringToSign = strtoupper($method) . '&' . $this->percentEncode('/') . '&';
$tmp = "";
foreach ($params as $key => $val) {
$tmp .= '&' . $this->percentEncode($key) . '=' . $this->percentEncode($val);
}
$tmp = trim($tmp, '&');
$stringToSign = $stringToSign . $this->percentEncode($tmp);
$key = $accessSecret . '&';
$hmac = hash_hmac("sha1", $stringToSign, $key, true);
return base64_encode($hmac);
}
function curlGetAndPostl($url, $params = false, $ispost = 0)
{
$httpInfo = array();
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_USERAGENT, 'JuheData');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
if ($ispost) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
curl_setopt($ch, CURLOPT_URL, $url);
} else {
if ($params) {
curl_setopt($ch, CURLOPT_URL, $url . '?' . $params);
} else {
curl_setopt($ch, CURLOPT_URL, $url);
}
}
$response = curl_exec($ch);
if ($response === FALSE) {
return false;
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$httpInfo = array_merge($httpInfo, curl_getinfo($ch));
curl_close($ch);
return $response;
}
function percentEncode($value = null)
{
$en = urlencode($value);
$en = str_replace("+", "%20", $en);
$en = str_replace("*", "%2A", $en);
$en = str_replace("%7E", "~", $en);
return $en;
}