Ejemplo n.º 1
0
 /**
  * 删除文件,要auth认证
  * @example shell curl -i -H 'Authorization: QBox asdf' 'http://rs.qbox.me/delete/asdf'
  * @return boolean
  */
 public function deleteFile($remoteFileName)
 {
     $remoteFileName = str_replace('/', '', $remoteFileName);
     $uri = 'http://' . str_replace('//', '/', $this->conf['host']['rs'] . '/delete/') . $this->encode($this->bucket . ':' . $remoteFileName);
     $policy = array('scope' => $this->bucket, 'deadline' => time() + 3600);
     $tmp = parse_url($uri);
     $auth = $this->sign($tmp['path'] . "\n");
     $http = new \HTTPRequest($uri, HTTP_METH_POST);
     $http->addHeaders(array('Authorization' => 'QBox ' . $auth));
     $r = $http->send();
     $body = json_decode($http->getResponseBody(), true);
     $code = $http->getResponseCode();
     //612是文件不存在
     if ($code == 200 || $code == 612) {
         return true;
     }
     throw new Exception($body['error'], $code);
 }
 public function decode($point = array('lat' => null, 'lng' => null))
 {
     $uri = 'http://maps.googleapis.com/maps/api/geocode/json?sensor=false&latlng=' . $point['lat'] . ',' . $point['lng'];
     $http = new \HTTPRequest($uri, HTTP_METH_GET);
     if (isset($this->conf['lang'])) {
         $http->addHeaders(array('Accept-Language' => $this->conf['lang']));
     }
     $http->send();
     $code = $http->getResponseCode();
     if ($code != 200) {
         throw new Exception('http error', $code);
     }
     $r = json_decode($http->getResponseBody(), true);
     if (!isset($r['results'][0]['formatted_address'])) {
         throw new Exception($r['status'], -1);
     }
     return array('address' => $r['results'][0]['formatted_address']);
 }