/**
  * @return array
  */
 public function getResults($offset, $itemCountPerPage)
 {
     $query = $this->createSearchQuery($offset, $itemCountPerPage);
     $adapter = new Http\Client\Adapter\Curl();
     $adapter->setOptions(array('curloptions' => array(CURLOPT_SSL_VERIFYPEER => false)));
     $client = new Http\Client();
     $client->setAdapter($adapter);
     $client->setMethod('GET');
     $client->setUri($this->getOptions()->getSearchEndpoint() . $query);
     $response = $client->send();
     if (!$response->isSuccess()) {
         throw new Exception\RuntimeException("Invalid response received from CloudSearch.\n" . $response->getContent());
     }
     $results = Json::decode($response->getContent(), Json::TYPE_ARRAY);
     $this->count = $results['hits']['found'];
     if (0 == $this->count) {
         return array();
     }
     if ($this->getOptions()->getReturnIdResults()) {
         $results = $this->extractResultsToIdArray($results);
     }
     foreach ($this->getConverters() as $converter) {
         $results = $converter->convert($results);
     }
     return $results;
 }
示例#2
0
文件: IpInfo.php 项目: arbi/MyCode
 /**
  * @param $ipString
  * @return IdentityInformation
  * @throws \Zend\Validator\Exception\InvalidArgumentException
  */
 public function getIpInfo($ipString)
 {
     $ipValidator = new Ip();
     if (!$ipValidator->isValid($ipString)) {
         throw new InvalidArgumentException();
     }
     // creating request object
     $request = new Request();
     $request->setUri($this->endPoint . $ipString . '/json');
     $client = new Client();
     $adapter = new Client\Adapter\Curl();
     $adapter->setCurlOption(CURLOPT_TIMEOUT_MS, 500);
     $client->setAdapter($adapter);
     $response = $client->send($request);
     $data = $response->getBody();
     $dataArray = json_decode($data);
     $identityInformation = new IdentityInformation();
     $identityInformation->setCountry(isset($dataArray->country) ? $dataArray->country : '');
     $identityInformation->setRegion(isset($dataArray->region) ? $dataArray->region : '');
     $identityInformation->setCity(isset($dataArray->city) ? $dataArray->city : '');
     $identityInformation->setLocation(isset($dataArray->loc) ? $dataArray->loc : '');
     $identityInformation->setProvider(isset($dataArray->org) ? $dataArray->org : '');
     $identityInformation->setHostName(isset($dataArray->hostname) ? $dataArray->hostname : '');
     return $identityInformation;
 }
示例#3
0
 /**
  * Constructor
  * @param string $api_key Flickr's API key
  * @param \Zend\Http\Client $adapter An instanceof \Zend\Http\Client to provide to ZendFlickr with settings for Flickr's new SSL requirement for their API
  */
 public function __construct($api_key = NULL, Client $HttpClient = NULL)
 {
     if ($HttpClient == NULL) {
         $HttpClient = new Client();
         $adapter = new Curl();
         $adapter->setOptions(array("curloptions" => array(CURLOPT_SSL_VERIFYPEER => false)));
         $HttpClient->setAdapter($adapter);
     }
     parent::__construct($api_key, $HttpClient);
 }
示例#4
0
 public function __construct(array $bitcoin)
 {
     $this->blockchain_identifier = $bitcoin['blockchain_identifier'];
     $this->blockchain_password = $bitcoin['blockchain_password'];
     $this->url = 'https://blockchain.info/merchant/' . $this->blockchain_identifier;
     $this->client = new HttpClient();
     $adapter = new CurlAdapter();
     $adapter->setCurlOption(CURLOPT_SSL_VERIFYPEER, false);
     $this->client->setAdapter($adapter);
     $this->client->setMethod('GET');
 }
示例#5
0
 /**
  * 获取会话信息
  * @param array $adapterData
  * @return HttpAdapter
  */
 public function getSessionAdapter($adapterData = [])
 {
     $httpAdapter = new HttpAdapter();
     $options = [CURLOPT_POST => 1, CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_USERAGENT => "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36", CURLOPT_AUTOREFERER => true, CURLOPT_CONNECTTIMEOUT => 120, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_TIMEOUT => 60, CURLOPT_COOKIE => Cache::get($this->getCacheKey())];
     foreach ($options as $k => $v) {
         $httpAdapter->setCurlOption($k, $v);
     }
     foreach ($adapterData as $k => $v) {
         $httpAdapter->setCurlOption($k, $v);
     }
     return $httpAdapter;
 }
示例#6
0
 /**
  * Constructor.
  *
  * @param AuthService $auth
  * @param string $api_url
  * @param string $key
  */
 public function __construct(\ModelFramework\AuthService\AuthService $auth, $key, $api_url)
 {
     $this->client = new Client();
     $this->api_url = $api_url;
     $timestamp = time();
     $company_id = (string) $auth->getMainUser()->company_id;
     $user_id = $auth->getUser()->_id;
     $login = $auth->getUser()->login;
     $key = $key;
     $hash = md5($login . $company_id . $timestamp . $key);
     $this->auth_param = ['timestamp' => $timestamp, 'login' => $login, 'owner' => $user_id, 'bucket' => $company_id, 'hash' => $hash];
     $adapter = new Curl();
     $adapter->setOptions(['curloptions' => [CURLOPT_POST => 1, CURLOPT_HTTPAUTH => CURLAUTH_BASIC, CURLOPT_USERPWD => "username:password", CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => FALSE, CURLOPT_SSL_VERIFYHOST => FALSE]]);
     $this->client->setAdapter($adapter);
 }
示例#7
0
 /**
  * Get Http Adapter
  * @return
  */
 public function getHttpAdapter()
 {
     if (null === $this->httpAdapter) {
         $this->httpAdapter = new Curl();
         $this->httpAdapter->setOptions(array('sslverifypeer' => false));
     }
     return $this->httpAdapter;
 }
示例#8
0
 /**
  * Mocks an NTLM SOAP request.
  *
  * @return void
  */
 private function mockNtlmRequest()
 {
     $headers = array('Content-Type' => 'text/xml; charset=utf-8', 'Method' => 'POST', 'SOAPAction' => '"http://unithost/test#TestMethod"', 'User-Agent' => 'PHP-SOAP-CURL');
     $response = "HTTP/1.1 200 OK\n" . "Cache-Control: private\n" . "Content-Type: text/xml; charset=utf-8\n" . "\n\n" . '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">' . '<s:Body>' . '<TestMethodResponse xmlns="http://unit/test">' . '<TestMethodResult>' . '<TestMethodResult><dummy></dummy></TestMethodResult>' . '</TestMethodResult>' . '</TestMethodResponse>' . '</s:Body>' . '</s:Envelope>';
     $this->mockCurlClient();
     $this->curlClient->expects($this->once())->method('connect')->with('unithost', 80);
     $this->curlClient->expects($this->once())->method('read')->will($this->returnValue($response));
     $this->curlClient->expects($this->any())->method('write')->with('POST', $this->isInstanceOf('Zend\\Uri\\Http'), 1.1, $headers, $this->stringContains('<SOAP-ENV'));
     $this->client->setOptions(array('authentication' => 'ntlm', 'login' => 'username', 'password' => 'testpass'));
 }
示例#9
0
 /**
  * Store or update an entity in the search index
  *
  * @param  array $data
  * @throws Exception\RuntimeException
  * @throws Exception\IndexException
  * @return boolean true if successfull
  */
 protected function index(array $data)
 {
     $adapter = new Http\Client\Adapter\Curl();
     $adapter->setOptions(array('curloptions' => array(CURLOPT_SSL_VERIFYPEER => false)));
     $client = new Http\Client();
     $client->setAdapter($adapter);
     $client->setMethod('POST');
     $client->setUri($this->getDocumentEndpoint());
     $client->setRawBody(Json::encode($data));
     $client->setHeaders(array('Content-Type' => 'application/json'));
     $response = $client->send();
     if (!$response->isSuccess()) {
         if ($this->throwExceptions) {
             throw new Exception\IndexException("Bad response received from CloudSearch.\n" . $response->toString());
         }
         return false;
     }
     $results = Json::decode($response->getContent(), Json::TYPE_ARRAY);
     $count = $results['adds'] + $results['deletes'];
     return $count != count($data) ? 0 : $count;
 }
示例#10
0
 /**
  * @group 4555
  */
 public function testResponseDoesNotDoubleDecodeGzippedBody()
 {
     $this->client->setUri($this->baseuri . 'testCurlGzipData.php');
     $adapter = new Adapter\Curl();
     $adapter->setOptions(array('curloptions' => array(CURLOPT_ENCODING => '')));
     $this->client->setAdapter($adapter);
     $this->client->setMethod('GET');
     $this->client->send();
     $this->assertEquals('Success', $this->client->getResponse()->getBody());
 }
示例#11
0
 /**
  * 执行网络请求
  * @param      $url 请求地址
  * @param null $aAddonOptions 附件参数
  *
  * @return \Zend\Http\Response 网络请求执行完毕所返回数据
  */
 public function _getWebPage($url, $aAddonOptions = null)
 {
     //从cache读入cookie
     $sCookie = $this->_getCachedCookie();
     //var_dump($sCookie);
     $options = [CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_USERAGENT => $this->sUserAgent, CURLOPT_AUTOREFERER => true, CURLOPT_CONNECTTIMEOUT => 120, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_TIMEOUT => $this->iTimeout, CURLOPT_REFERER => $this->sReferer, CURLOPT_PROXY => $this->sProxyServer, CURLOPT_COOKIE => $sCookie];
     $oAdapter = new Client\Adapter\Curl();
     foreach ($options as $k => $v) {
         $oAdapter->setCurlOption($k, $v);
     }
     if (is_array($aAddonOptions)) {
         foreach ($aAddonOptions as $k => $v) {
             $oAdapter->setCurlOption($k, $v);
         }
     }
     //var_dump($oAdapter);
     $oClient = new Client();
     $oClient->setAdapter($oAdapter);
     if ($oAdapter->getConfig()['curloptions'][CURLOPT_FOLLOWLOCATION] == false) {
         $oClient->setOptions(['maxredirects' => 0]);
     }
     $oClient->setUri($url);
     //var_dump($oClient);
     $oResponse = $oClient->send();
     //保存form表单中的org.apache.struts.taglib.html.TOKEN控件值
     $this->_saveLastPageStrutsToken($oResponse);
     //获取新COOKIES字符串
     $oCookies = $oResponse->getCookie();
     $sCookiesNew = '';
     foreach ($oCookies as $oItem) {
         $sItem = $oItem->getName() . '=' . $oItem->getValue();
         $sCookiesNew .= $sItem . ';';
     }
     //更新cookie字符串
     $sCookiesNew = $this->_updateCookieString($sCookie, $sCookiesNew);
     //将cookie存入cache
     $this->_setCookieCache($sCookiesNew);
     return $oResponse;
 }
 /**
  * Creates a HTTP client object.
  * 
  * @param string $useSsl
  * @return Http\Client
  */
 protected function createHttpClient($useSsl = null)
 {
     if (null === $useSsl) {
         $useSsl = $this->useSsl();
     }
     $httpClient = new \Zend\Http\Client(null, array('useragent' => $this->getOption(self::OPT_HTTP_CLIENT_USER_AGENT)));
     if ($useSsl) {
         $adapter = new Http\Client\Adapter\Curl();
         $adapter->setOptions(array('curloptions' => array(CURLOPT_SSL_VERIFYPEER => true, CURLOPT_SSL_VERIFYHOST => 2, CURLOPT_CAINFO => $this->getCaFile())));
         $httpClient->setAdapter($adapter);
     }
     return $httpClient;
 }
 /**
  * Creates a Zend\Http\Client object based on the provided configuration.
  * 
  * @param array $config
  * @throws GeneralException\MissingConfigException
  * @return \Zend\Http\Client
  */
 public function createHttpClient(array $config)
 {
     $zendClientOptions = $this->_defaultZendClientOptions;
     $curlAdapterOptions = $this->_defaultCurlAdapterOptions;
     if (!isset($config[self::OPT_OPTIONS]) || !is_array($config[self::OPT_OPTIONS])) {
         throw new GeneralException\MissingConfigException(self::OPT_OPTIONS);
     }
     $options = $config[self::OPT_OPTIONS];
     if (isset($config[self::OPT_ZEND_CLIENT_OPTIONS]) && is_array($config[self::OPT_ZEND_CLIENT_OPTIONS])) {
         $zendClientOptions = $config[self::OPT_ZEND_CLIENT_OPTIONS] + $zendClientOptions;
     }
     if (isset($config[self::OPT_CURL_ADAPTER_OPTIONS]) && is_array($config[self::OPT_CURL_ADAPTER_OPTIONS])) {
         $curlAdapterOptions = $config[self::OPT_CURL_ADAPTER_OPTIONS] + $curlAdapterOptions;
     }
     if (!isset($options[self::OPT_CAFILE]) && !isset($options[self::OPT_CAPATH])) {
         throw new GeneralException\MissingConfigException(sprintf("%s/%s or %s/%s", self::OPT_OPTIONS, self::OPT_CAFILE, self::OPT_OPTIONS, self::OPT_CAPATH));
     }
     if (isset($options[self::OPT_CAFILE])) {
         $curlAdapterOptions[CURLOPT_CAINFO] = $options[self::OPT_CAFILE];
     }
     if (isset($options[self::OPT_CAPATH])) {
         $curlAdapterOptions[CURLOPT_CAPATH] = $options[self::OPT_CAPATH];
     }
     $client = new Http\Client();
     $client->setOptions($zendClientOptions);
     $adapter = new Http\Client\Adapter\Curl();
     $adapter->setOptions(array('curloptions' => $curlAdapterOptions));
     $client->setAdapter($adapter);
     return $client;
 }
示例#14
0
 /**
  * Creates a dataProvider object (\Zend\Http\Client)
  *
  * @param  string|null $auth Auth data login:password
  * @return Client
  */
 protected function setDefaultDataProvider()
 {
     $dataProvider = new Client();
     $adapter = new Client\Adapter\Curl();
     $curlOptions = [CURLOPT_FOLLOWLOCATION => 1, CURLOPT_RETURNTRANSFER => 1, CURLOPT_SSL_VERIFYPEER => 0, CURLOPT_SSL_VERIFYHOST => 0];
     $adapter->setOptions(['curloptions' => $curlOptions]);
     $dataProvider->setAdapter($adapter);
     $dataProvider->setOptions(['maxredirects' => 1, 'timeout' => 30, 'useragent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4)' . ' AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.122 Safari/537.36']);
     return $dataProvider;
 }
示例#15
0
 /**
  * sendRequest(array $data = null) Send request and get response from internal server
  * @param array [msisdn, message] $data request data
  * @see Aware\ProviderInterface
  * @return json data
  */
 public function sendRequest($uri = null, array $data = null)
 {
     // Compile URL from pattern
     $url = strtr($this->__config['api_url_pattern'], [':username' => $this->__config['username'], ':password' => $this->__config['password'], ':message' => urlencode($data['message']), ':msisdn' => urlencode($data['msisdn'])]);
     // set Client adapter config
     $this->__setAdapterConfig([]);
     // Do the request to server with POST data
     $adapter = new Curl();
     $adapter->setOptions(['curloptions' => $this->getAdapterConfig()]);
     $client = new Client($url);
     $client->setAdapter($adapter);
     $client->setMethod('POST');
     $client->setParameterPost($data);
     $response = $client->send($client->getRequest());
     if ($response->getStatusCode() != 200) {
         throw new Exception\ExceptionStrategy($this->getShortName() . ' connection error. Code: ' . $response->getStatusCode());
     }
     $parseResult = explode('|', trim($response->getContent()));
     if ($parseResult[0] > 0) {
         $result['result']['error'] = $parseResult[1];
     } else {
         $result['result'] = $parseResult[1];
     }
     // Return result
     return $result;
 }
示例#16
0
 /**
  * @group ZF-7040
  */
 public function testGetCurlHandle()
 {
     $adapter = new Adapter\Curl();
     $adapter->setOptions(array('timeout' => 2, 'maxredirects' => 1));
     $adapter->connect("http://framework.zend.com");
     $this->assertTrue(is_resource($adapter->getHandle()));
 }
示例#17
0
 /**
  * Set proxy options in a Curl adapter.
  *
  * @param \Zend\Http\Client\Adapter\Curl $adapter Adapter to configure
  *
  * @return void
  */
 protected function setCurlProxyOptions($adapter)
 {
     $adapter->setCurlOption(CURLOPT_PROXY, $this->proxyConfig['proxy_host']);
     if (!empty($this->proxyConfig['proxy_port'])) {
         $adapter->setCurlOption(CURLOPT_PROXYPORT, $this->proxyConfig['proxy_port']);
     }
 }
示例#18
0
文件: Zend2.php 项目: tillk/vufind
 /**
  * Constructor
  *
  * Sets up the EDS API Client
  *
  * @param array           $settings Associative array of setting to use in
  * conjunction with the EDS API
  *    <ul>
  *      <li>debug - boolean to control debug mode</li>
  *      <li>authtoken - Authentication to use for calls to the API. If using IP
  * Authentication, this is not needed.</li>
  *      <li>username -  EBSCO username for account setup for usage with the EDS
  * API. This is only required for institutions using UID Authentication </li>
  *      <li>password - EBSCO password for account setup for usage with the EDS
  * API. This is only required for institutions using UID Authentication </li>
  *      <li>orgid - Organization making calls to the EDS API </li>
  *      <li>sessiontoken - SessionToken this call is associated with, is one
  * exists. If not, the a profile value must be present </li>
  *      <li>profile - EBSCO profile to use for calls to the API. </li>
  *      <li>isguest - is the user a guest. This needs to be present if there
  * is no session token present</li>
  *    </ul>
  * @param Zend2HttpClient $client   Zend2 HTTP client object (optional)
  */
 public function __construct($settings = [], $client = null)
 {
     parent::__construct($settings);
     $this->client = is_object($client) ? $client : new Zend2HttpClient();
     $this->client->setOptions(['timeout' => 120]);
     $adapter = new CurlAdapter();
     $adapter->setOptions(['curloptions' => [CURLOPT_SSL_VERIFYPEER => false, CURLOPT_FOLLOWLOCATION => true]]);
     $this->client->setAdapter($adapter);
 }
 /**
  * @return bool|NormalizedData
  */
 public function getUserData()
 {
     if ($this->data) {
         return $this->data;
     }
     $config = array('consumerKey' => $this->consumerKey, 'consumerSecret' => $this->consumerSecret, 'siteUrl' => 'https://api.twitter.com/oauth');
     $httpClientOptions = array('adapter' => 'Zend\\Http\\Client\\Adapter\\Curl', 'curloptions' => array(CURLOPT_SSL_VERIFYHOST => false, CURLOPT_SSL_VERIFYPEER => false));
     $consumer = new Consumer($config);
     $consumer->setHttpClient($consumer->getHttpClient()->setOptions($httpClientOptions));
     $tw_session = new Container('twitter');
     if (!empty($this->getParams) && $tw_session->offsetExists('request_token')) {
         try {
             $tw_request_token = $tw_session->offsetGet('request_token');
             $token = $consumer->getAccessToken($this->getParams, unserialize($tw_request_token));
             $tw_session->offsetUnset('request_token');
             $client = $token->getHttpClient($config, null, array('adapter' => new Client\Adapter\Curl()));
             $client->setUri('https://api.twitter.com/1.1/account/verify_credentials.json');
             $client->setMethod(Request::METHOD_GET);
             $adapter = new Client\Adapter\Curl();
             $adapter->setCurlOption(CURLOPT_SSL_VERIFYHOST, false);
             $adapter->setCurlOption(CURLOPT_SSL_VERIFYPEER, false);
             $client->setAdapter($adapter);
             $response = $client->send();
             $data = Json::decode($response->getBody(), Json::TYPE_ARRAY);
             $data['token'] = serialize($token);
             $this->isValid = true;
             return new NormalizedData(NormalizedData::PROVIDER_TYPE_TWITTER, $data);
         } catch (\Exception $e) {
             return false;
         }
     }
     return false;
 }
 /**
  * Constructor
  *
  * @param null|string $accessKey
  *            Access Key
  * @param null|string $secretKey
  *            Secret Key
  * @param null|HttpClient $httpClient
  */
 public function __construct($accessKey = null, $secretKey = null, ZendServiceApi $api = null, HttpClient $httpClient = null)
 {
     $this->setKeys($accessKey, $secretKey);
     if (null === $httpClient) {
         $httpClient = new HttpClient();
         $adapter = new HttpClient\Adapter\Curl();
         $adapter->setCurlOption(CURLOPT_USERPWD, $accessKey . ':' . $secretKey);
         $httpClient->setAdapter($adapter);
     }
     if (null === $api) {
         $api = new ZendServiceApi($httpClient);
     }
     if (!$this->resultSetPrototype instanceof ResultSetInterface) {
         $this->resultSetPrototype = new ResultSet(new ClassMethods(false), new ArrayObject());
     }
     $defaultApiQueryParams = array('format' => 'json');
     $api->setQueryParams($defaultApiQueryParams);
     $this->api = $api;
     $this->setUrl(static::API_BASE_URI);
     /*$this->setUrl(static::API_BASE_URI . '/' . $this->name);
     
             if ('apikey' !== $this->name ) {
                 $this->api->setQueryParams(array_merge(
                     $defaultApiQueryParams,
                     array(
                         'akid' => $this->getAkid() //TODO TO REMOVE AFTER TEST
                     )
                 ));
             }*/
     $this->init();
 }
示例#21
0
 /**
  * sendRequest($uri, array $data) Send request and get response from internal server
  * @param string $uri request URI
  * @param array $data request data
  * @see Aware\ProviderInterface
  * @return json data
  */
 public function sendRequest($uri = null, array $data = null)
 {
     // Compile URL from pattern
     $url = strtr($this->__config['api_url_pattern'] . '?q=WWW', [':lang' => $this->__config['lang'], ':uri' => $uri]);
     // apply API key to request data
     $data['api_key'] = $this->__config['api_key'];
     // set Client adapter config
     $this->__setAdapterConfig([]);
     // Do the request to server with POST data
     $adapter = new Curl();
     $adapter->setOptions(['curloptions' => $this->getAdapterConfig()]);
     $client = new Client($url);
     $client->setAdapter($adapter);
     $client->setMethod('POST');
     $client->setParameterPost($data);
     $response = $client->send($client->getRequest());
     if ($response->getStatusCode() != 200) {
         throw new Exception\ExceptionStrategy($this->getShortName() . ' connection error. Code: ' . $response->getStatusCode());
     }
     // Parse and return result
     $json = json_decode($response->getContent(), TRUE);
     if (!empty($json['error'])) {
         $error = iconv(mb_detect_encoding($json['error']), 'UTF-8//TRANSLIT', $json['error']);
         $json['result']['error'] = $json['code'] . ': ' . $json['error'];
     }
     // Return result
     return $json['result'];
 }