生成多次有效签名函数（用于上传和下载资源，有效期内可重复对不同资源使用）
@param  int $expired    过期时间,unix时间戳
@param  string $bucketName 文件所在bucket
@return string          签名
498707
public static function appSign($expired, $bucketName) {

        $appId = Conf::APPID;
        $secretId = Conf::SECRET_ID;
        $secretKey = Conf::SECRET_KEY;
        
        if (empty($secretId) || empty($secretKey) || empty($appId)) {
            return self::AUTH_SECRET_ID_KEY_ERROR;
        }

        return self::appSignBase($appId, $secretId, $secretKey, $expired, null, $bucketName);
    }
1188756
protected function createReusableSignature($expiration, $bucket, $filepath = null)
    {
        if ( empty($filepath)) {
            return $this->createSignature($expiration, $bucket, null);
        } else {
            if (preg_match('/^\//', $filepath) == 0) {
                $filepath = '/' . $filepath;
            }

            return $this->createSignature($expiration, $bucket, $filepath);
        }
    }
1101585
public Bucket createBucket(String bucketName) {
    // [START createBucket]
    Bucket bucket = storage.create(BucketInfo.of(bucketName));
    // [END createBucket]
    return bucket;
  }
589444
private function getPath($bucketName = null, $key = null)
    {
        return HttpUtils::appendUri(self::BOS_URL_PREFIX, $bucketName, $key);
    }
14914
static public function createFileName($originalName)
    {
        $returnValue = uniqid(hash('crc32', $originalName));

        $ext = @pathinfo($originalName, PATHINFO_EXTENSION);
        if (!empty($ext)){
            $returnValue .= '.' . $ext;
        }

        return $returnValue;
    }
333587
private static function statBase($bucketName, $path)
    {
        $path = self::cosUrlEncode($path);
        $expired = self::time() + self::EXPIRED_SECONDS;
        $url = self::generateResUrl($bucketName, $path);
        $sign = Auth::appSign($expired, $bucketName);

        $data = [
            'op' => 'stat',
        ];

        $url = $url.'?'.http_build_query($data);

        $req = [
            'url'     => $url,
            'method'  => 'get',
            'timeout' => self::$timeout,
            'header'  => [
                'Authorization:'.$sign,
            ],
        ];

        return self::sendRequest($req);
    }
677597
public static function statFolder($bucketName, $path) {
        $path = self::normalizerPath($path, True);	

        return self::statBase($bucketName, $path);
    }
184573
public function copy($key, $bucket2, $key2 = false, $bucket = '')
    {
        $bucket = $bucket ? $bucket : $this->bucket;
        if (!$key2) {
            $key2 = $bucket2;
            $bucket2 = $bucket;
        }
        $encodedEntryURISrc = self::urlBase64Encode("{$bucket}:{$key}");
        $encodedEntryURIDest = self::urlBase64Encode("{$bucket2}:{$key2}");
        $url = "/copy/{$encodedEntryURISrc}/{$encodedEntryURIDest}";
        return $this->fileHandle($url);
    }
1333937
public static function delFolder($bucketName, $path)
    {
        $path = self::normalizerPath($path, true);

        return self::delBase($bucketName, $path);
    }
789990
public static function appSign($url, $expired) {

        $secretId = Conf::SECRET_ID;
        $secretKey = Conf::SECRET_KEY;

        if (empty($secretId) || empty($secretKey)) {
            return self::AUTH_SECRET_ID_KEY_ERROR;
        }

        $urlInfo = self::getInfoFromUrl($url);
        if (empty($urlInfo)) {
            return self::AUTH_URL_FORMAT_ERROR;
        }

        $cate   = isset($urlInfo['cate']) ? $urlInfo['cate'] : '';
        $ver    = isset($urlInfo['ver']) ? $urlInfo['ver'] : '';
        $appid  = $urlInfo['appid'];
        $userid = $urlInfo['userid'];
        $oper   = isset($urlInfo['oper']) ? $urlInfo['oper'] : '';
        $fileid = isset($urlInfo['fileid']) ? $urlInfo['fileid'] : '';
        $style = isset($urlInfo['style']) ? $urlInfo['style'] : '';

        $onceOpers = array('del', 'copy');
        if ($fileid || ($oper && in_array($oper, $onceOpers))) {
            $expired = 0;
        }
        
        $puserid = '';
        if (!empty($userid)) {
            if (strlen($userid) > 64) {
                return self::AUTH_URL_FORMAT_ERROR;
            }
            $puserid = $userid;
        }
                    
        $now = time();    
        $rdm = rand();

        $plainText = 'a='.$appid.'&k='.$secretId.'&e='.$expired.'&t='.$now.'&r='.$rdm.'&u='.$puserid.'&f='.$fileid;
        $bin = hash_hmac("SHA1", $plainText, $secretKey, true);
        $bin = $bin.$plainText;        
        $sign = base64_encode($bin);        
        return $sign;
    }
824724
public function statBase($bucket, $path)
    {
        $path       = self::cosUrlEncode($path);
        $expired    = time() + self::EXPIRED_SECONDS;
        $url        = self::generateResUrl($bucket, $path);
        $signature  = $this->createReusableSignature($expired, $bucket);
        $data       = array('op' => 'stat');
        $url        = $url . '?' . http_build_query($data);

        $req = [
            'url'       => $url,
            'method'    => 'get',
            'timeout'   => self::$timeout,
            'header'    => [
                'Authorization: ' . $signature,
            ],
        ];

        return self::sendRequest($req);
    }
780553
public function dropPrimaryIndex($bucketName)
    {
        $sql = $this->db->getQueryBuilder()->dropPrimaryIndex($bucketName);

        return $this->setSql($sql)->setBucketName($bucketName);
    }
175164
public function retrieve(Memento\Key $key, $expired = false)
    {
        if (!$this->__connect($key)) {
            $this->__disconnect();

            return NULL;
        }

        $meta = $this->getMeta($key);

        // handle arguments based on group or single key
        if ($this->groupKey) {
            $keys = $this->memcache->get($meta[Memento\Hash::FIELD_KEYS]);
            if (!is_array($keys) || !array_key_exists($key->getKey(), $keys)) {
                $this->__disconnect();

                return NULL;
            }
            $data = $this->memcache->get($keys[$key->getKey()]);
        } else {
            if (!array_key_exists(Memento\Hash::FIELD_DATA, $meta)) {
                $this->__disconnect();

                return NULL;
            }
            $data = $this->memcache->get($meta[Memento\Hash::FIELD_DATA]);
        }

        $this->__disconnect();

        return $data;
    }
839449
private function uploadFile($bucket, $dstPath, $filecontent, $mime_type, $bizAttr = null, $insertOnly = null)
    {
        $dstPath = self::cosUrlEncode($dstPath);

        $expired    = time() + self::EXPIRED_SECONDS;
        $url        = self::generateResUrl($bucket, $dstPath);
        $signature  = $this->createReusableSignature($expired, $bucket);
        $fileSha    = sha1($filecontent);

        $data = array(
            'op'        => 'upload',
            'sha'       => $fileSha,
            'biz_attr'  => (isset($bizAttr) ? $bizAttr : ''),
        );

        $data['filecontent'] = $filecontent;

        if (isset($insertOnly) && strlen($insertOnly) > 0) {
            $data['insertOnly'] = (($insertOnly == 0 || $insertOnly == '0' ) ? 0 : 1);
        }

        // 设置文件的 mime 类型
        $data['custom_headers']['Content-Type'] = $mime_type;

        $req = [
            'url'       => $url,
            'method'    => 'post',
            'timeout'   => self::$timeout,
            'data'      => $data,
            'header'    => [
                'Authorization: ' . $signature,
            ],
        ];

        return self::sendRequest($req);
    }
669648
public function dropIndex($bucketName, $indexName)
    {
        $this->beginProfile($token = "    > drop index $bucketName.$indexName ...");

        $result = $this->db->dropIndex($bucketName, $indexName);

        $this->endProfile($token);

        return $result;
    }
639334
private function generateName($key, $expiration = null) {

		if(null !== $expiration && false === ('-' . intval($expiration) == '-' . $expiration)) {
			return trigger_error(sprintf('Argument 2 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($expiration)), E_USER_ERROR);
		}
		
		return md5(serialize($key)) . '-' . ($expiration ? $expiration : '*') . '-' . ($expiration ? (time() + $expiration) : '*') . Application :: get(['extensions', 'cache']);
	}
226016
public function createPrimaryIndex($bucketName, $indexName = null, $options = [])
    {
        $sql = $this->db->getQueryBuilder()->createPrimaryIndex($bucketName, $indexName, $options);

        return $this->setSql($sql)->setBucketName($bucketName);
    }