public function getUserInfo($accessToken)
 {
     // Get the correct Profile Endpoint URL based off the country/region provided in the config['region']
     $this->profileEndpointUrl();
     if (empty($accessToken)) {
         throw new \InvalidArgumentException('Access Token is a required parameter and is not set');
     }
     // To make sure double encoding doesn't occur decode first and encode again.
     $accessToken = urldecode($accessToken);
     $url = $this->profileEndpoint . '/auth/o2/tokeninfo?access_token=' . urlEncode($accessToken);
     $httpCurlRequest = new HttpCurl($this->config);
     $response = $httpCurlRequest->httpGet($url);
     $data = json_decode($response);
     if ($data->aud != $this->config['client_id']) {
         // The access token does not belong to us
         throw new \Exception('The Access token entered is incorrect');
     }
     // Exchange the access token for user profile
     $url = $this->profileEndpoint . '/user/profile';
     $httpCurlRequest = new HttpCurl($this->config);
     $httpCurlRequest->setAccessToken($accessToken);
     $httpCurlRequest->setHttpHeader(true);
     $response = $httpCurlRequest->httpGet($url);
     $userInfo = json_decode($response, true);
     return $userInfo;
 }
Beispiel #2
0
 private static function getList($infos, $params)
 {
     $infos = StringOpt::cameltounline($infos['index']);
     $infos = explode('_', $infos);
     if (empty($infos[0]) || empty($infos[1])) {
         return false;
     }
     $index = $infos[0];
     $type = $infos[1];
     $url = 'http://localhost:9200/' . $index . '/' . $type . '/_search';
     $ret = HttpCurl::get($url, json_encode($params[0]));
     $body = json_decode($ret['body'], true);
     if ($body == false || empty($body['hits']['total'])) {
         return false;
     }
     return $body;
 }
Beispiel #3
0
 public static function curlInit()
 {
     if (!empty(self::$handle)) {
         curl_close(self::$handle);
     }
     self::$user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US)' . ' AppleWebKit/532.0 (KHTML, like Gecko)' . ' Chrome/3.0.195.32 Safari/532.0';
     self::$max_redirects = 5;
     self::$connect_timeout = 0.5;
     self::$handle = curl_init();
     curl_setopt(self::$handle, CURLOPT_USERAGENT, self::$user_agent);
     curl_setopt(self::$handle, CURLOPT_CONNECTTIMEOUT, self::$connect_timeout);
     curl_setopt(self::$handle, CURLOPT_RETURNTRANSFER, TRUE);
     curl_setopt(self::$handle, CURLOPT_AUTOREFERER, TRUE);
     curl_setopt(self::$handle, CURLOPT_FOLLOWLOCATION, TRUE);
     curl_setopt(self::$handle, CURLOPT_FILETIME, TRUE);
     curl_setopt(self::$handle, CURLOPT_MAXREDIRS, self::$max_redirects);
     curl_setopt(self::$handle, CURLOPT_HTTPHEADER, array('Expect:'));
     curl_setopt(self::$handle, CURLOPT_SSL_VERIFYPEER, FALSE);
     curl_setopt(self::$handle, CURLOPT_HEADER, TRUE);
     curl_setopt(self::$handle, CURLOPT_NOBODY, FALSE);
 }
    private function invokePost($parameters)
    {
        $response       = array();
        $statusCode     = 200;
        $this->success = false;

	// Submit the request and read response body
	try {
            $shouldRetry = true;
            $retries     = 0;
            do {
                try {
                    $this->constructUserAgentHeader();

                    $httpCurlRequest = new HttpCurl($this->config);
		    $response = $httpCurlRequest->httpPost($this->mwsServiceUrl, $this->userAgent, $parameters);

		    // Split the API response into Response Body and the other parts of the response into other
                    list($other, $responseBody) = explode("\r\n\r\n", $response, 2);
                    $other = preg_split("/\r\n|\n|\r/", $other);

                    list($protocol, $code, $text) = explode(' ', trim(array_shift($other)), 3);
                    $response = array(
                        'Status' => (int) $code,
                        'ResponseBody' => $responseBody
                    );

		    $statusCode = $response['Status'];

		    if ($statusCode == 200) {
                        $shouldRetry    = false;
                        $this->success = true;
                    } elseif ($statusCode == 500 || $statusCode == 503) {

			$shouldRetry = true;
                        if ($shouldRetry && strtolower($this->config['handle_throttle'])) {
                            $this->pauseOnRetry(++$retries, $statusCode);
                        }
                    } else {
                        $shouldRetry = false;
                    }
                } catch (\Exception $e) {
                    throw $e;
                }
            } while ($shouldRetry);
        } catch (\Exception $se) {
            throw $se;
        }

        return $response;
    }
Beispiel #5
0
 private function getCertificate($certificatePath)
 {
     $httpCurlRequest = new HttpCurl($this->ipnConfig);
     $response = $httpCurlRequest->httpGet($certificatePath);
     return $response;
 }
 private function invokePost($parameters)
 {
     $response = array();
     $statusCode = 200;
     $this->success = false;
     // Submit the request and read response body
     try {
         $shouldRetry = true;
         $retries = 0;
         do {
             try {
                 $this->constructUserAgentHeader();
                 $httpCurlRequest = new HttpCurl($this->config);
                 $response = $httpCurlRequest->httpPost($this->mwsServiceUrl, $this->userAgent, $parameters);
                 $curlResponseInfo = $httpCurlRequest->getCurlResponseInfo();
                 $statusCode = $curlResponseInfo["http_code"];
                 $response = array('Status' => $statusCode, 'ResponseBody' => $response);
                 $statusCode = $response['Status'];
                 if ($statusCode == 200) {
                     $shouldRetry = false;
                     $this->success = true;
                 } elseif ($statusCode == 500 || $statusCode == 503) {
                     $shouldRetry = true;
                     if ($shouldRetry && strtolower($this->config['handle_throttle'])) {
                         $this->pauseOnRetry(++$retries, $statusCode);
                     }
                 } else {
                     $shouldRetry = false;
                 }
             } catch (\Exception $e) {
                 throw $e;
             }
         } while ($shouldRetry);
     } catch (\Exception $se) {
         throw $se;
     }
     return $response;
 }
function get_cookie()
{
    $url = 'https://www.wacai.com/user/user!login.action?cmd=null';
    $config = file_get_contents(APP_PATH . '/config.json');
    $config = json_decode($config, true);
    $config = $config['wacai'];
    $post_data = array('user.account' => $config['user'], 'user.pwd' => $config['pwd']);
    $ret = HttpCurl::post($url, $post_data);
    if ($ret['body'] == false) {
        echo 'get_cookie ERROR: ' . $ret['error'] . PHP_EOL;
        return false;
    }
    return isset($ret['header']['set_cookie']) ? $ret['header']['set_cookie'] : false;
}