/** * 初始化,注册错误处理函数 */ public function __construct() { date_default_timezone_set('PRC'); $this->time_start = microtime(true); if (App::environment() != 'production') { Log::info('request: ' . Request::url() . ' with input:' . json_encode(Input::all())); } //从配置中取出需要登录的API $requireLoginApis = Config::get('rest.api_required_login'); foreach ($requireLoginApis as $api) { if (Request::is("*{$api}*")) { $this->beforeFilter('@auth'); } } $input = Input::all(); $json = Input::get('json'); if (!empty($json)) { $jsonData = @json_decode($json, true); !is_array($jsonData) || ($input = array_merge($input, $jsonData)); } $input = multi_urldecode($input); Request::merge($input); $uid = Input::get('uid'); $sid = Input::get('sid'); if (!empty($uid) && !empty($sid)) { //$this->currentUser = User::whereId(Input::get('uid'))->remember(60)->first(); $this->currentUser = User::whereId(Input::get('uid'))->first(); if ($this->currentUser && $this->currentUser->locked()) { return self::error(self::STATUS_ACCOUNT_LOCKED, '账户被锁定'); } } }
function multi_urldecode(array $array) { foreach ($array as $key => $value) { if (is_string($value)) { $array[$key] = urldecode($value); } else { if (is_array($value)) { $array[$key] = multi_urldecode($value); } } } return $array; }