您好,登錄后才能下訂單哦!
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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。