$apiParamValue) { $requestUrl .= "$apiParamKey=" . urlencode($apiParamValue) . '&'; } return substr($requestUrl, 0, -1); } public static function signString($source, $accessSecret) { return base64_encode(hash_hmac('sha1', $source, $accessSecret, true)); } /** * 视频名称 */ public static function video_name($FileName) { return mb_substr(substr($FileName, strrpos($FileName, '.') + 1), 0, 128, 'utf8'); } /**签名机制 * @param $parameters * @param $accessKeySecret * @return mixed */ public static function computeSignature($parameters, $accessKeySecret) { ksort($parameters); $canonicalizedQueryString = ''; foreach ($parameters as $key => $value) { $canonicalizedQueryString .= '&' . self::percentEncode($key) . '=' . self::percentEncode($value); } $stringToBeSigned = self::$method . '&%2F&' . self::percentEncode(substr($canonicalizedQueryString, 1)); return self::signString($stringToBeSigned, $accessKeySecret . '&'); } /** * @param $str * @return string|string[]|null */ public static function percentEncode($str) { $res = urlencode($str); $res = str_replace(array('+', '*'), array('%20', '%2A'), $res); $res = preg_replace('/%7E/', '~', $res); return $res; } }