예제 #1
0
 /**
  * Rest api 'GET' call (Curl lib)
  * function overriden
  * @author Mustafa Zeynel Dağlı
  * @version 0.2
  */
 public function restApiDefaultCall()
 {
     /*$encrypt = new \vendor\Encrypt\EncryptManual('test');
       $encryptValue = $encrypt->encrypt_times(4, 'kullanici:sifre');
       //print_r('--'.$encryptValue.'--');
       $decryptValue = $encrypt->decrypt_times(4, $encryptValue);
       //print_r('??'.$decryptValue.'??');*/
     $this->setEncryptClass();
     $params = null;
     $params = $this->getRequestParams();
     $this->hmacObj->setPublicKey($params['pk']);
     $this->hmacObj->setPrivateKey('e249c439ed7697df2a4b045d97d4b9b7e1854c3ff8dd668c779013653913572e');
     $this->hmacObj->setRequestParams($this->getRequestParamsWithoutPublicKey());
     $this->hmacObj->makeHmac();
     //print_r($this->hmacObj);
     $preparedParams = $this->prepareGetParams();
     //$preparedParams = $this->prepareGetParams('', array('pk'));
     if (($ch = @curl_init()) == false) {
         header("HTTP/1.1 500", true, 500);
         die("Cannot initialize CURL session. Is CURL enabled for your PHP installation?");
     }
     //print_r($this->restApiFullPathUrl.'?'.$preparedParams);
     //print_r($this->endPointUrl.$this->getEndPointFunction().'?'.$preparedParams);
     curl_setopt($ch, CURLOPT_URL, $this->restApiFullPathUrl . '?' . $preparedParams);
     //Url together with parameters
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     //Return data instead printing directly in Browser
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->getCallTimeOut());
     //Timeout (Default 7 seconds)
     curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-Public: ' . $this->hmacObj->getPublicKey() . '', 'X-Hash: ' . $this->hmacObj->getHash() . '', 'X-Nonce:' . $this->hmacObj->getNonce(), 'X-TimeStamp:' . $this->hmacObj->setTimeStamp($this->encryptClass->encrypt('' . time() . ''))));
     curl_setopt($ch, CURLOPT_HEADER, 0);
     // we don’t want also to get the header information that we receive.
     //sleep(10);
     $response = curl_exec($ch);
     $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     if ($response == false) {
         die("curl_exec() failed. Error: " . curl_error($ch));
     }
     return $response;
 }
 /**
  * public key control processes has been wrapped
  * @param array $params
  * @return mixed array | null
  * @throws Exception
  * @author Mustafa Zeynel Dağlı
  * @since 0.3 27/01/2016
  */
 private function publicKeyProcessControler($params)
 {
     $resultSet;
     if ($this->isServicePkRequired) {
         /**
          * getting private key due to public key
          * @author Mustafa Zeynel Dağlı
          * @since 05/01/2016 version 0.3
          */
         if (isset($params['pk'])) {
             $resultSet = $this->dalObject->getPrivateKey($params['pk']);
         }
         /**
          * if not get private key due to public key
          * forward to private not found
          * @author Mustafa Zeynel Dağlı
          * @since 06/01/2016 version 0.3
          */
         if (empty($resultSet['resultSet'])) {
             $this->privateKeyNotFoundRedirect();
         }
         /**
          * if service has to be secure then prepare hash for public and private keys
          * @author Mustafa Zeynel Dağlı
          * @since version 0.3 06/01/2016
          */
         if (!isset($resultSet['resultSet'][0]['sf_private_key_value'])) {
             throw new Exception('SlimHmacProxy->restApiDefaultCall() method private key not found!!');
         }
         if (!isset($params['pk'])) {
             throw new Exception('SlimHmacProxy->restApiDefaultCall() method public key not found!!');
         } else {
             $this->hmacObj->setPublicKey($params['pk']);
         }
         //$this->hmacObj->setPrivateKey('e249c439ed7697df2a4b045d97d4b9b7e1854c3ff8dd668c779013653913572e');
         $this->hmacObj->setPrivateKey($resultSet['resultSet'][0]['sf_private_key_value']);
         $this->hmacObj->setRequestParams($this->getRequestParamsWithoutPublicKey());
         $this->hmacObj->makeHmac();
         //print_r($this->hmacObj);
         return $resultSet;
     } else {
         return null;
     }
 }