Advertisement
fabi0

Untitled

Jan 19th, 2015
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.88 KB | None | 0 0
  1. <?php
  2.  
  3. class EmagController extends AppController {
  4.  
  5.     /**
  6.      *
  7.      * @var type
  8.      */
  9.     private $_marketplase_url = 'https://marketplace.emag.bg/';
  10.  
  11.     /**
  12.      *
  13.      * @var type
  14.      */
  15.     private $_marketplase_api_url = 'https://marketplace.emag.bg/api-3';
  16.  
  17.     /**
  18.      *
  19.      * @var type
  20.      */
  21.     private $_ch;
  22.  
  23.     /**
  24.      *
  25.      * @var type
  26.      */
  27.     private $_username = 'lancombg';
  28.  
  29.     /**
  30.      *
  31.      * @var type
  32.      */
  33.     private $_password = 'lancombg123';
  34.  
  35.     /**
  36.      *
  37.      * @param type $request
  38.      * @param type $response
  39.      */
  40.     public function __construct($request = null, $response = null) {
  41.        
  42.         $this->_ch = curl_init();
  43.         parent::__construct($request, $response);
  44.     }
  45.  
  46.     /**
  47.      *
  48.      */
  49.     public function export() {
  50.  
  51.         echo '<pre>' . print_r($_SERVER, true) . '</pre>';
  52.         $data =
  53.                 array(
  54.                     'currentPage' => 1,
  55.                     'itemsPerPage' => 10
  56.         );
  57.  
  58.         $hash = sha1(http_build_query($data) . sha1($this->_password));
  59.  
  60.         $requestData = array(
  61.             'code' => 1,
  62.             'username' => $this->_username,
  63.             'data' => $data,
  64.             'hash' => $hash);
  65.  
  66.  
  67.  
  68.         curl_setopt($this->_ch, CURLOPT_URL, $this->_marketplase_url . 'api-3/category/read');
  69.  
  70.         curl_setopt($this->_ch, CURLOPT_SSL_VERIFYPEER, false);
  71.         curl_setopt($this->_ch, CURLOPT_FOLLOWLOCATION, 1);
  72.         curl_setopt($this->_ch, CURLOPT_HEADER, 0);
  73.         curl_setopt($this->_ch, CURLOPT_RETURNTRANSFER, 1);
  74.         curl_setopt($this->_ch, CURLOPT_CUSTOMREQUEST, 'POST');
  75.  
  76.         curl_setopt($this->_ch, CURLOPT_POSTFIELDS, http_build_query($requestData));
  77.  
  78.         $result = curl_exec($this->_ch);
  79.         echo '<pre>' . print_r(json_decode($result), true) . '</pre>';
  80.         die();
  81.     }
  82.  
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement