PHP建站技术分享-从入门到精通_各类知识收集PHP建站技术分享-从入门到精通_各类知识收集PHP建站技术分享-从入门到精通_各类知识收集

QQ:420220301 微信/手机:150-3210-7690
当前位置:首页 > CMS教程 > Fastadmin

第三方登录如何微信自动登录

管理员 2024-12-14
Fastadmin
88

环境:fastadmin安装了第三方登录插件、表单可视化管理插件。

目的:如何实现前端可视化表单微信浏览自动微信登录

一:
application/index/controller/formdesign/Foreign.php做如下修改
引入:
use thinkRequest;
use thinkCache;
use appcommonlibraryAuth;
use thinkConfig;
use thinkController;
use thinkHook;
use thinkLang;
use thinkLoader;
use thinkValidate;

将frontend的重写,而不是直接parent::_initialize()引入
public function _initialize()

{    //parent::_initialize();                //移除HTML标签    $this->request->filter('trim,strip_tags,htmlspecialchars');    $modulename = $this->request->module();    $controllername = Loader::parseName($this->request->controller());    $actionname = strtolower($this->request->action());    // 如果有使用模板布局    if ($this->layout) {        $this->view->engine->layout('layout/' . $this->layout);    }    $this->auth = Auth::instance();    // token    $token = $this->request->server('HTTP_TOKEN', $this->request->request('token', thinkCookie::get('token')));    $path = str_replace('.', '/', $controllername) . '/' . $actionname;    // 设置当前请求的URI    $this->auth->setRequestUri($path);    // 检测是否需要验证登录    if (!$this->auth->match($this->noNeedLogin)) {        //初始化        $this->auth->init($token);        //检测是否登录        if (!$this->auth->isLogin()) {                        //获取当前url            Cache::set('redirecturl',Request::instance()->url(),3600);  //Cache方法            Session::set('redirecturl', Request::instance()->url()); //session方法无效,在不同控制器之前无法传值。                    //die(Session::pull("redirecturl"));            $this->error(__('Please login first'), 'third/connect/wechat');        }        // 判断是否需要验证权限        if (!$this->auth->match($this->noNeedRight)) {            // 判断控制器和方法判断是否有对应权限            if (!$this->auth->check($path)) {                $this->error(__('You have no permission'));            }        }    } else {        // 如果有传递token才验证是否登录状态        if ($token) {            $this->auth->init($token);        }    }    $this->view->assign('user', $this->auth->getUser());    // 语言检测    $lang = strip_tags($this->request->langset());    $site = Config::get("site");    $upload = appcommonmodelConfig::upload();    // 上传信息配置后    Hook::listen("upload_config_init", $upload);    // 配置信息    $config = [        'site'           => array_intersect_key($site, array_flip(['name', 'cdnurl', 'version', 'timezone', 'languages'])),        'upload'         => $upload,        'modulename'     => $modulename,        'controllername' => $controllername,        'actionname'     => $actionname,        'jsname'         => 'frontend/' . str_replace('.', '/', $controllername),        'moduleurl'      => rtrim(url("/{$modulename}", '', false), '/'),        'language'       => $lang    ];    $config = array_merge($config, Config::get("view_replace_str"));    Config::set('upload', array_merge(Config::get('upload'), $upload));    // 配置信息后    Hook::listen("config_init", $config);    // 加载当前控制器语言包    $this->loadlang($controllername);    $this->assign('site', $site);    $this->assign('config', $config);            Formsafe::safe_gpc();}

二:/addons/third/controller/index.php
use thinkCache;
// 注销这行代码

    //$url = Session::has("redirecturl") ? Session::pull("redirecturl") : url('index/user/index');    

// 改为这行代码,改为cache

    $url = !empty(Cache::get('redirecturl')) ? Cache::get('redirecturl') : url('index/user/index');        

三:分析
1、以上修改可以将任何前端控制器实现微信端自动登录,而不影响系统任何其它功能。
2、tp5的session为何不能在不同的控制器之间传值?
3、以上是我的思路,欢迎留言交流。



希望以上内容对你有所帮助!如果还有其他问题,请随时提问。 各类知识收集 拥有多年CMS企业建站经验,对 iCMS, LeCMS, ClassCMS, Fastadmin, PbootCMS, PHPCMS, 易优CMS, YzmCMS, 讯睿CMS, 极致CMS, Wordpress, HkCMS, YznCMS, WellCMS, ThinkCMF, 等各类cms的相互转化,程序开发,网站制作,bug修复,程序杀毒,插件定制都可以提供最佳解决方案。

相关推荐

扫码关注

qrcode

QQ交谈

回顶部