/** * 解析RefererConfig数据 * * @return RefererConfig */ protected function parseDataFromResponse() { $content = $this->rawResponse->body; $config = new RefererConfig(); $config->parseFromXml($content); return $config; }
public function testBucket() { $refererConfig = new RefererConfig(); $refererConfig->addReferer('http://www.aliyun.com'); try { $this->ossClient->putBucketReferer($this->bucket, $refererConfig); } catch (Exception $e) { var_dump($e->getMessage()); $this->assertTrue(false); } try { sleep(5); $refererConfig2 = $this->ossClient->getBucketReferer($this->bucket); $this->assertEquals($refererConfig->serializeToXml(), $refererConfig2->serializeToXml()); } catch (Exception $e) { $this->assertTrue(false); } try { $nullRefererConfig = new RefererConfig(); $nullRefererConfig->setAllowEmptyReferer(false); $this->ossClient->putBucketReferer($this->bucket, $nullRefererConfig); } catch (Exception $e) { $this->assertTrue(false); } try { sleep(5); $refererConfig3 = $this->ossClient->getBucketLogging($this->bucket); $this->assertNotEquals($refererConfig->serializeToXml(), $refererConfig3->serializeToXml()); } catch (Exception $e) { $this->assertTrue(false); } }
public function testParseValidXml2() { $refererConfig = new RefererConfig(); $refererConfig->parseFromXml($this->validXml2); $this->assertEquals(true, $refererConfig->isAllowEmptyReferer()); $this->assertEquals(1, count($refererConfig->getRefererList())); $this->assertEquals($this->cleanXml($this->validXml2), $this->cleanXml(strval($refererConfig))); }
/** * 设置一个bucket的referer访问白名单和是否允许referer字段为空的请求访问 * Bucket Referer防盗链具体见OSS防盗链 * * @param string $bucket bucket名称 * @param RefererConfig $refererConfig * @param array $options * * @return ResponseCore * @throws null */ public function putBucketReferer($bucket, $refererConfig, $options = null) { $this->precheckCommon($bucket, null, $options, false); $options[self::OSS_BUCKET] = $bucket; $options[self::OSS_METHOD] = self::OSS_HTTP_PUT; $options[self::OSS_OBJECT] = '/'; $options[self::OSS_SUB_RESOURCE] = 'referer'; $options[self::OSS_CONTENT_TYPE] = 'application/xml'; $options[self::OSS_CONTENT] = $refererConfig->serializeToXml(); $response = $this->auth($options); $result = new PutSetDeleteResult($response); return $result->getData(); }