Esempio n. 1
0
 function PlanJSONManager($action, $url, $requestjson, $uid)
 {
     $request = new Request();
     $request->getHeaders()->addHeaders(array('Content-Type' => 'application/json; charset=UTF-8'));
     //$url="";
     try {
         $request->setUri($url);
         $request->setMethod($action);
         $client = new Client();
         if ($action == 'PUT' || $action == 'POST') {
             $client->setUri($url);
             $client->setMethod($action);
             $client->setRawBody($requestjson);
             $client->setEncType('application/json');
             $response = $client->send();
             return $response;
         } else {
             $response = $client->dispatch($request);
             //var_dump(json_decode($response->getBody(),true));
             return $response;
         }
     } catch (\Exception $e) {
         $e->getTrace();
     }
     return null;
 }
 /**
  * @param MessageInterface|Message $message
  * @return mixed|void
  * @throws RuntimeException
  */
 public function send(MessageInterface $message)
 {
     $config = $this->getSenderOptions();
     $serviceURL = "http://letsads.com/api";
     $body = new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><request></request>');
     $auth = $body->addChild('auth');
     $auth->addChild('login', $config->getUsername());
     $auth->addChild('password', $config->getPassword());
     $messageXML = $body->addChild('message');
     $messageXML->addChild('from', $config->getSender());
     $messageXML->addChild('text', $message->getMessage());
     $messageXML->addChild('recipient', $message->getRecipient());
     $client = new Client();
     $client->setMethod(Request::METHOD_POST);
     $client->setUri($serviceURL);
     $client->setRawBody($body->asXML());
     $client->setOptions(['sslverifypeer' => false, 'sslallowselfsigned' => true]);
     try {
         $response = $client->send();
     } catch (Client\Exception\RuntimeException $e) {
         throw new RuntimeException("Failed to send sms", null, $e);
     }
     try {
         $responseXML = new \SimpleXMLElement($response->getBody());
     } catch (\Exception $e) {
         throw new RuntimeException("Cannot parse response", null, $e);
     }
     if ($responseXML->name === 'error') {
         throw new RuntimeException("LetsAds return error (" . $responseXML->description . ')');
     }
 }
 public function doPostRequest()
 {
     $url = 'http://www.mvg-live.de/MvgLive/mvglive/rpc/newstickerService';
     $client = new Client();
     $client->setUri($url);
     $client->setMethod(\Zend\Http\Request::METHOD_POST);
     $headers = array('Origin' => 'http://www.mvg-live.de', 'Accept-Encoding' => 'gzip, deflate', 'Accept-Language' => 'de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4,da;q=0.2', 'X-GWT-Module-Base' => 'http://www.mvg-live.de/MvgLive/mvglive/', 'Connection' => 'keep-alive', 'Cache-Control' => 'no-cache', 'Pragma' => 'no-cache', 'User-Agent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36', 'Content-Type' => 'text/x-gwt-rpc; charset=UTF-8', 'Accept' => '*/*', 'X-GWT-Permutation' => '1DD521F1FA9966B50432692AB421CD55', 'Referer' => 'http://www.mvg-live.de/MvgLive/MvgLive.jsp', 'DNT' => '1');
     $client->setHeaders($headers);
     $client->setRawBody('7|0|4|http://www.mvg-live.de/MvgLive/mvglive/|7690A2A77A0295D3EC713772A06B8898|de.swm.mvglive.gwt.client.newsticker.GuiNewstickerService|getNewsticker|1|2|3|4|0|');
     $response = $client->send();
     return $response->getBody();
 }
Esempio n. 4
0
 public function insert(Nfse $nfse, $reference)
 {
     $url = $this->_server . "/nfe2/autorizar/?token={$this->_token}&ref={$reference}";
     $client = new Client($url);
     $client->setMethod('POST');
     $dumper = new Dumper();
     $yaml = $dumper->dump($nfse->getNfse());
     $client->setRawBody($yaml);
     $response = $client->send();
     $this->_responseBody = $response->getBody();
     return $response->isSuccess();
 }
 public static function executePost($uri, $value)
 {
     $client = new Client();
     $client->setUri($uri);
     $client->setMethod(Request::METHOD_POST);
     $client->setRawBody($value);
     $client->setHeaders(array('Content-Type: text/plain'));
     $response = $client->send();
     if ($response->getStatusCode() >= 300) {
         throw new \Exception(sprintf('Request Response: Status Code %d, Url: %s', $response->getStatusCode(), $uri));
     }
     return $response->getBody();
 }
Esempio n. 6
0
 public function testStreamRequest()
 {
     if (!$this->client->getAdapter() instanceof Adapter\StreamInterface) {
         $this->markTestSkipped('Current adapter does not support streaming');
         return;
     }
     $data = fopen(dirname(realpath(__FILE__)) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'staticFile.jpg', "r");
     $this->client->setRawBody($data);
     $this->client->setEncType('image/jpeg');
     $this->client->setMethod('PUT');
     $res = $this->client->send();
     $expected = $this->_getTestFileContents('staticFile.jpg');
     $this->assertEquals($expected, $res->getBody(), 'Response body does not contain the expected data');
 }
Esempio n. 7
0
 /**
  * Write a message to the log.
  *
  * @param array $event event data
  *
  * @return void
  * @throws \Zend\Log\Exception\RuntimeException
  */
 protected function doWrite(array $event)
 {
     // Apply verbosity filter:
     if (is_array($event['message'])) {
         $event['message'] = $event['message'][$this->verbosity];
     }
     // Create request
     $this->client->setUri($this->url);
     $this->client->setMethod('POST');
     $this->client->setEncType($this->contentType);
     $this->client->setRawBody($this->getBody($this->applyVerbosity($event)));
     // Send
     $response = $this->client->send();
 }
Esempio n. 8
0
 /**
  * Requests RAYNET Cloud CRM REST API. Check https://s3-eu-west-1.amazonaws.com/static-raynet/webroot/api-doc.html for any further details.
  *
  * @param $serviceName string URL service name
  * @param $method string Http method
  * @param $request array request
  * @return \Zend\Http\Response response
  */
 private function callRaynetcrmRestApi($serviceName, $method, $request)
 {
     $client = new Client('', array('adapter' => 'Zend\\Http\\Client\\Adapter\\Curl', 'curloptions' => array(CURLOPT_FOLLOWLOCATION => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false)));
     $client->setMethod($method);
     $client->setUri($this->buildUrl($serviceName));
     $client->setHeaders(array('X-Instance-Name' => $this->fInstanceName, 'Content-Type' => 'application/json; charset=UTF-8'));
     $client->setAuth($this->fUserName, $this->fApiKey);
     if ($method === self::HTTP_METHOD_GET) {
         $client->setParameterGet($request);
     } else {
         $client->setRawBody(Json::encode($request));
     }
     return $client->send();
 }
Esempio n. 9
0
 /**
  * Test that we properly calculate the content-length of multibyte-encoded
  * request body
  *
  * This may file in case that mbstring overloads the substr and strlen
  * functions, and the mbstring internal encoding is a multibyte encoding.
  *
  * @link http://framework.zend.com/issues/browse/ZF-2098
  */
 public function testMultibyteRawPostDataZF2098()
 {
     $this->_client->setAdapter('Zend\\Http\\Client\\Adapter\\Test');
     $this->_client->setUri('http://example.com');
     $bodyFile = __DIR__ . '/_files/ZF2098-multibytepostdata.txt';
     $this->_client->setRawBody(file_get_contents($bodyFile));
     $this->_client->setEncType('text/plain');
     $this->_client->setMethod('POST');
     $this->_client->send();
     $request = $this->_client->getLastRawRequest();
     if (!preg_match('/^content-length:\\s+(\\d+)/mi', $request, $match)) {
         $this->fail("Unable to find content-length header in request");
     }
     $this->assertEquals(filesize($bodyFile), (int) $match[1]);
 }
Esempio n. 10
0
 /**
  * Perform an HTTP request.
  *
  * @param string $baseUrl     Base URL for request
  * @param string $method      HTTP method for request
  * @param string $queryString Query string to append to URL
  * @param array  $headers     HTTP headers to send
  *
  * @throws SerialsSolutions_Summon_Exception
  * @return string             HTTP response body
  */
 protected function httpRequest($baseUrl, $method, $queryString, $headers)
 {
     $this->debugPrint("{$method}: {$baseUrl}?{$queryString}");
     $this->client->resetParameters();
     if ($method == 'GET') {
         $baseUrl .= '?' . $queryString;
     } elseif ($method == 'POST') {
         $this->client->setRawBody($queryString, 'application/x-www-form-urlencoded');
     }
     $this->client->setHeaders($headers);
     // Send Request
     $this->client->setUri($baseUrl);
     $result = $this->client->setMethod($method)->send();
     if (!$result->isSuccess()) {
         throw new SerialsSolutions_Summon_Exception($result->getBody());
     }
     return $result->getBody();
 }
Esempio n. 11
0
 /**
  * Perform an HTTP request.
  *
  * @param string $baseUrl       Base URL for request
  * @param string $method        HTTP method for request (GET,POST, etc.)
  * @param string $queryString   Query string to append to URL
  * @param array  $headers       HTTP headers to send
  * @param string $messageBody   Message body to for HTTP Request
  * @param string $messageFormat Format of request $messageBody and respones
  *
  * @throws EbscoEdsApiException
  * @return string               HTTP response body
  */
 protected function httpRequest($baseUrl, $method, $queryString, $headers, $messageBody = null, $messageFormat = "application/json; charset=utf-8")
 {
     $this->debugPrint("{$method}: {$baseUrl}?{$queryString}");
     $this->client->resetParameters();
     $this->client->setHeaders($headers);
     $this->client->setMethod($method);
     if ($method == 'GET' && !empty($queryString)) {
         $baseUrl .= '?' . $queryString;
     } elseif ($method == 'POST' && isset($messageBody)) {
         $this->client->setRawBody($messageBody);
     }
     $this->client->setUri($baseUrl);
     $this->client->setEncType($messageFormat);
     $result = $this->client->send();
     if (!$result->isSuccess()) {
         throw new \EbscoEdsApiException(json_decode($result->getBody(), true));
     }
     return $result->getBody();
 }
Esempio n. 12
0
    /**
     * Perform an JSOC-RPC request and return a response.
     *
     * @param  Request $request Request.
     * @return Response Response.
     * @throws Exception\HttpException When HTTP communication fails.
     */
    public function doRequest($request)
    {
        $this->lastRequest = $request;

        $httpRequest = $this->httpClient->getRequest();
        if ($httpRequest->getUri() === null) {
            $this->httpClient->setUri($this->serverAddress);
        }

        $headers = $httpRequest->headers();
        $headers->addHeaders(array(
            'Content-Type' => 'application/json',
            'Accept'       => 'application/json',
        ));

        if (!$headers->get('User-Agent')) {
            $headers->addHeaderLine('User-Agent', 'Zend_Json_Server_Client');
        }

        $this->httpClient->setRawBody($request->__toString());
        $this->httpClient->setMethod('POST');
        $httpResponse = $this->httpClient->send();

        if (!$httpResponse->isSuccess()) {
            throw new Exception\HttpException(
                $httpResponse->getReasonPhrase(),
                $httpResponse->getStatusCode()
            );
        }

        $response = new Response();

        $this->lastResponse = $response;

        // import all response data form JSON HTTP response
        $response->loadJson($httpResponse->getBody());

        return $response;
    }
Esempio n. 13
0
 /**
  * @param $endpoint
  * @param $token
  * @param $postArray
  * @return array
  * @throws \Exception
  */
 public function basicOauthPostConnect($endpoint, $token, $postArray)
 {
     $client = new Client($endpoint, ['maxredirects' => 0, 'timeout' => 60]);
     $client->setMethod('POST');
     $client->setAdapter('Zend\\Http\\Client\\Adapter\\Curl');
     //to deal with ssl errors
     $client->setHeaders(['content-type' => 'application/json', 'Accept' => 'application/json', 'Authorization' => 'Bearer ' . $token]);
     //        $data = array(
     //            $postArray
     //        );
     $json = json_encode($postArray);
     $client->setRawBody($json, 'application/json');
     try {
         $response = $client->send();
     } catch (\Exception $e) {
         throw new \Exception($e);
     }
     $responseObject = json_decode($response->getBody());
     if (is_null($responseObject)) {
         return false;
     }
     $hydrator = new \Zend\Stdlib\Hydrator\ObjectProperty();
     return $hydrator->extract($responseObject);
 }
Esempio n. 14
0
 public function sendMessage($postdata)
 {
     $defaults = array('publisher' => $this->config['publisher'], 'provider' => '', 'message' => '', 'message_plain' => '', 'lang' => '', 'property_reference' => '', 'salutation_code' => '', 'firstname' => '', 'lastname' => '', 'legal_name' => '', 'street' => '', 'postal_code' => '', 'locality' => '', 'phone' => '', 'mobile' => '', 'fax' => '', 'email' => '');
     $postdata = array_merge($defaults, $postdata);
     $postdata['publisher'] = $this->config['publisher'];
     if ($postdata['message'] && !$postdata['message_plain']) {
         $postdata['message'] = $this->sanitizeHtml($postdata['message']);
         $postdata['message_plain'] = strip_tags($postdata['message']);
     }
     if (!$postdata['message'] && $postdata['message_plain']) {
         $postdata['message_plain'] = strip_tags($postdata['message_plain']);
         $postdata['message'] = $this->sanitizeHtml($postdata['message_plain']);
     }
     if ($postdata['message'] && $postdata['message_plain']) {
         $postdata['message_plain'] = strip_tags($postdata['message_plain']);
         $postdata['message'] = $this->sanitizeHtml($postdata['message_plain']);
     }
     $config = array('adapter' => 'Zend\\Http\\Client\\Adapter\\Curl', 'curloptions' => array(CURLOPT_FRESH_CONNECT => true));
     $query = array();
     $uri = $this->config['url'] . '/msg?' . http_build_query($query);
     $client = new HttpClient($uri, $config);
     $client->setHeaders(array('Accept' => 'application/json; charset=UTF-8', 'Content-Type' => 'application/json'));
     $client->setMethod('POST');
     $client->setRawBody(Json::encode($postdata));
     $client->setEncType(HttpClient::ENC_FORMDATA);
     $client->setAuth($this->config['username'], $this->config['password'], \Zend\Http\Client::AUTH_BASIC);
     $response = $client->send();
     return $response->getContent();
 }
Esempio n. 15
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;
 }
Esempio n. 16
0
    /**
     * Perform request using Client channel
     *
     * @param string  $path               Path
     * @param string  $queryString        Query string
     * @param string  $httpVerb           HTTP verb the request will use
     * @param array   $headers            x-ms headers to add
     * @param boolean $forTableStorage    Is the request for table storage?
     * @param mixed   $rawData            Optional RAW HTTP data to be sent over the wire
     * @param string  $resourceType       Resource type
     * @param string  $requiredPermission Required permission
     * @return Response
     */
    protected function _performRequest(
        $path = '/',
        $queryString = '',
        $httpVerb = Request::METHOD_GET,
        $headers = array(),
        $forTableStorage = false,
        $rawData = null,
        $resourceType = Storage::RESOURCE_UNKNOWN,
        $requiredPermission = Credentials\AbstractCredentials::PERMISSION_READ
    )
    {
        // Clean path
        if (strpos($path, '/') !== 0) {
            $path = '/' . $path;
        }

        // Clean headers
        if ($headers === null) {
            $headers = array();
        }

        // Ensure cUrl will also work correctly:
        //  - disable Content-Type if required
        //  - disable Expect: 100 Continue
        if (!isset($headers["Content-Type"])) {
            $headers["Content-Type"] = '';
        }
        $headers["Expect"] = '';

        // Add version header
        $headers['x-ms-version'] = $this->_apiVersion;

        // URL encoding
        $path        = self::urlencode($path);
        $queryString = self::urlencode($queryString);

        // Generate URL and sign request
        $requestUrl     = $this->_credentials
            ->signRequestUrl($this->getBaseUrl() . $path . $queryString, $resourceType, $requiredPermission);
        $requestHeaders = $this->_credentials
            ->signRequestHeaders($httpVerb, $path, $queryString, $headers, $forTableStorage, $resourceType,
                                 $requiredPermission);

        // Prepare request
        $this->_httpClientChannel->resetParameters(true);
        $this->_httpClientChannel->setUri($requestUrl);
        $this->_httpClientChannel->setHeaders($requestHeaders);
        $this->_httpClientChannel->setRawBody($rawData);

        // Execute request
        $response = $this->_retryPolicy->execute(
            array($this->_httpClientChannel, 'request'),
            array($httpVerb)
        );

        return $response;
    }
Esempio n. 17
0
 /**
  * Performs a HTTP request using the specified method
  *
  * @param string $method The HTTP method for the request - 'GET', 'POST',
  *                       'PUT', 'DELETE'
  * @param string $uri The URL to which this request is being performed
  * @param array $headers An associative array of HTTP headers
  *                       for this request
  * @param string $body The body of the HTTP request
  * @param string $contentType The value for the content type
  *                                of the request body
  * @param int $remainingRedirects Number of redirects to follow if request
  *                              s results in one
  * @return \Zend\Http\Response The response object
  */
 public function performHttpRequest($method, $uri, $headers = null, $body = null, $contentType = null, $remainingRedirects = null)
 {
     if ($remainingRedirects === null) {
         $remainingRedirects = self::getMaxRedirects();
     }
     if ($headers === null) {
         $headers = array();
     }
     // Append a GData version header if protocol v2 or higher is in use.
     // (Protocol v1 does not use this header.)
     $major = $this->getMajorProtocolVersion();
     $minor = $this->getMinorProtocolVersion();
     if ($major >= 2) {
         $headers['GData-Version'] = $major + ($minor === null ? '.' + $minor : '');
     }
     // check the overridden method
     if (($method == 'POST' || $method == 'PUT') && $body === null && $headers['x-http-method-override'] != 'DELETE') {
         throw new App\InvalidArgumentException('You must specify the data to post as either a ' . 'string or a child of ZendGData\\App\\Entry');
     }
     if ($uri === null) {
         throw new App\InvalidArgumentException('You must specify an URI to which to post.');
     }
     if ($contentType != null) {
         $headers['Content-Type'] = $contentType;
     }
     if (self::getGzipEnabled()) {
         // some services require the word 'gzip' to be in the user-agent
         // header in addition to the accept-encoding header
         if (strpos($this->_httpClient->getHeaders()->get('User-Agent'), 'gzip') === false) {
             $headers['User-Agent'] = $this->_httpClient->getHeaders()->get('User-Agent') . ' (gzip)';
         }
         $headers['Accept-encoding'] = 'gzip, deflate';
     } else {
         $headers['Accept-encoding'] = 'identity';
     }
     // Make sure the HTTP client object is 'clean' before making a request
     // In addition to standard headers to reset via resetParameters(),
     // also reset the Slug and If-Match headers
     $this->_httpClient->resetParameters();
     $this->_httpClient->setHeaders(array('Slug' => 'If-Match'));
     // Set the params for the new request to be performed
     $this->_httpClient->setHeaders($headers);
     $uriObj = Uri\UriFactory::factory($uri);
     preg_match("/^(.*?)(\\?.*)?\$/", $uri, $matches);
     $this->_httpClient->setUri($matches[1]);
     $queryArray = $uriObj->getQueryAsArray();
     $this->_httpClient->setParameterGet($queryArray);
     $this->_httpClient->setOptions(array('maxredirects' => 0));
     // Set the proper adapter if we are handling a streaming upload
     $usingMimeStream = false;
     $oldHttpAdapter = null;
     if ($body instanceof \ZendGData\MediaMimeStream) {
         $usingMimeStream = true;
         $this->_httpClient->setRawDataStream($body, $contentType);
         $oldHttpAdapter = $this->_httpClient->getAdapter();
         if ($oldHttpAdapter instanceof \Zend\Http\Client\Adapter\Proxy) {
             $newAdapter = new HttpAdapterStreamingProxy();
         } else {
             $newAdapter = new HttpAdapterStreamingSocket();
         }
         $this->_httpClient->setAdapter($newAdapter);
     } else {
         $this->_httpClient->setRawBody($body);
     }
     try {
         $this->_httpClient->setMethod($method);
         $response = $this->_httpClient->send();
         // reset adapter
         if ($usingMimeStream) {
             $this->_httpClient->setAdapter($oldHttpAdapter);
         }
     } catch (\Zend\Http\Client\Exception\ExceptionInterface $e) {
         // reset adapter
         if ($usingMimeStream) {
             $this->_httpClient->setAdapter($oldHttpAdapter);
         }
         throw new App\HttpException($e->getMessage(), $e);
     }
     if ($response->isRedirect() && $response->getStatusCode() != '304') {
         if ($remainingRedirects > 0) {
             $newUrl = $response->getHeaders()->get('Location')->getFieldValue();
             $response = $this->performHttpRequest($method, $newUrl, $headers, $body, $contentType, $remainingRedirects);
         } else {
             throw new App\HttpException('Number of redirects exceeds maximum', null, $response);
         }
     }
     if (!$response->isSuccess()) {
         $exceptionMessage = 'Expected response code 200, got ' . $response->getStatusCode();
         if (self::getVerboseExceptionMessages()) {
             $exceptionMessage .= "\n" . $response->getBody();
         }
         $exception = new App\HttpException($exceptionMessage);
         $exception->setResponse($response);
         throw $exception;
     }
     //Apply defaults in case of later requests.
     $this->applyDefaults();
     return $response;
 }
Esempio n. 18
0
 public function logMsg($message, $priority = 7)
 {
     $config = array('adapter' => 'Zend\\Http\\Client\\Adapter\\Curl', 'curloptions' => array(CURLOPT_FRESH_CONNECT => true));
     $query = array();
     $uri = $this->config['url'] . '/msg?' . http_build_query($query);
     $client = new HttpClient($uri, $config);
     $client->setHeaders(array('Accept' => 'application/json; charset=UTF-8', 'Content-Type' => 'application/json'));
     $client->setMethod('POST');
     $client->setRawBody(Json::encode(array('software' => $this->config['software'], 'message' => $message, 'priority' => $priority, 'priorityName' => array_search($priority, $this->priorities), 'timestamp' => date('Y-m-dTH:i:s', time()))));
     $client->setEncType(HttpClient::ENC_FORMDATA);
     $client->setAuth($this->config['username'], $this->config['password'], \Zend\Http\Client::AUTH_BASIC);
     try {
         $response = $client->send();
     } catch (\Exception $e) {
         //probably timeout thats ok ^^;
     }
     return true;
 }
 public function remotesincronizarAction()
 {
     try {
         set_time_limit(500);
         ini_set('max_execution_time', 500);
         $config = $this->getServiceLocator()->get('Config');
         $body = $this->getRequest()->getContent();
         $json = json_decode($body, true);
         if (empty($json['agr_connect'])) {
             $agr_connect = 0;
             $agr_fecha = '';
         } else {
             $agr_connect = $json['agr_connect'];
             $agr_fecha = $json['agr_fecha'];
         }
         //end if
         if (empty($json['htc_connect'])) {
             $htc_connect = 0;
             $htc_fecha = '';
         } else {
             $htc_connect = $json['htc_connect'];
             $htc_fecha = $json['htc_fecha'];
         }
         //end if
         if (empty($json['lma_connect'])) {
             $lma_connect = 0;
             $lma_fecha = '';
         } else {
             $lma_connect = $json['lma_connect'];
             $lma_fecha = $json['lma_fecha'];
         }
         //end if
         $uri = $config['url_server_integrador'] . '/sincronizador/disponibilidad/sincronizar';
         $data = array('agr_connect' => $agr_connect, 'htc_connect' => $htc_connect, 'lma_connect' => $lma_connect, 'agr_fecha' => $agr_fecha, 'htc_fecha' => $htc_fecha, 'lma_fecha' => $lma_fecha);
         $json = json_encode($data);
         //Instantiate a client object
         $client = new Client($uri, array('timeout' => 500));
         $requestHeaders = $client->getRequest()->getHeaders();
         $client->setRawBody($json);
         $client->setMethod('post');
         //setting header optional - some API need this;
         $headerString = 'Accept: application/json';
         $requestHeaders->addHeaderLine($headerString);
         // The following request will be sent over a TLS secure connection.
         $response = $client->send();
         //if ($response->isSuccess()) {
         $json_string = $response->getBody();
         //echo("<pre>");var_dump($json_string); echo("</pre");
         $json = json_decode($json_string);
         $json->respuesta_code = 'OK';
         $json->respuesta_mensaje = $json->response->message;
         $json->respuesta_codex = $json->response->code;
         //echo("<pre>");var_dump($json); echo("</pre");
         $json = new JsonModel(get_object_vars($json));
         return $json;
     } catch (\Exception $e) {
         $excepcion_msg = utf8_encode($this->ExcepcionPlugin()->getMessageFormat($e));
         $response = $this->getResponse();
         $response->setStatusCode(500);
         $response->setContent($excepcion_msg);
         return $response;
     }
 }
Esempio n. 20
0
 /**
  * Perform an http call. This method is used by the resource specific classes. Please use the $payments property to
  * perform operations on payments.
  *
  * @see $payments
  * @see $isuers
  *
  * @param $http_method
  * @param $api_method
  * @param $http_body
  *
  * @return string
  * @throws Mollie_API_Exception
  *
  * @codeCoverageIgnore
  */
 public function performHttpCall($http_method, $api_method, $http_body = NULL)
 {
     if (empty($this->api_key)) {
         throw new Mollie_API_Exception("You have not set an API key. Please use setApiKey() to set the API key.");
     }
     $url = $this->api_endpoint . "/" . self::API_VERSION . "/" . $api_method;
     $adapter = new Zend\Http\Client\Adapter\Socket();
     $client = new Client();
     $client->setAdapter($adapter);
     $client->setUri($this->api_endpoint . "/" . self::API_VERSION . "/" . $api_method);
     $user_agent = join(' ', $this->version_strings);
     $client->setOptions(array('useragent' => $user_agent, 'maxredirects' => 0, 'timeout' => 10, 'verify_peer' => true, 'allow_self_signed' => false, 'sslcafile' => realpath(dirname(__FILE__)) . "/cacert.pem"));
     $client->setMethod($http_method);
     $client->setHeaders(["Accept" => "application/json", "Authorization" => "Bearer {$this->api_key}", "User-Agent" => $user_agent, "Connection" => "Keep-Alive", 'Keep-Alive' => 300, "X-Mollie-Client-Info" => php_uname()]);
     $client->setRawBody($http_body);
     $response = $client->send();
     return $response->getBody();
 }