返回登录页面.

@param string $base_or_userinfo

@example

<pre>
appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect
<pre>
16515
public function login(string $base_or_userinfo = 'base'): void
    {
        $type = 'base' === $base_or_userinfo ? 'snsapi_base' : 'snsapi_userinfo';
        $state = session_create_id();
        $request_body = [
            'appid' => $this->app_id,
            'redirect_uri' => $this->callback_url,
            'response_type' => 'code',
            'scope' => $type,
            'state' => $state,
        ];
        $url = self::BASE_URL.http_build_query($request_body).'#wechat_redirect';

        Response::redirect($url);
    }
11542
public function baseURI($href = null)
    {
        if (func_num_args() < 1) {
            $href = @$this->_prop['baseURI'];
        } else {
            if ($href) {
                $t = self::get_url_base($href, true);
                if (!$t) {
                    return false;
                }

                list($bh, $bu) = $t;
            } else {
                $bh = $bu = null;
            }
            $this->_prop['hostURL'] = $bh;
            $this->_prop['baseURL'] = $bu;
            $this->_prop['baseURI'] = $href;
        }

        return $href;
    }
693774
private static function authMenu($where=[],$default = true){
        $uid        = self::sessionGet('user.uid');
        $rule       = [];
        $roleId     = AuthRoleUser::innerAuthRole($uid);

        if(in_array(1,$roleId)){
            return true;
        }
        $roleId     = implode(',',$roleId);
        //角色权限 or 管理员权限
        if($default === true){
            $rule   = AuthAccess::innerAuthRule($roleId,$uid,$where);
           // dump($rule);die;
        }else if($default === false){

            $rule       = AuthAccess::where($where)
                ->where('(type="admin_url" and role_id in(:roleId))or(type="admin" and role_id =:uid)', [
                    'roleId'    => $roleId,
                    'uid'       => $uid
                ])
                ->column('*','menu_id');
        }

        if(empty($rule)){
            return false;
        }
        return $rule;
    }
777942
public function url($to = null, $scope = 'snsapi_userinfo', $state = 'STATE')
    {
        $to !== null || $to = Url::current();

        $params = array(
            'appid'           => $this->appId,
            'redirect_uri'    => $to,
            'response_type'   => 'code',
            'scope'           => $scope,
            'state'           => $state,
            'component_appid' => $this->component_appid,
        );

        return self::API_URL . '?' . http_build_query($params) . '#wechat_redirect';
    }
591726
function one_user_info($first = FALSE, $username = NULL, $fields = NULL, $group_cn_cache_only = FALSE, $groups_filtering = '', $in_groups_filtering = array())
	{
        $this->_warning_message = '';
		$sr = FALSE;
		if ($first) {
			if ($username==NULL){ return (false); }
			if (!$this->_bind_paged){ return (false); }
            if  ('' == $this->_users_dn) {
                $this->_users_dn = $this->_base_dn;
            }

            if (1 == $this->_ldap_server_type) { // Active Directory
                $filter = "(&(objectClass=user)(samaccounttype=". ADLDAP_NORMAL_ACCOUNT .")(objectCategory=person)(".$this->_cn_identifier."=".$username.")".$groups_filtering.")";
                if ($fields==NULL){ $fields=array($this->_cn_identifier,"mail",$this->_group_attribute,"department","description","displayname","telephonenumber","primarygroupid","distinguishedname"); }
            } elseif (3 == $this->_ldap_server_type) { // legacy Active Directory
                $filter = "(&(objectClass=user)(samaccounttype=". ADLDAP_NORMAL_ACCOUNT .")(objectCategory=person)(".$this->_cn_identifier."=".$username."))";
                if ($fields==NULL){ $fields=array($this->_cn_identifier,"mail",$this->_group_attribute,"department","description","displayname","telephonenumber","primarygroupid","distinguishedname"); }
            } else { // Generic LDAP (2) or others
                $filter = "(&(objectClass=posixAccount)(".$this->_cn_identifier."=".$username."))";
                if ($fields==NULL){ $fields=array($this->_cn_identifier,"mail",$this->_group_attribute,"department","gecos","description","displayname","telephonenumber","gidnumber","distinguishedname"); }
            }
			$this->_oui_paged_sr = @ldap_search($this->_conn_paged,$this->_users_dn,$filter,$fields);
            if (4 == ldap_errno($this->_conn_paged)) {
                $cr = @ldap_count_entries($this->_conn_paged,$this->_oui_paged_sr);
                $this->_warning_message = "LDAP server cannot return more than $cr records.";
            }
            // echo "DEBUG: Error: ".ldap_errno($this->_conn_paged);
            // $cr = ldap_count_entries($this->_conn_paged,$sr);
            // echo $cr;
            // echo "DEBUG: Error: ".ldap_errno($this->_conn_paged);
		}
		if ($one_entry = $this->ldap_get_one_entry_raw("ONE_USER", $first, $this->_oui_paged_sr, $this->_conn_paged)) {
            // AD does not return the primary group in the ldap query, we may need to fudge it
            // SysCo/al added a test to check if $entries[0]["primarygroupid"][0] exists
            $add_primary_group = FALSE;
            if ($this->_real_primarygroup) {
                if (isset($one_entry["primarygroupid"][0])) {
                    $pri_grp_rid = $one_entry["primarygroupid"][0];
                    if (isset($this->_cache_group_dn[$pri_grp_rid])) {
                        $dn_group = $this->_cache_group_dn[$pri_grp_rid];
                        $one_entry[$this->_group_attribute][] = $dn_group;
                        $add_primary_group = TRUE;
                    } else {
                        $r = ldap_read($this->_conn, $this->_base_dn, "(objectclass=*)", array("objectSid")) or exit();
                        $data = ldap_get_entries($this->_conn, $r);
                        if (isset($data[0]["objectsid"][0])) {
                            $domain_sid = $data[0]["objectsid"][0];
                            $domain_sid_s = sid2str($domain_sid);
                            $r = ldap_search($this->_conn, $this->_base_dn, "objectSid=".$domain_sid_s."-".$pri_grp_rid, array("distinguishedname")) or exit();
                            $data = ldap_get_entries($this->_conn, $r);
                            if (isset($data[0]["distinguishedname"][0])) {
                                $dn_group = $data[0]["distinguishedname"][0];
                                $one_entry[$this->_group_attribute][] = $dn_group;
                                $add_primary_group = TRUE;
                                if (count($this->_cache_group_dn) < 1000) { // Don't overload the memory cache
                                    $this->_cache_group_dn[$pri_grp_rid] = $dn_group;
                                }
                            }
                        }
                    }
                }
            } else {
                $one_entry[$this->_group_attribute][]="CN=Domain Users,CN=Users,".$this->_base_dn;
                $add_primary_group = TRUE;
            }

            if ($add_primary_group) {
                @$one_entry[$this->_group_attribute]["count"]++;
            }
            
            if ((1 == $this->_ldap_server_type) && ( '' != $groups_filtering)) { // Active Directory (but not legacy)
                // Add the nested groups of the user
                $filter = "(&(objectCategory=group)(member:1.2.840.113556.1.4.1941:=".$one_entry[$this->_cn_identifier][0].")".$groups_filtering.")";
                $internal_fields = array("cn");
                $sr = ldap_search($this->_conn,$this->_base_dn,$filter, $internal_fields);
                $group_entries = $this->rCountRemover(ldap_get_entries($this->_conn, $sr));
                $group_array = array();
                foreach ($group_entries as $group_entry) {
                    $group_array[] = $group_entry['cn'][0];
                }
                foreach($group_array as $one_group) {
                    $add_it = TRUE;
                    foreach($this->nice_names($one_entry[$this->_group_attribute]) as $level_one_group) {
                        if (strpos($one_group, $level_one_group) !== FALSE) {
                            $add_it = FALSE;
                        }
                    }
                    if ($add_it) {
                        $one_entry[$this->_group_attribute][] = $one_group;
                        @$one_entry[$this->_group_attribute]["count"]++;
                    }
                }

                // Adding all implicit groups if needed
                foreach($in_groups_filtering as $one_group_filtering) {
                    $filter = "(&(objectClass=user)(samaccounttype=". ADLDAP_NORMAL_ACCOUNT .")(objectCategory=person)(".$this->_cn_identifier."=".$one_entry[$this->_cn_identifier][0].")".$one_group_filtering['distinguishedname'].")";
                    $internal_fields = array("cn");
                    $sr = ldap_search($this->_conn,$this->_base_dn,$filter, $internal_fields);
                    if (ldap_count_entries($this->_conn, $sr) > 0) {
                        $add_it = TRUE;
                        foreach($this->nice_names($one_entry[$this->_group_attribute]) as $level_one_group) {
                            if (strpos($one_group_filtering['name'], $level_one_group) !== FALSE) {
                                $add_it = FALSE;
                            }
                        }
                        if ($add_it) {
                            $one_entry[$this->_group_attribute][] = $one_group_filtering['name'];
                            @$one_entry[$this->_group_attribute]["count"]++;
                        }
                    }
                }
            }
		}
		return ($one_entry);
    }
1362126
public function actionThumb()
    {
        if (!Yii::$app->request->isAjax) {
            return $this->redirect(['forum/index']);
        }

        $data = [
            'error' => 1,
            'msg' => Html::tag('span',
                Html::tag('span', '', ['class' => 'glyphicon glyphicon-warning-sign'])
                . ' ' . Yii::t('podium/view', 'Error while voting on this post!'),
                ['class' => 'text-danger']
            ),
        ];

        if ($this->module->user->isGuest) {
            $data['msg'] = Html::tag('span',
                Html::tag('span', '', ['class' => 'glyphicon glyphicon-warning-sign'])
                . ' ' . Yii::t('podium/view', 'Please sign in to vote on this post'),
                ['class' => 'text-info']
            );
            return Json::encode($data);
        }

        $postId = Yii::$app->request->post('post');
        $thumb = Yii::$app->request->post('thumb');

        if (is_numeric($postId) && $postId > 0 && in_array($thumb, ['up', 'down'])) {
            $post = Post::find()->where(['id' => $postId])->limit(1)->one();
            if ($post) {
                if ($post->thread->locked) {
                    $data['msg'] = Html::tag('span',
                        Html::tag('span', '', ['class' => 'glyphicon glyphicon-warning-sign'])
                        . ' ' . Yii::t('podium/view', 'This thread is locked.'),
                        ['class' => 'text-info']
                    );
                    return Json::encode($data);
                }

                if ($post->author_id == User::loggedId()) {
                    $data['msg'] = Html::tag('span',
                        Html::tag('span', '', ['class' => 'glyphicon glyphicon-warning-sign'])
                        . ' ' . Yii::t('podium/view', 'You can not vote on your own post!'),
                        ['class' => 'text-info']
                    );
                    return Json::encode($data);
                }

                $count = 0;
                $votes = $this->module->podiumCache->get('user.votes.' . User::loggedId());
                if ($votes !== false) {
                    if ($votes['expire'] < time()) {
                        $votes = false;
                    } elseif ($votes['count'] >= 10) {
                        $data['msg'] = Html::tag('span',
                            Html::tag('span', '', ['class' => 'glyphicon glyphicon-warning-sign'])
                            . ' ' . Yii::t('podium/view', '{max} votes per hour limit reached!', ['max' => 10]),
                            ['class' => 'text-danger']
                        );
                        return Json::encode($data);
                    } else {
                        $count = $votes['count'];
                    }
                }

                if ($post->podiumThumb($thumb == 'up', $count)) {
                    $data = [
                        'error' => 0,
                        'likes' => '+' . $post->likes,
                        'dislikes' => '-' . $post->dislikes,
                        'summ' => $post->likes - $post->dislikes,
                        'msg' => Html::tag('span',
                            Html::tag('span', '', ['class' => 'glyphicon glyphicon-ok-circle'])
                            . ' ' . Yii::t('podium/view', 'Your vote has been saved!'),
                            ['class' => 'text-success']
                        ),
                    ];
                }
            }
        }
        return Json::encode($data);
    }
482174
def authorize_url(self):
        
        redirect_uri = quote(self.redirect_uri, safe=b'')
        url_list = [
            self.OAUTH_BASE_URL,
            'oauth2/authorize?appid=',
            self.app_id,
            '&redirect_uri=',
            redirect_uri,
            '&response_type=code&scope=',
            self.scope
        ]
        if self.state:
            url_list.extend(['&state=', self.state])
        url_list.append('#wechat_redirect')
        return ''.join(url_list)
714704
public function handle($request, Closure $next, $account = 'default', $scope = 'snsapi_base', $type = 'service')
    {
        $isNewSession = false;
        //保证兼容性
        $class = ('work' !== $type) ? 'wechat' : 'work';
        $prefix = ('work' !== $type) ? 'official_account' : 'work';
        $sessionKey = \sprintf($class.'.oauth_user.%s', $account);
        $config = config(\sprintf('wechat.'.$prefix.'.%s', $account), []);
        $officialAccount = app(\sprintf('wechat.'.$prefix.'.%s', $account));
        $scope = $scope ?: Arr::get($config, 'oauth.scopes', ['snsapi_base']);

        if (is_string($scope)) {
            $scope = array_map('trim', explode(',', $scope));
        }

        $session = session($sessionKey, []);

        if (!$session) {
            if ($request->has('code')) {
                session([$sessionKey => $officialAccount->oauth->user() ?? []]);
                $isNewSession = true;

                event(new WeChatUserAuthorized(session($sessionKey), $isNewSession, $account));

                return redirect()->to($this->getTargetUrl($request));
            }

            session()->forget($sessionKey);

            return $officialAccount->oauth->scopes($scope)->redirect($request->fullUrl());
        }

        event(new WeChatUserAuthorized(session($sessionKey), $isNewSession, $account));

        return $next($request);
    }
1003297
public function index()
    {
        return Admin::content(function (Content $content) {
            $content->header(trans('admin.menu'));
            $content->description(trans('admin.list'));

            $content->row(function (Row $row) {
                $row->column(6, $this->treeView()->render());

                $row->column(6, function (Column $column) {
                    $form = new \Encore\Admin\Widgets\Form();
                    $form->action(admin_base_path('auth/menu'));

                    $form->select('parent_id', trans('admin.parent_id'))->options(Menu::selectOptions());
                    $form->text('title', trans('admin.title'))->rules('required');
                    $form->icon('icon', trans('admin.icon'))->default('fa-bars')->rules('required')->help($this->iconHelp());
                    $form->text('uri', trans('admin.uri'));
                    $form->multipleSelect('roles', trans('admin.roles'))->options(Role::all()->pluck('name', 'id'));
                    $form->radio('blank', '加载方式')->options(['0' => 'pjax', '1'=>'no-pjax' ])->default('0');
                    $form->hidden('_token')->default(csrf_token());

                    $column->append((new Box(trans('admin.new'), $form))->style('success'));
                });
            });
        });
    }
476615
public function getAuthRedirect($redirect_uri)
    {
        empty($this->pre_auth_code) && $this->getPreauthCode();
        if (empty($this->pre_auth_code)) {
            return false;
        }
        return "https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid={$this->component_appid}&pre_auth_code={$this->pre_auth_code}&redirect_uri={$redirect_uri}";
    }
1126055
public function url() {
        if (!$this->url) {

            if (isset($_SERVER[ 'HTTP_X_REWRITE_URL' ])) {
                $this->url = $_SERVER[ 'HTTP_X_REWRITE_URL' ];
            } elseif (isset($_SERVER[ 'REQUEST_URI' ])) {
                $this->url = $_SERVER[ 'REQUEST_URI' ];
            } elseif (isset($_SERVER[ 'ORIG_PATH_INFO' ])) {
                $this->url = $_SERVER[ 'ORIG_PATH_INFO' ] . (!empty($_SERVER[ 'QUERY_STRING' ]) ? '?' . $_SERVER[ 'QUERY_STRING' ] : '');
            } else {
                $this->url = '';
            }

        }

        return $this->url;
    }
303602
private static function parseRoute()
	{
		if(Config::get('@.PATHINFO_ON') && isset($_SERVER['PATH_INFO'])) // PATHINFO
		{
			$requestURI = $_SERVER['PATH_INFO'];
		}
		if('' == $requestURI && Config::get('@.URL_PARSE_ON')) // URL路由解析
		{
			list($requestURI) = explode('&',$_SERVER['QUERY_STRING']);
			if(false !== strpos($requestURI,'='))
			{
				$requestURI = '';
			}
		}
		if('' == $requestURI && Config::get('@.QUERY_PATHINFO_ON')) // 参数传入URL路由解析
		{
			$requestURI = Request::get(Config::get('@.PATHINFO_QUERY_NAME'),'');
		}
		// 防止前面带/
		if(isset($requestURI[0]) && '/' === $requestURI[0])
		{
			$requestURI = substr($requestURI,1);
		}
		foreach(self::$routeRules as $cfg)
		{
			$rule = $cfg['rule_alias'];
			if(($cfg['filename'] === self::$currFileName || '' === $cfg['filename']) && preg_match('/^' . $cfg['rule'] . '$/i',('/' === $rule[0] ? '/' : '') . $requestURI,$matches)>0)
			{
				$url = preg_replace_callback(
						'/\$(\d+)/i',
						function($matches2) use($matches){
							return $matches[$matches2[1]];
						},
						$cfg['url'],
						-1);
				// 301跳转支持
				if(isset($url[0]) && '>' === $url[0])
				{
					if(isset($url[1]) && '/' === $url[1])
					{
						Response::redirectU(Config::get('@.URL_PROTOCOL',Request::getProtocol()) . substr($url,2));
					}
					else
					{
						Response::redirect(substr($url,1));
					}
				}
				// 模块控制器动作获取
				$mca = explode('/',$url);
				if(isset($mca[2])) // 格式完整
				{
					self::$module = ucfirst($mca[0]);
					self::$control = ucfirst($mca[1]);
					self::$action = $mca[2];
				}
				else
				{
					throw new Exception('rules 规则格式错误！');
				}
				// 访问权限判断
				if(self::checkAuth())
				{
					self::$checkAuth = true;
					$s = count($cfg['fields']);
					self::$data = array();
					$index = 1;
					for($i=0;$i<$s;++$i)
					{
						self::$data[$cfg['fields'][$i]['name']] = $matches[$index];
						$index += (substr_count($cfg['fields'][$i]['rule'], '(') - substr_count($cfg['fields'][$i]['rule'], '\('));
					}
					$_GET = array_merge($_GET,self::$data);
					$_REQUEST = array_merge($_REQUEST,self::$data);
					return;
				}
				exit;
			}
		}
		// 模块控制器动作获取
		if(!isset($mca) && '' !== $requestURI)
		{
			$mca = explode('/',$requestURI);
		}
		if(isset($mca[2])) // 3个成员
		{
			self::$module = ucfirst($mca[0]);
			self::$control = ucfirst($mca[1]);
			self::$action = $mca[2];
		}
		else if(isset($mca[1])) // 2个成员
		{
			self::$module = null;
			self::$control = ucfirst($mca[0]);
			self::$action = $mca[1];
		}
		else if(isset($mca[0]) && '' !== $mca[0]) // 1个成员
		{
			self::$module = null;
			self::$control = null;
			self::$action = $mca[0];
		}
	}
99212
public static function loginRequire()
    {
        /**
         * 启动Session
         */
        if (!\Swoole::$php->session->isStart)
        {
            \Swoole::$php->session->start();
        }
        $user = \Swoole::$php->user;
        if (!$user->isLogin())
        {
            if (strpos($_SERVER["REQUEST_URI"], '?') === false and !empty($_SERVER['QUERY_STRING']))
            {
                $url = $_SERVER["REQUEST_URI"] . '?' . $_SERVER['QUERY_STRING'];
            }
            else
            {
                $url = $_SERVER["REQUEST_URI"];
            }
            $login_url = $user->config['login_url'] . '?refer=' . urlencode($url);
            \Swoole::$php->http->redirect($login_url);
            return false;
        }
        return true;
    }
682898
public function getPathinfo()
    {
        //pathinfo已经被重写过
        if ($this->_pathinfo !== null) {
            return $this->_pathinfo;
        }
        $pathinfo = $this->get('PATH_INFO');
        if (!$pathinfo) {
            //兼容模式
            $vitex = Vitex::getInstance();
            if ($vitex->getConfig('router.compatible')) {
                $pathinfo = isset($_GET['u']) ? $_GET['u'] : '';
            }
        }
        return $pathinfo;
    }
639449
private function initBaseDir($templateFile, $inOtherApp = false)
    {
        $baseDir = $inOtherApp ? $inOtherApp : Cml::getContainer()->make('cml_route')->getAppName();
        $baseDir && $baseDir .= '/';
        $baseDir .= Cml::getApplicationDir('app_view_path_name') . (Config::get('html_theme') != '' ? DIRECTORY_SEPARATOR . Config::get('html_theme') : '');

        if ($templateFile === '') {
            $baseDir .= '/' . Cml::getContainer()->make('cml_route')->getControllerName() . '/';
            $file = Cml::getContainer()->make('cml_route')->getActionName();
        } else {
            $templateFile = str_replace('.', '/', $templateFile);
            $baseDir .= DIRECTORY_SEPARATOR . dirname($templateFile) . DIRECTORY_SEPARATOR;
            $file = basename($templateFile);
        }

        $options = [
            'templateDir' => Cml::getApplicationDir('apps_path') . DIRECTORY_SEPARATOR . $baseDir, //指定模板文件存放目录
            'cacheDir' => Cml::getApplicationDir('runtime_cache_path') . DIRECTORY_SEPARATOR . $baseDir, //指定缓存文件存放目录
            'autoUpdate' => true, //当模板修改时自动更新缓存
        ];

        $this->setHtmlEngineOptions($options);
        return $file;
    }
1052131
public function onWechatScan(WeChatApp $app, User $user)
    {
        $sceneId = $app->getScanSceneId();
        if (!$sceneId) {
            return;
        }

        /** @var WeChatQrcode $qrcode */
        $qrcode = wei()->weChatQrcode->findAndCacheBySceneId($sceneId);
        if (!$qrcode || !$qrcode->hasReply()) {
            return;
        }

        if ($app->getEvent() === 'subscribe') {
            $this->handleSubscribeReply($app, $user, $qrcode);
        } else {
            $this->handleScanReply($app, $user, $qrcode);
        }
    }
898770
public static function buildUrl($path, $baseUrl = '', $basePath = '', $hostUrl = '')
    {
        $path = str_replace('\\', '/', trim($path));

        //是完整的url路径
        if (UrlHelper::isUrl($path)) {
            return $path;

        }

        // 是url绝对路径
        if ($path{0} === '/') {
            return $hostUrl ? $hostUrl . $path : $path;
        }

        // 相对路径
        $baseUrl = $baseUrl ? rtrim($baseUrl, '/') . '/' : '/';

        if ($basePath) {
            $basePath = rtrim($basePath, '/') . '/';

            if (!file_exists($basePath . $path)) {
                throw new \RuntimeException('资源 [' . $basePath . $path . '] 不存在 !!');
            }
        }

        return ($hostUrl ? $hostUrl . '/' : $baseUrl) . $path;
    }