1.封装函数
10年积累的成都网站设计、成都网站制作经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站设计后付款的网站建设流程,更有阿尔山免费网站建设让你可以放心的选择与我们合作。
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这个区域.
网站名称:ali媒体转码签名生成-php
转载来于:http://lswzjz.com/article/jggice.html