Esempio n. 1
0
 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);
 }
Esempio n. 2
0
 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);
 }
Esempio n. 3
0
 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'] : '');
     }
 }
Esempio n. 4
0
File: Tof.php Progetto: rgwybb/tars
 public function decryptTicket($encryptedTicket, $browseIP)
 {
     $appkey = Config::get('auth.appkey');
     return $this->request('Passport/DecryptTicketWithClientIP', compact('appkey', 'encryptedTicket', 'browseIP'));
 }
Esempio n. 5
0
File: Pkg.php Progetto: rgwybb/tars
 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;
 }
Esempio n. 6
0
define('BASEDIR', __DIR__);
include BASEDIR . '/Common/Loader.php';
include BASEDIR . '/Common/PHPMailer/PHPMailer.php';
// using PSR-0 coding standard
spl_autoload_register('\\Common\\Loader::autoload');
// check user post data
$check = new CommonAPI();
$check->check();
// get configure data, including hostname, $instance, $user and $password
$configFile = './config/sys_config.xml';
//echo realpath($configPath);
//if (file_exists($configPath)) {
//    echo "file exists";
//}
//new config
$cfg = new Config();
$configInfo = $cfg->getXml($configFile);
//var_dump($configInfo);
//exit;
///////////////////test data///////////////////
/// out of date
$configPath = './config/config';
$getConfig = new Get_Config($configPath);
if (!$getConfig->readConfig()) {
    exit('read configure file failure');
}
// Get parameters from xml
$hostname = $getConfig->hostname;
$instance = $getConfig->instance;
$username = $getConfig->username;
$password = $getConfig->password;