Exemplo n.º 1
0
 private function __construct($src, $debug, $request)
 {
     $this->_db = new DB('master');
     $this->_action = $src;
     $this->_request = $request;
     foreach ($this->_request as $k => $v) {
         switch ($k) {
             case 'userid':
             case 'nickname':
             case 'paymentid':
             case 'paymode':
                 $v = __paramValue('int', $v);
                 break;
             case 'amount':
                 $v = __paramValue('money', $v);
                 break;
             default:
                 $v = __paramValue('string', $v);
         }
         $this->_request[$k] = $v;
     }
     //        if ($debug) {
     $this->_log = new log('onlinedengi/income-%d%m%Y.log', 'a', '%d.%m.%Y %H:%M:%S : ' . self::$req_descr[$this->_action] . ' : ');
     $this->_log->addAlternativeMethodSave(new log_pskb(), true);
     $alt_out = array('param' => self::$req_descr[$this->_action], 'response' => $this->_request);
     $this->_log->setAlternativeWrite(serialize($alt_out), 'log_pskb');
     //            $dbg = var_export($this->_request, true);
     $this->_log->writevar($this->_request);
     //        }
 }
Exemplo n.º 2
0
 protected function _request($method, $params, $content_plain = false, $query_params = array('method' => 'POST'))
 {
     $ch = curl_init();
     $str_method = strtolower($method);
     $cp1251_params = $params;
     if (is_array($params)) {
         foreach ($params as $k => $v) {
             $params[$k] = $this->_enc($v);
         }
     } else {
         $params = $this->_enc($params);
     }
     if ($query_params['method'] == 'GET') {
         $method .= (defined('PSKB_TEST_MODE') ? "&" : "?") . http_build_query($params);
     }
     if (defined('PSKB_BETA_MODE')) {
         curl_setopt($ch, CURLOPT_PORT, 8085);
         curl_setopt($ch, CURLOPT_URL, "http://localhost/apiLCPlace/" . $method);
     } else {
         if (!defined('PSKB_TEST_MODE')) {
             curl_setopt($ch, CURLOPT_PORT, 8085);
             curl_setopt($ch, CURLOPT_URL, 'http://192.168.88.13/apiLCPlace/' . $method);
             //            curl_setopt($ch, CURLOPT_URL, "http://localhost/apiLCPlace/" . $method);
         } else {
             if (defined('BASIC_AUTH')) {
                 curl_setopt($ch, CURLOPT_USERPWD, BASIC_AUTH);
             }
             curl_setopt($ch, CURLOPT_URL, $this->_request_url . $method);
         }
     }
     if ($query_params['method'] == 'POST') {
         curl_setopt($ch, CURLOPT_POST, 1);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
     }
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
     curl_setopt($ch, CURLOPT_TIMEOUT, 30);
     if ($content_plain) {
         curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/plain'));
     }
     $res = curl_exec($ch);
     $log = new log("pskb/{$str_method}-" . SERVER . '-%d%m%Y.log', 'a', '%d.%m.%Y %H:%M:%S : ');
     if ($this->_useAlternativeLog) {
         $log->addAlternativeMethodSave(new log_pskb(), true);
         $alt_out = array('request_url' => $this->_request_url . $method, 'param' => $cp1251_params, 'response' => iconv('utf8', 'cp1251', $res));
         $log->setAlternativeWrite(serialize($alt_out), 'log_pskb');
     }
     ob_start();
     var_dump($this->_request_url . $method);
     var_dump($params);
     var_dump($res);
     $out = ob_get_clean();
     $log->writeln(iconv('utf8', 'cp1251', $out));
     return $res;
 }