示例#1
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;
 }
示例#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
 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');
 }
示例#4
0
 public function testSetCurlOptions()
 {
     $adapter = new Adapter\Curl();
     $adapter->setCurlOption('foo', 'bar')->setCurlOption('bar', 'baz');
     $this->assertEquals(array('curloptions' => array('foo' => 'bar', 'bar' => 'baz')), $this->readAttribute($adapter, 'config'));
 }
示例#5
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;
 }
 /**
  * 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();
 }
示例#7
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']);
     }
 }
 /**
  * @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;
 }