1.封裝函數(shù)
創(chuàng)新互聯(lián)專注于羅源網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠為您提供羅源營銷型網(wǎng)站建設(shè),羅源網(wǎng)站制作、羅源網(wǎng)頁設(shè)計(jì)、羅源網(wǎng)站官網(wǎng)定制、小程序定制開發(fā)服務(wù),打造羅源網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供羅源網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。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.調(diào)用函數(shù)并請(qǐng)求
$TimeFormat = 'Y-m-d\TH:i:s\Z';
$Format= 'JSON';
$Version = '2014-06-18';
$AccessKeyId = 'xxxxxxxxxxxxxxxx';//替換為你們?cè)赼li申請(qǐng)的Access Key ID
$AccessSecret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';//替換為你們?cè)赼li申請(qǐng)的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.根據(jù)第2步生成的鏈接,直接復(fù)制到地址中進(jìn)行請(qǐng)求即可看到結(jié)果.
4.注意:
a.在步驟1的composeUrl函數(shù)中的requestUrl這個(gè)變量,需要與步驟2的轉(zhuǎn)遞參數(shù)Location中的所在區(qū)域操持一致,比如:$requestUrl = ""oss-cn-shanghai".這里面都有shanghai這個(gè)區(qū)域.">http://mts.cn-shanghai.aliyuncs.com/?";那么"Location"=>"oss-cn-shanghai".這里面都有shanghai這個(gè)區(qū)域.
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。