示例#1
0
 private function _setHeaders($method, $url, $body = NULL)
 {
     $ctType = 'application/json';
     $macToken = $this->_credentials->MACToken($method, $url, $ctType, $body);
     $ua = Utils::getUserAgent(Config::SDK_USER_AGENT, Config::SDK_VERSION);
     return array('Content-Type' => $ctType, 'User-Agent' => $ua, 'Authorization' => $macToken);
 }
示例#2
0
 public function MACToken($method, $url, $contentType, $body)
 {
     $url = parse_url($url);
     $data = '';
     if (!empty($url['path'])) {
         $data = $method . ' ' . $url['path'];
     }
     if (!empty($url['query'])) {
         $data .= '?' . $url['query'];
     }
     if (!empty($url['host'])) {
         $data .= "\nHost: " . $url['host'];
         if (isset($url['port'])) {
             $data .= ':' . $url['port'];
         }
     }
     if (!empty($contentType)) {
         $data .= "\nContent-Type: " . $contentType;
     }
     $data .= "\n\n";
     if (!empty($body)) {
         $data .= $body;
     }
     return 'Qiniu ' . $this->_accessKey . ':' . Utils::sign($this->_secretKey, $data);
 }
示例#3
0
 /**
  * 提交表单,触发持久化处理
  * @param QiniuEntry $entry 被处理的entry
  * @param array      $fops  array of fops
  * @param string     $notifyURL  处理结果通知接收URL,请参考处理结果通知小节。
  * @param int        $force 强制执行数据处理。当服务端发现fops指定的数据处理结果已经存在,那就认为已经处理成功,避免重复处理浪费资源。加上本字段并设为1,则可强制执行数据处理并覆盖原结果。
  * @param null       $pipeline 为空则表示使用公用队列,处理速度比较慢。建议指定专用队列,转码的时候使用独立的计算资源
  */
 public static function pfop(QiniuEntry $entry, array $fops, $notifyURL, $force = 0, $pipeline = null)
 {
     $encodedBucket = urlencode($entry->bucket());
     $encodedKey = urlencode($entry->key());
     $fops = implode(';', $fops);
     $encodedFops = urlencode($fops);
     $encodedNotifyURL = urlencode($notifyURL);
     $apiHost = Conf::$QINIU_API_HOST;
     $apiPath = "/pfop/";
     $requestBody = "bucket={$encodedBucket}&key={$encodedKey}&fops={$encodedFops}&notifyURL={$encodedNotifyURL}";
     if ($force !== 0) {
         $requestBody .= "&force=1";
     }
     if (!is_null($pipeline)) {
         $requestBody .= "{$pipeline}={$pipeline}";
     }
     $mac = new QiniuMac();
     $client = new QiniuMacHttpClient($mac);
     list($ret, $err) = Utils::Qiniu_Client_CallWithForm($client, $apiHost . $apiPath, $requestBody);
     if ($err !== null) {
         echo "failed\n";
         var_dump($err);
     } else {
         echo "success\n";
         var_dump($ret);
     }
 }
示例#4
0
 /**
  * bucket:key形式的entryURI做urlsafe_base64_encode
  * @return mixed
  */
 public function encodedEntryURI()
 {
     return Utils::Qiniu_Encode($this->entryURI());
 }
示例#5
0
 private function _publishDynamicToken($nonce)
 {
     $url = parse_url($this->_rtmpPublishBaseUrl());
     $data = $url['path'];
     $separator = empty($url['query']) ? '?' : '&';
     if (!empty($url['query'])) {
         $data .= $separator . $url['query'];
     }
     $data .= $separator . 'nonce=' . $nonce;
     $publishToken = Utils::sign($this->publishKey, $data);
     return $publishToken;
 }
示例#6
0
 /**
  * 水印源图片网址,必须有效且返回一张图片
  * @param $url
  * @return $this
  */
 public function imageUrl($url)
 {
     return $this->setParameter('image', Utils::Qiniu_Encode($url));
 }
示例#7
0
 /**
  * 根据上传策略获取上传token
  * @return string
  */
 public function token()
 {
     $json = $this->toJson();
     return Utils::Qiniu_SignWithData(null, $json);
 }
 public function testUrlSafe()
 {
     $a = '你好';
     $b = Utils::base64UrlEncode($a);
     $this->assertEquals($a, Utils::base64UrlDecode($b));
 }
示例#9
0
function initKeys()
{
    \Qiniu\Utils::Qiniu_SetKeys(AccessKey, SecretKey);
}
示例#10
0
 public function videoWatermark($url, $gravity = null)
 {
     if (is_null($gravity)) {
         $gravity = static::Gravity3;
     }
     $url = Utils::Qiniu_Encode($url);
     return $this->setParameter('wmImage', $url)->setParameter('wmGravity', $gravity);
 }
示例#11
0
 /**
  * 水印文字字体
  * @param $font
  * @return $this
  */
 public function font($font)
 {
     return $this->setParameter('font', Utils::Qiniu_Encode($font));
 }