function make_downloadurl($sha1, $filesize, $filename) { global $_G; $filename = trim($filename, ' "'); // Discuz! 默认的filename两侧会加上 双引号 $filename = diconv($filename, CHARSET, 'UTF-8'); $filename = str2hex($filename); $filename = strtolower($filename[1]); $post = 'http://dz.xf.qq.com/ftn.php?v=1&&'; $k = _hash_hmac('sha1', sprintf('%s|%s|%s', $sha1, $_G['timestamp'], $_G['setting']['ftn_site_id']), $_G['setting']['xf_storage_enc_key']); $parm = array('site_id' => $_G['setting']['ftn_site_id'], 't' => $_G['timestamp'], 'sha1' => $sha1, 'filesize' => $filesize, 'filename' => $filename, 'k' => $k, 'ip' => $_G['clientip']); return $post . cloud_http_build_query($parm, '', '&&'); }
function hash_hmac($algo, $data, $key, $raw_output = false) { return _hash_hmac($algo, $data, $key, $raw_output); }
function test_hash_hmac_output() { $this->assertEquals(array(1 => '140d1cb79fa12e2a31f32d35ad0a2723'), unpack('H32', _hash_hmac('md5', 'simple', 'key', true))); $this->assertEquals(array(1 => '993003b95758e0ac2eba451a4c5877eb1bb7b92a'), unpack('H40', _hash_hmac('sha1', 'simple', 'key', true))); }