/** * * @param array $putPolicy [description] * @return string [description] */ protected function _getAccessToken($str) { $encodedPutPolicy = \urlsafe_base64_encode(json_encode($this->cfg[$this->name]['putPolicy'])); return $this->_getAccessKey('AccessKey') . ':' . \urlsafe_base64_encode(hash_hmac("sha1", $encodedPutPolicy, $this->_getSecertKey('SecertKey'), true)) . ':' . $encodedPutPolicy; }
$source = $_POST[$fieldName]; } else { $source = $_GET[$fieldName]; } $context = stream_context_create(array('http' => array('follow_location' => false))); foreach ($source as $imgUrl) { //命名规则 $key = time() . rand(0, 10) . '.png'; ob_start(); readfile($imgUrl, false, $context); $img = ob_get_contents(); ob_end_clean(); $upfile = array('name' => 'file', 'fileName' => $key, 'fileBody' => $img); $result = $qiniu->upload(array(), $upfile); if (!empty($result['hash'])) { //加水印判断 if ($USEWATER) { $waterBase = urlsafe_base64_encode($WATERIMAGEURL); $url = $qiniu->downlink($result['key']) . "?watermark/1/image/{$waterBase}/dissolve/{$DISSOLVE}/gravity/{$GRAVITY}/dx/{$DX}/dy/{$DY}"; } else { $url = $qiniu->downlink($result['key']); } /*构建返回数据格式*/ $FileInfo = array("url" => $url, "title" => $result['key'], "state" => 'SUCCESS', "source" => htmlspecialchars($imgUrl)); array_push($list, $FileInfo); } unset($img); unset($result); } /* 返回数据 */ return json_encode(array('state' => count($list) ? 'SUCCESS' : 'ERROR', 'list' => $list));
<?php /* *@description 文件上传方法 *@author widuu http://www.widuu.com *@mktime 08/01/2014 */ header("Content-type:text/html;charset=utf-8"); require "conf.php"; $accessKey = $QINIU_ACCESS_KEY; $secretKey = $QINIU_SECRET_KEY; $bucket = $BUCKET; $host = $HOST; $time = time() + $TIMEOUT; if (empty($_GET["key"])) { exit('param error'); } else { if ($USEWATER && empty($_GET['type'])) { $waterBase = urlsafe_base64_encode($WATERIMAGEURL); $returnBody = "{\"url\":\"{$host}/\$(key)?watermark/1/image/{$waterBase}/dissolve/{$DISSOLVE}/gravity/{$GRAVITY}/dx/{$DX}/dy/{$DY}\", \"state\": \"SUCCESS\", \"name\": \$(fname),\"size\": \"\$(fsize)\",\"w\": \"\$(imageInfo.width)\",\"h\": \"\$(imageInfo.height)\"}"; } else { $returnBody = "{\"url\":\"{$host}/\$(key)\", \"state\": \"SUCCESS\", \"name\": \$(fname),\"size\": \"\$(fsize)\",\"w\": \"\$(imageInfo.width)\",\"h\": \"\$(imageInfo.height)\"}"; } $data = array("scope" => $bucket . ":" . $_GET['key'], "deadline" => $time, "returnBody" => $returnBody); } $data = json_encode($data); $dataSafe = urlsafe_base64_encode($data); $sign = hash_hmac('sha1', $dataSafe, $secretKey, true); $result = $accessKey . ':' . urlsafe_base64_encode($sign) . ':' . $dataSafe; echo $result;