3.获取预授权码
@return mixed
@throws \Exception
554571
public function preAuthCode() {
        $key = 'WeChatThirdPreAuthCode';
        if (Factory::cache()->has($key)) {
            return Factory::cache()->get($key);
        }
        $args = $this->getPreAuthCode()->json();
        if (!is_array($args)) {
            throw new \Exception('HTTP ERROR!');
        }
        if (!array_key_exists('pre_auth_code', $args)) {
            throw new \Exception(isset($args['errmsg']) ? $args['errmsg'] : 'GET ACCESS TOKEN ERROR!');
        }
        Factory::cache()->set($key, $args['pre_auth_code'], $args['expires_in']);
        return $args['pre_auth_code'];
    }
188361
public function convertData()
    {
        $ver = $this->estimateVersion();
        if($ver > $this->getVersion()) {
            $this->setVersion($ver);
        }

        for(;;) {
            $bits = $this->createBitStream();

            if($bits < 0)
                return -1;

            $ver = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level);
            if($ver < 0) {
                throw new Exception('WRONG VERSION');
                return -1;
            } else if($ver > $this->getVersion()) {
                $this->setVersion($ver);
            } else {
                break;
            }
        }

        return 0;
    }
691179
public function exceptionAction() {
		
		// get the exception
		$this->Exception = Store\Request::get('exception');
		// if the exception is not a 404 or a 403 (the most common and non important)
		if(
			$this->Exception->getCode() < 401 || 
			$this->Exception->getCode() > 404
		) {
			// log the exception
			Logger::critical(
				$this->Exception->getCode() . ' '.
				$this->Exception->getMessage(), 
				$this->Exception->getTrace()
			);
		}
		// error occured while requesting something else than html
		if(!in_array(
			Response::getType(), 
			['html','html-page']
		)) {
			// change the type to plaintext
			Response::setType('text');
			// set the stack a string
			Response::setContent(
				$this->Exception->getCode() . "\n".
				$this->Exception->getMessage() . "\n".
				$this->Exception
			);
			// render as is
			Response::render();
		}
		// error occured normally
		else {
			// disable space removal for the trace stack
			Config::set('response','minify', 0);
			// reset already output data (very important, because of content-length)
			Response::setType('html-page');
			// proper title and assets
			Response\HTML::set([
				'metas'		=>[
					'title'=> $this->Exception->getCode() . ', ' . 
						Locales::get($this->Exception->getMessage())
				],
				'scripts'	=>[
					'//code.jquery.com/jquery-3.3.1.slim.min.js',
					'//stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.bundle.min.js'
				],
				'links'		=>[
					'//stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css',
					'//use.fontawesome.com/releases/v5.3.1/css/all.css'
				]
			]);
			
			// error is of type forbidden/bad request
			if(
				$this->Exception->getCode() >= 400 && 
				$this->Exception->getCode() <= 403
			) {
				$this->icon = 'fa fa-ban';
			}
			// error is of type internal error
			elseif(
				$this->Exception->getCode() >= 500 && 
				$this->Exception->getCode() <= 599
			) {
				$this->icon = 'fa fa-bug';
			}
			// error is not found
			elseif(
				$this->Exception->getCode() == 404
			) {
				$this->icon = 'fa fa-exclamation-circle';
			}
			// any other type of errors
			else {
				$this->icon = 'fa fa-exclamation-triangle';
			}

			// pass to the exception view
			$this->view('Exception');
		}
			
	}
28160
public function run() {

		try {
			
			//初始化
			$this->init();

			//触发uri路由
			$this->make('router')->dispatch();

			//reset GET
			$_GET = $this->make('router')->getQueryArray();
			foreach ($_GET as $ik => $iv) {
				if (is_string($ik)) {
					$_REQUEST[$ik] = $iv;
				}
			}

			$this->runControllerAction();

			//结束
			$this->finish(0);

		} catch (\Exception $exception) {
			
			if ($this->currentController == null) {
				$this->currentController = new Controller($this, ''); //默认的controller
			}
			
			//触发事件
			$this->eventDispatcher->dispatchEvent(new \Fasim\Event\ExceptionEvent(\Fasim\Event\Event::$EXCEPTION, $exception));

			$config = $this->make('config');
			$view = $this->currentController->getView();
			$view->getLoader()->setPaths([ FS_PATH . 'View' ]);


			$debug = $this->make('config')->get('debug') === true;
			$traceString = str_replace("\n", "<br />\n", $traceString);
			$error = [
				'code' => $exception->getCode(),
				'message' => $exception->getMessage(),
				'file' => $exception->getFile(),
				'line' => $exception->getLine(),
				'trace' => $exception->getTrace()
			];
			$data = [
				'error' => $error,
				'debug' => $debug
			];
			
			if (file_exists(FS_PATH . 'View' . DIRECTORY_SEPARATOR . 'error' . $exception->getCode() . '.html')) {
				echo $view->render('error' . $exception->getCode() . '.html', $data);
			} else {
				echo $view->render('error500.html', $data);
			}
		
			//结束
			$this->finish(-1);
		}
	}
1210077
public function from()
    {
        $from = '';

        $numargs = func_num_args();

        if ($this->oosql_del_multiFlag) {


            if ($numargs < $this->oosql_del_numargs) {
                $msg = 'Columns and passed data do not match! ' . $this->sql();
                throw new \Exception($msg, 9810, null);
            }


        }

        $from .= ' FROM ';

        $from .= $this->oosql_table;

        if ($numargs > 0) {
            $from .= ', ';

            $arg_list = func_get_args();

            for ($i = 0; $i < $numargs; $i++) {
                if ($i !== 0 && $numargs > $i) {
                    $from .= ', ';
                }

                if ($arg_list[$i] instanceof oosql) {

                    $arg_list[$i]->alias();
                    $fields = $arg_list[$i]->getFields($arg_list[$i]->getTableAlias());

                    $this->sql(',' . implode(', ', $fields));
                    $from .= $arg_list[$i]->getSql() . ' AS ' . $arg_list[$i]->getTableAlias();
                } else {
                    $from .= $arg_list[$i];
                }
            }
        }

        $this->sql($from);

        $this->oosql_fromFlag = false;

        return $this;
    }
64823
protected function open()
    {
        if (null === $this->_pdo) {
            if (empty($this->dsn)) {
                throw new Exception('数据库连接串"dsn"不能为空', 101300101);
            }
            try {
                Timer::begin('db-connect');

                $this->_pdo = $this->createPdoInstance();
                $this->initConnection($this->_pdo);
                $this->_active = true;

                $this->pushLog('connect-db', [
                    'lastTime' => Timer::end('db-connect'),
                ]);
            } catch (\PDOException $e) {
                if (APP_DEBUG) {
                    $err_msg = '数据库连接失败: (' . $e->getCode() . ')' . $e->getMessage();
                } else {
                    $err_msg = '数据库连接失败.(' . $e->getCode() . ')';
                }
                throw new Exception($err_msg, 101300102, $e->errorInfo);
            }
        }
    }
1264150
public function run()
    {
        if (($exception = Yii::$app->getErrorHandler()->exception) === null) {
            return '';
        }

        if ($exception instanceof \HttpException) {
            $code = $exception->statusCode;
        } else {
            $code = $exception->getCode();
        }

        if ($exception instanceof Exception) {
            $name = $exception->getName();
        } else {
            $name = $this->defaultName ?: Yii::t('yii', 'Error');
        }

        if ($code) {
            $name .= " (#$code)";
        }

        if ($exception instanceof UserException) {
            $message = $exception->getMessage();
        } else {
            $message = $this->defaultMessage ?: Yii::t('yii', 'An internal server error occurred.');
        }


        if (Yii::$app->getRequest()->getIsAjax()) {
            $rr = new RequestResponse();

            $rr->success = false;
            $rr->message = "$name: $message";

            return (array)$rr;
        } else {
            //All requests are to our backend
            //TODO::Add image processing
            $info = pathinfo(\Yii::$app->request->pathInfo);
            if ($extension = ArrayHelper::getValue($info, 'extension')) {
                $extension = \skeeks\cms\helpers\StringHelper::strtolower($extension);
                if (in_array($extension, ['js', 'css'])) {
                    \Yii::$app->response->format = Response::FORMAT_RAW;
                    if ($extension == 'js') {
                        \Yii::$app->response->headers->set('Content-Type', 'application/javascript');
                    }
                    if ($extension == 'css') {
                        \Yii::$app->response->headers->set('Content-Type', 'text/css');
                    }

                    $url = \Yii::$app->request->absoluteUrl;
                    return "/* File: '{$url}' not found */";
                }
            }

            return $this->controller->render($this->view ?: $this->id, [
                'name' => $name,
                'message' => $message,
                'exception' => $exception,
            ]);
        }
    }
1218821
public function token() {
        $key = 'WeChatToken'.$this->get('appid');
        if (Factory::cache()->has($key)) {
            return Factory::cache()->get($key);
        }
        $args = $this->getToken()->json();
        if (!is_array($args)) {
            throw new Exception('HTTP ERROR!');
        }
        if (!array_key_exists('access_token', $args)) {
            throw new Exception(isset($args['errmsg']) ?
                $args['errmsg'] : 'GET ACCESS TOKEN ERROR!');
        }
        Factory::cache()->set($key, $args['access_token'], $args['expires_in']);
        return $args['access_token'];
    }
128865
public function getSync()
    {
        if (isset($this->redisClient)) {
            return $this->redisClient;
        }

        //task进程内同步redis连接
        $this->redisClient = new \Redis();
        $conf              = $this->config['redis'][$this->active];
        $addr              = $conf['ip'] . ':' . $conf['port'] . ' ';
        try {
            // 连接
            if (!$this->redisClient->connect($conf['ip'], $conf['port'], 0.05)) {
                throw new Exception($this->redisClient->getLastError());
            }

            // 验证
            if ($this->config->has('redis.' . $this->active . '.password')) {//存在验证
                $addr .= 'auth password failed, message ';
                if (!$this->redisClient->auth($this->config['redis'][$this->active]['password'])) {
                    throw new Exception($this->redisClient->getLastError());
                }
            }

            // select
            if ($this->config->has('redis.' . $this->active . '.select')) {//存在验证
                $addr .= 'select failed, message ';
                if (!$this->redisClient->select($this->config['redis'][$this->active]['select'])) {
                    throw new Exception($this->redisClient->getLastError());
                }
            }
        } catch (Exception $e) {
            throw new Exception($addr . $e->getMessage());
        }

        return $this->redisClient;
    }
856660
final public function delete()
    {
        if (!$this->DB) {
            throw  new Exception('您还没有连接数据库', Exception::CODE_DATABASE_ERROR);
        }
        $sql = "delete from " . $this->getTable() . " ";
        $where = $this->buildWhere();
        //条件判断
        //没有外部条件的时候查询当前对象是否有查询过的模型
        if (!$where && $this->isfind) {
            $this->where($this->pk, '=', $this->pkval);
            $where = $this->buildWhere();
        }
        if (!$where) {
            throw new \Error('删除全部数据请使用truncate方法', Exception::CODE_DATABASE_ERROR);
        }
        $sql .= $where;
        $this->sql = $sql;
        /**
         * 只获取sql
         */
        if ($this->justSql) {
            return true;
        }
        $ret = $this->DB->execute($sql);
        $this->resetCon();
        return $ret;
    }
504971
protected static function getTypo3Version()
    {
        if (is_null(static::$version)) {
            static::$version = \TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionNumberToInteger(TYPO3_branch);
        }
        return static::$version;
    }
838389
public function postStep3()
    {
        $postData = Binput::all();

        $v = Validator::make($postData, $this->rulesStep1 + $this->rulesStep2 + $this->rulesStep3);

        if ($v->passes()) {
            // Pull the user details out.
            $userDetails = Arr::pull($postData, 'user');

            $user = User::create([
                'username' => $userDetails['username'],
                'email'    => $userDetails['email'],
                'password' => $userDetails['password'],
                'level'    => User::LEVEL_ADMIN,
            ]);

            Auth::login($user);

            $setting = app(Repository::class);

            $settings = Arr::pull($postData, 'settings');

            foreach ($settings as $settingName => $settingValue) {
                $setting->set($settingName, $settingValue);
            }

            $envData = Arr::pull($postData, 'env');

            // Write the env to the .env file.
            execute(new UpdateConfigCommand($envData));

            if (Request::ajax()) {
                return Response::json(['status' => 1]);
            }

            return cachet_redirect('dashboard');
        }

        if (Request::ajax()) {
            return Response::json(['errors' => $v->getMessageBag()], 400);
        }

        return cachet_redirect('setup')->withInput()->withErrors($v->getMessageBag());
    }
169486
public function create(): string
    {
        switch ($this->operation) {
            case 'exist':
                // 判断是否存在满足条件的记录
                return $this->createExist();
            case 'query':
            case 'repair':
            case 'optimize':
            case 'call':
                // 直接SQL查询
                return $this->createQuery();
            case 'execute':
                // 直接SQL操作
                return $this->createExecute();
            case 'insert':
                // 插入
            case 'replace':
                // 存在则替换,否则插入
            case 'insertIgnore':
                // 存在则忽略,否则插入
                return $this->createAdd();
            case 'inserts':
                //多行插入
                return $this->createInserts();
            case 'update':
                // 修改
                return $this->createUpdate();
            case 'delete':
                // 删除
                return $this->createDelete();
            case 'deleteAll':
                // 删除全部
                return $this->createDeleteAll();
            case 'select':
                // 查询
            case 'selectHandle':
                // 查询并返回句柄
                return $this->createSelect();
            case 'crease':
                // 增减
                return $this->createCrease();
        }
        trigger_error('无法识别或不支持的SQL命令:' . $this->operation, E_USER_ERROR);
        return '';
    }
1173370
public function getError()
    {
        if ($this->PDOStatement) {
            $error = $this->PDOStatement->errorInfo();
            $error = $error[1] . ':' . $error[2];
        } else {
            $error = '';
        }

        if ('' != $this->queryStr) {
            $error .= "\n [ SQL语句 ] : " . $this->getLastsql();
        }

        return $error;
    }
390849
public function postIndex()
	{
		if ( ! Input::hasFile('file'))
		{
			return Response::json(array('error' => 'File is required'), 400);
		}

		$contents = trim(File::get(Input::file('file')->getRealPath()));

		if (substr($contents, 0, 3) !== '---')
		{
			throw new Exception('Bad Markdown Formatting');
		}

		if ( ! ($pos = strpos($contents, '---', 3)))
		{
			throw new Exception('Bad Markdown Formatting');
		}

		$frontMatter = trim(substr($contents, 3, $pos - 3));
		$contents = trim(substr($contents, $pos + 3));

		$yaml = new Parser();

		$fields = $yaml->parse($frontMatter);

		return Response::json(array(
			'fields' => $fields,
			'content' => $contents
		));
	}
903789
public function get3pid()
    {
        if ($this->check()) {
            return $this->matrix()->request('GET', $this->endpoint('account/3pid'), [], [
                    'access_token' => $this->data['access_token']
                ]);
        }
        throw new \Exception('Not authenticated');
    }
246730
public function tryGetResource()
    {
        if($this->getFree() <= 0)
        {
            if($this->getCount() < $this->config->getMaxResources())
            {
                // 没有空闲连接，当前连接数少于最大连接数
                $this->addResource();
            }
            else 
            {
                return false;
            }
        }
        $read = [$this->queue];
        $write = null;
        // Coroutine\Channel::select()/->pop() 最小超时时间1毫秒
        if(SWOOLE_VERSION < '4.0.3')
        {
            $result = Channel::select($read, $write, 0.001);
        }
        else
        {
            $result = $this->queue->pop(0.001);
        }
        if(false === $result)
        {
            return false;
        }
        if(true === $result)
        {
            $resource = $this->queue->pop();
        }
        else
        {
            $resource = $result;
        }
        if(!$resource->checkState() && !$resource->open())
        {
            throw new \RuntimeException(sprintf('AsyncPool [%s] tryGetResource failed', $this->getName()));
        }
        return $resource;
    }