一、代码示例
/** * 生成cos签名 * @param string $httpURI 你的url地址,如:https://xxxx.com/123/23/test.png * @param string $expires 有效时间 分钟 * @param string $headerList * @param string $urlParamList * @param string $httpParameters * @param string $httpHeaders * @return string */ function createAuthorization($httpURI = '', $expires = '+5 minutes', $headerList = '', $urlParamList = '', $httpParameters = '', $httpHeaders = '') { global $secretKey, $accessKey; $signTime = ( string )(time() - 60) . ';' . ( string )(strtotime($expires)); $httpString = (string)"get\n" . $httpURI . "\n" . $httpParameters . "\n" . $httpHeaders . "\n"; $sha1edHttpString = sha1($httpString); $stringToSign = (string)"sha1\n$signTime\n$sha1edHttpString\n"; $signKey = hash_hmac('sha1', $signTime, $secretKey); $signature = hash_hmac('sha1', $stringToSign, $signKey); $signTime = urlencode($signTime); $query = "q-sign-algorithm=sha1&q-ak=" . trim($accessKey) . "&q-sign-time=$signTime&q-key-time=$signTime&q-header-list=$headerList&q-url-param-list=$urlParamList&" . "q-signature=$signature"; return $query; }
$secretKey:你的SecretKey
$accessKey:你的SecretId
地址为:https://xxxx.com/123/23/test.png?你生成的签名
二、签名工具
https://cos.cloud.tencent.com/tools/cos?tab=sign
标签:signTime,存储,sha1,string,httpURI,param,sign,腾讯,PHP From: https://www.cnblogs.com/yang-2018/p/18327119