<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace Module\Vendor\SDK; use ModStart\Core\Input\Response; use ModStart\Core\Util\CurlUtil; use Module\Vendor\Log\Logger; class HttpRequest { protected $LOG_FILE = 'base_request'; protected $LOG_PREFIX = 'BaseRequest'; protected $BASE_URL = ''; protected $REQUEST_INTERVAL_US = 0; protected function info($dScvi, $fBbl8) { Logger::info($this->LOG_FILE, $this->LOG_PREFIX . '.' . $dScvi, $fBbl8); } protected function error($dScvi, $fBbl8) { Logger::error($this->LOG_FILE, $this->LOG_PREFIX . '.' . $dScvi, $fBbl8); } public function setBaseUrl($SKxst) { $this->BASE_URL = $SKxst; } protected function post($C1E2v, $OzAEo, $aY5Ol = array()) { goto wB4Vi; lMAB_: $this->info('PostResponse', array('elapse ' . intval((microtime(true) - $aiKb9) * 1000) . 'ms', $C1E2v, $yvBIN)); goto gVO4N; vjXAP: $this->info('PostRequest', array($C1E2v, $OzAEo, $aY5Ol)); goto jqOvq; aHdNo: $yvBIN = CurlUtil::post($this->BASE_URL . $C1E2v, $OzAEo, $aY5Ol); goto lMAB_; gVO4N: if (!isset($yvBIN['body'])) { $this->error('PostError', array($C1E2v, $OzAEo, $aY5Ol)); return Response::generate(-1, '请求失败(' . $C1E2v . ')'); } goto A1PJe; jqOvq: $aiKb9 = microtime(true); goto aHdNo; A1PJe: return Response::generate(0, 'ok', $yvBIN['body']); goto XO6X2; wB4Vi: if ($this->REQUEST_INTERVAL_US > 0) { usleep($this->REQUEST_INTERVAL_US); } goto vjXAP; XO6X2: } protected function postJSON($C1E2v, $OzAEo, $aY5Ol = array()) { goto hC7Bx; MgQdN: $this->info('PostJSONRequest', array($C1E2v, $OzAEo, $aY5Ol)); goto M4kf2; tnmEq: $this->info('PostJSONResponse', array('elapse ' . intval((microtime(true) - $aiKb9) * 1000) . 'ms', $C1E2v, $yvBIN)); goto IomHw; M4kf2: $aiKb9 = microtime(true); goto YznAv; YznAv: $yvBIN = CurlUtil::postJSON($this->BASE_URL . $C1E2v, $OzAEo, $aY5Ol); goto tnmEq; hC7Bx: if ($this->REQUEST_INTERVAL_US > 0) { usleep($this->REQUEST_INTERVAL_US); } goto MgQdN; IomHw: return $yvBIN; goto qB15p; qB15p: } protected function get($C1E2v, $OzAEo, $aY5Ol = array()) { goto Ht23v; vrgTi: $this->info('GetRequest', array($C1E2v, $OzAEo, $aY5Ol)); goto HGYZP; HGYZP: $aiKb9 = microtime(true); goto vezBe; B4PmF: return Response::generate(0, 'ok', $yvBIN['body']); goto Gth_J; OQkF1: $this->info('GetRequest', array('elapse ' . intval((microtime(true) - $aiKb9) * 1000) . 'ms', $C1E2v, $yvBIN)); goto B4PmF; vezBe: $yvBIN = CurlUtil::get($this->BASE_URL . $C1E2v, $OzAEo, $aY5Ol); goto OQkF1; Ht23v: if ($this->REQUEST_INTERVAL_US > 0) { usleep($this->REQUEST_INTERVAL_US); } goto vrgTi; Gth_J: } protected function getJSON($C1E2v, $OzAEo, $aY5Ol = array()) { goto fDeUb; LI254: $this->info('GetJSONRequest', array($C1E2v, $OzAEo, $aY5Ol)); goto c0C1H; OUkl2: $this->info('GetJSONResponse', array('elapse ' . intval((microtime(true) - $aiKb9) * 1000) . 'ms', $C1E2v, $yvBIN)); goto gygFT; c0C1H: $aiKb9 = microtime(true); goto ls182; fDeUb: if ($this->REQUEST_INTERVAL_US > 0) { usleep($this->REQUEST_INTERVAL_US); } goto LI254; gygFT: return $yvBIN; goto NpED4; ls182: $yvBIN = CurlUtil::getJSON($this->BASE_URL . $C1E2v, $OzAEo, $aY5Ol); goto OUkl2; NpED4: } }