Example #1
0
 /**
  * 发起一个HTTP/HTTPS的请求
  *
  * @param string $method  请求类型   GET | POST
  * @param string $url     接口的URL
  * @param array  $params  接口参数
  * @param array  $options 其它选项
  *
  * @return array|boolean
  */
 public static function request($method, $url, array $params = array(), array $options = array())
 {
     self::requireInstance();
     if (self::$autoToken) {
         $url .= (stripos($url, '?') ? '&' : '?') . 'access_token=' . self::$instance->getAccessToken();
     }
     $method = strtolower($method);
     $response = self::$instance->service('http')->{$method}($url, $params, $options);
     if (empty($response['data'])) {
         throw new Exception("服务器无响应");
     }
     $contents = json_decode($response['data'], true);
     if (isset($contents['errcode'])) {
         if ($contents['errmsg'] == 'ok') {
             return true;
         }
         throw new Exception("[{$contents['errcode']}] " . $contents['errmsg'], $contents['errcode']);
     }
     return $contents;
 }