public function request($path, array $query = null, array $data = null, $method = 'GET') { $url = Config::get('pkg.api_url') . 'user/' . $path; $host = Config::get('pkg.api_host'); $timeout = self::TIMEOUT; $header = array(); // 请求头中加入 `token` if ($this->token) { $header[] = 'Tars-Token: ' . $this->token; } /* else { $header[] = 'Tars-Token: no'; }*/ // GET 参数 if ($query) { $url .= '?' . http_build_query($query); } $options = compact('url', 'method', 'host', 'timeout'); // 请求主体 if ($data) { $header[] = 'Content-Type: application/json'; $options['data'] = json_encode($data); } $options['header'] = $header; return $this->curl($options); }
public function request($path, array $query = null, array $data = null, $method = 'GET') { $url = Config::get('pkg.api_url') . 'user/' . $path; $host = Config::get('pkg.api_host'); $timeout = self::TIMEOUT; $header = array('Content-Type: application/json'); if ($query) { $url .= '?' . http_build_query($query); } $options = compact('url', 'method', 'host', 'header', 'timeout'); if ($data) { $options['data'] = json_encode($data); } return $this->curl($options); }
public function auth() { $req = Flight::request(); $ticket = $req->query->ticket; if (!$ticket) { Flight::halt(400); } $tof = new Tof(); $ret = $tof->decryptTicket($ticket, $req->ip); if ($ret && $ret['Ret'] === 0) { $data = $ret['Data']; session_start(); $_SESSION['token'] = $data['Token']; $_SESSION['id'] = $data['StaffId']; $_SESSION['username'] = $data['LoginName']; $isAdmin = in_array($_SESSION['username'], explode(',', Config::get('auth.admin_list'))); $_SESSION['role'] = $isAdmin ? 'admin' : 'user'; session_write_close(); Flight::redirect('/'); } else { Flight::halt(500, $ret ? $ret['ErrMsg'] : ''); } }
public function decryptTicket($encryptedTicket, $browseIP) { $appkey = Config::get('auth.appkey'); return $this->request('Passport/DecryptTicketWithClientIP', compact('appkey', 'encryptedTicket', 'browseIP')); }
public function downloadFile($path, $home = null) { $url = Config::get('pkg.api_url') . 'pack/download_file' . '?' . http_build_query(compact('path', 'home')); $host = Config::get('pkg.api_host'); $timeout = 0; $method = 'GET'; $options = compact('url', 'host', 'method', 'timeout'); $options[CURLOPT_HEADER] = 1; $curl = new Curl(); $ret = $curl->curl($options, false, function ($ch, $result) use(&$size) { if ($result !== false) { $size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); } }); if ($ret !== false && $ret !== null) { $ret = array('header' => substr($ret, 0, $size), 'body' => substr($ret, $size)); } else { $error = $curl->curlLastError(); $ret = $error->getHttpStatus(); } return $ret; }