//获取阿里云oss授权
public function sts(){
$url = 'https://sts.aliyuncs.com';
$action = 'AssumeRole';
$RoleArn = 'rolearn';
$RoleSessionName = 'client';
$DurationSeconds = '1500';
date_default_timezone_set("UTC");
$param = array(
'Format' => 'JSON',
'Version' => '2015-04-01',
'AccessKeyId' => 'AccessKeyId',
'SignatureMethod' => 'HMAC-SHA1',
'SignatureVersion' => '1.0',
'SignatureNonce' => getRandChar(8),
'Action' => $action,
'RoleArn' => $RoleArn,
'RoleSessionName' => $RoleSessionName,
'DurationSeconds' => $DurationSeconds,
'Timestamp' => date('Y-m-d').'T'.date('H:i:s').'Z'
);
foreach ($param as $k => $v) {
$Parameters[$k] = $v;
}
$Parameters = $this->formatBizQueryParaMap($Parameters,true);
//签名步骤一:按字典序排序参数
$stringtosign = 'POST'."&".urlencode('/')."&".urlencode($Parameters);
$key = 'AccessSecretId'.'&';
$sign = hash_hmac('SHA1',$stringtosign,$key,true);
$sign = base64_encode($sign);
$param['Signature'] = $sign;
$res = curl($url,true,$param);//curl post请求
if($res){
return $res;
}else{
return null;
}
}
//将数组转成uri字符串
function formatBizQueryParaMap($paraMap, $urlencode) {
$buff = "";
ksort($paraMap);
foreach ($paraMap as $k => $v) {
if ($urlencode) {
$v = urlencode($v);
}
$buff.= ($k) . "=" . $v . "&";
}
$reqPar = '';
if (strlen($buff) > 0) {
$reqPar = substr($buff, 0, strlen($buff) - 1);
}
return $reqPar;
}
/**
*@desc 封闭curl的调用接口
* $url(网址),$ifpost(用post传值是需调为1),$datafields(post的数据)
*/
function curl($url, $ifpost = 0, $datafields = '', $cookiefile = '', $v = false) {
$header = array("Connection: Keep-Alive","Accept: text/html, application/xhtml+xml, */*", "Pragma: no-cache", "Accept-Language: zh-Hans-CN,zh-Hans;q=0.8,en-US;q=0.5,en;q=0.3","User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, $v);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$ifpost && curl_setopt($ch, CURLOPT_POST, $ifpost);
$ifpost && curl_setopt($ch, CURLOPT_POSTFIELDS, $datafields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
$cookiefile && curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
$cookiefile && curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,FALSE);
$r = curl_exec($ch);
curl_close($ch);
return $r;
}