您好,登录后才能下订单哦!
1.封装函数
function composeUrl($AccessKeyId,$Format,$SignatureMethod,$SignatureVersion,$TimeFormat,$ActionName,$Version,$InputJson,$AccessSecret){
$apiParams = array();
$apiParams["AccessKeyId"] = $AccessKeyId;
$apiParams["Format"] = $Format;
$apiParams["SignatureMethod"] = $SignatureMethod;
$apiParams["SignatureVersion"] = $SignatureVersion;
$apiParams["SignatureNonce"] = uniqid();
date_default_timezone_set("GMT");
$apiParams["Timestamp"] = date($TimeFormat);
$apiParams["Action"] = $ActionName;
$apiParams["Version"] = $Version;
$apiParams["Input"]= $InputJson;
$apiParams["Signature"] = util::computeSignature($apiParams, $AccessSecret, $apiParams);
$requestUrl = "http://mts.cn-shanghai.aliyuncs.com/?";
foreach ($apiParams as $apiParamKey => $apiParamValue){
$requestUrl .= "$apiParamKey=" . urlencode($apiParamValue) . "&";
}
return substr($requestUrl, 0, -1);
}
function computeSignature($parameters, $accessKeySecret, $iSigner){
ksort($parameters);
$canonicalizedQueryString = '';
foreach($parameters as $key => $value){
$canonicalizedQueryString .= '&' . util::percentEncode($key). '=' . util::percentEncode($value);
}
$stringToSign = 'GET&%2F&' . util::percentencode(substr($canonicalizedQueryString, 1));
$signature = base64_encode(hash_hmac('sha1', $stringToSign, $accessKeySecret."&", true));
return $signature;
}
function percentEncode($str){
$res = urlencode($str);
$res = preg_replace('/\+/', '%20', $res);
$res = preg_replace('/\*/', '%2A', $res);
$res = preg_replace('/%7E/', '~', $res);
return $res;
}
2.调用函数并请求
$TimeFormat = 'Y-m-d\TH:i:s\Z';
$Format= 'JSON';
$Version = '2014-06-18';
$AccessKeyId = 'xxxxxxxxxxxxxxxx';//替换为你们在ali申请的Access Key ID
$AccessSecret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';//替换为你们在ali申请的Access Key Secret
$SignatureMethod = 'Hmac-SHA1';
$SignatureVersion = '1.0';
$ActionName = 'SubmitMediaInfoJob';
$InputJson = json_encode(array("Bucket"=>"test-2-20161024","Location"=>"oss-cn-shanghai","Object"=>"user-dir/avi.avi"));
$SubmitMediaInfoJobRequest = util::composeUrl($AccessKeyId,$Format,$SignatureMethod,$SignatureVersion,$TimeFormat,$ActionName,$Version,$InputJson,$AccessSecret);
print_r($SubmitMediaInfoJobRequest);
3.根据第2步生成的链接,直接复制到地址中进行请求即可看到结果.
4.注意:
a.在步骤1的composeUrl函数中的requestUrl这个变量,需要与步骤2的转递参数Location中的所在区域操持一致,比如:$requestUrl = ""oss-cn-shanghai".这里面都有shanghai这个区域.">http://mts.cn-shanghai.aliyuncs.com/?";那么"Location"=>"oss-cn-shanghai".这里面都有shanghai这个区域.
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。