/**
 * 设置bucket的防盗链配置
 *
 * @param OssClient $ossClient OssClient实例
 * @param string $bucket 存储空间名称
 * @return null
 */
function putBucketReferer($ossClient, $bucket)
{
    $refererConfig = new RefererConfig();
    $refererConfig->setAllowEmptyReferer(true);
    $refererConfig->addReferer("www.aliiyun.com");
    $refererConfig->addReferer("www.aliiyuncs.com");
    try {
        $ossClient->putBucketReferer($bucket, $refererConfig);
    } catch (OssException $e) {
        printf(__FUNCTION__ . ": FAILED\n");
        printf($e->getMessage() . "\n");
        return;
    }
    print __FUNCTION__ . ": OK" . "\n";
}
Пример #2
0
 public function testBucket()
 {
     $refererConfig = new RefererConfig();
     $refererConfig->addReferer('http://www.aliyun.com');
     try {
         $this->ossClient->putBucketReferer($this->bucket, $refererConfig);
     } catch (OssException $e) {
         var_dump($e->getMessage());
         $this->assertTrue(false);
     }
     try {
         Common::waitMetaSync();
         $refererConfig2 = $this->ossClient->getBucketReferer($this->bucket);
         $this->assertEquals($refererConfig->serializeToXml(), $refererConfig2->serializeToXml());
     } catch (OssException $e) {
         $this->assertTrue(false);
     }
     try {
         Common::waitMetaSync();
         $nullRefererConfig = new RefererConfig();
         $nullRefererConfig->setAllowEmptyReferer(false);
         $this->ossClient->putBucketReferer($this->bucket, $nullRefererConfig);
     } catch (OssException $e) {
         $this->assertTrue(false);
     }
     try {
         Common::waitMetaSync();
         $refererConfig3 = $this->ossClient->getBucketLogging($this->bucket);
         $this->assertNotEquals($refererConfig->serializeToXml(), $refererConfig3->serializeToXml());
     } catch (OssException $e) {
         $this->assertTrue(false);
     }
 }