request() public static method

[request 执行一次curl请求]
public static request ( [string] $method, [string] $url, array $fields = [] ) : [stirng]
$method [string]
$url [string]
$fields array [执行POST请求时的数据]
return [stirng]
Exemplo n.º 1
0
 public function getToken()
 {
     $username = self::CONFIG_USERNAME;
     $password = self::CONFIG_PASSWORD;
     $time = time();
     $hash = md5("{$username}@{$password}@{$time}");
     $auth = "{$username}@{$time}@{$hash}";
     $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
     $url = 'http://axe.mappy.com/1v1/token/generate.aspx?' . 'auth=' . urlencode($auth) . '&' . 'ip=' . urldecode($ip);
     /**
             $remote = @fopen($url, 'rb');
     
             if ( false === $remote )
        return false;
     
             $token = '';
     
             while ( !( feof($remote) ) )
        $token .= fread($remote, 8192);
     
             fclose($remote);
     */
     $curl = new Curl($url);
     $curl->request();
     $resp = $curl->response();
     $curl->disconnect();
     return $resp['body'];
 }
Exemplo n.º 2
0
 /**
  * Если статус возврата получен - возвращает true
  * Значение полученного статуса возврата - getValuePayReturnStatus()
  *
  * @param string $orderId     - Уникальный в магазине id заказа
  * @param string $payReturnId - Уникальный для заказа id возврата
  *
  * @return bool
  */
 public function doRequestReturnStatus($orderId, $payReturnId)
 {
     $oResponse = $this->curl->request($orderId, 'GET', null, $payReturnId);
     $this->parseError($oResponse);
     if ($this->getError()) {
         return false;
     }
     $status = $oResponse->response->refund->status;
     $this->setValuePayReturnStatus($this->statusMap[$status]);
     return true;
 }
 /**
  * Call web service method
  * 
  * @param  string $methodUrl Web service method URL eg: /getEmployee/empNumber/5
  * @param  string $httpVerb  HTTP Verb. Eg: GET, POST, PUT, DELETE
  * @return Array  Webservice return values as an array
  */
 public function callMethod($methodUrl, $httpVerb, array $parameters = array())
 {
     $token = $this->getToken();
     $curlOptions = array('headers' => array("Authorization: Bearer {$token}"));
     if (!empty($this->port)) {
         $curlOptions[CURLOPT_PORT] = $this->port;
     }
     $endpoint = $this->baseUrl . '/api/' . ltrim($methodUrl, '/');
     $curl = new Curl();
     $response = $curl->request($endpoint, json_encode($parameters), $httpVerb, $curlOptions);
     return $response;
 }
Exemplo n.º 4
0
 protected function request($url)
 {
     $curl = new Curl($url);
     $curl->request();
     $this->response = $curl->response();
     $curl->disconnect();
     if ($this->response['status']) {
         if ($this->response['status']['code'] == 200) {
             return $this->response['body'];
         }
         throw new Exception($this->response['status']['message'], $this->response['status']['code']);
     }
     throw new Exception('Error!');
 }
Exemplo n.º 5
0
 protected function request($url, $post = false)
 {
     if (true === $post || is_array($post)) {
         $curl = new Curl($url, CURLOPT_POST, true === $post ? array() : $post);
     } else {
         $curl = new Curl($url);
     }
     $curl->request();
     $this->response = $curl->response();
     $curl->disconnect();
     if ($this->response['status']) {
         if ($this->response['status']['code'] == 200) {
             return $this->response['body'];
         }
         throw new Exception($this->response['status']['message'], $this->response['status']['code']);
     }
     throw new Exception('Error!');
 }
 private function _call($call, $data = FALSE, $type = FALSE)
 {
     switch ($type) {
         case "post":
             $curl = new Curl();
             $url = $this->api_host . $call . "?key={$this->key}";
             $response = $curl->post($url, $data);
             $response = json_decode($response->body);
             return $response;
             break;
         case "put":
             $curl = new Curl();
             $url = $this->api_host . $call . "?key={$this->key}";
             $response = $curl->put($url, $data);
             $response = json_decode($response->body);
             return $response;
             break;
         case "delete":
             $curl = new Curl();
             $url = $this->api_host . $call . "?key={$this->key}";
             $response = $curl->request('DELETE', $url, $data);
             $response = json_decode($response->body);
             return $response;
             break;
         default:
             $data["key"] = $this->key;
             $curl = new Curl();
             //$url = $this->api_host . $call . "?key=$this->key";
             $url = $this->api_host . $call;
             $response = $curl->get($url, $data);
             $response = json_decode($response->body);
             return $response;
             break;
     }
 }
Exemplo n.º 7
0
Arquivo: curl.php Projeto: nickon/curl
 /**
  *   Request
  *
  *   @static
  *   @private
  *   @param $url
  *   @return bool
  */
 private static function request($url)
 {
     if (!self::$ready) {
         return false;
     }
     $url = mb_strtolower($url);
     self::$content = '';
     self::$raw = '';
     self::$response = array();
     if (stristr($url, 'https')) {
         curl_setopt_array(self::$conn, array(CURLOPT_SSLVERSION => 3, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false));
     }
     $headers = array();
     if (self::$headers) {
         foreach (self::$headers as $name => $value) {
             $headers[] = $name . ': ' . $value;
         }
     }
     curl_setopt(self::$conn, CURLOPT_HTTPHEADER, $headers);
     if (self::$cookies) {
         $cookies = array();
         foreach (self::$cookies as $name => $value) {
             $cookies[] = $name . '=' . $value;
         }
         $cookies = implode('; ', $cookies);
         curl_setopt(self::$conn, CURLOPT_COOKIE, $cookies);
     }
     curl_setopt(self::$conn, CURLOPT_URL, $url);
     $response = curl_exec(self::$conn);
     $request = curl_getinfo(self::$conn, CURLINFO_HEADER_OUT);
     self::$request = curl_getinfo(self::$conn);
     if ($response) {
         $sections = explode("\r\n\r\n", $response, self::$request['redirect_count'] + 2);
         self::$content = array_pop($sections);
         self::$raw = $response;
         self::parseHeaders($sections);
     }
     return self::$content;
 }
Exemplo n.º 8
0
/**
 * [saveUserInfo 更新用户信息]
 * @param  [type]  $tmp_u_id    [用户ID]
 * @return [type]             [description]
 */
function updateUserInfo($tmp_u_id)
{
    echo "--------update user {$tmp_u_id}--------\n";
    echo "--------start updating {$tmp_u_id} info--------\n";
    $result = Curl::request('GET', 'http://www.zhihu.com/people/' . $tmp_u_id . '/followees');
    if (empty($result)) {
        $i = 0;
        while (empty($result)) {
            echo "--------empty result.try get {$i} time--------\n";
            $result = Curl::request('GET', 'http://www.zhihu.com/people/' . $tmp_u_id);
            if (++$i == 5) {
                exit($i);
            }
        }
    }
    $current_user = getUserInfo($result);
    unset($current_user['u_id']);
    User::update($current_user, $tmp_u_id);
    echo "--------update {$tmp_u_id} info done--------\n";
}