溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

ali 媒體轉(zhuǎn)碼簽名生成-php

發(fā)布時間:2020-07-15 20:41:49 來源:網(wǎng)絡(luò) 閱讀:615 作者:素顏豬 欄目:web開發(fā)

1.封裝函數(shù)

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ù)并請求

$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.根據(jù)第2步生成的鏈接,直接復(fù)制到地址中進行請求即可看到結(jié)果.



4.注意:

   a.在步驟1的composeUrl函數(shù)中的requestUrl這個變量,需要與步驟2的轉(zhuǎn)遞參數(shù)Location中的所在區(qū)域操持一致,比如:$requestUrl = ""oss-cn-shanghai".這里面都有shanghai這個區(qū)域.">http://mts.cn-shanghai.aliyuncs.com/?";那么"Location"=>"oss-cn-shanghai".這里面都有shanghai這個區(qū)域.

ali 媒體轉(zhuǎn)碼簽名生成-php

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI