打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
larevl5.3自定义认证guards

config/auth.php添加guard

    'guards' => [        'web' => [            'driver' => 'session',            'provider' => 'users',        ],        'admin' => [            'driver' => 'session',            'provider' => 'admins',        ],        'three' => [            'driver' => 'session',            'provider' => 'threes',        ],        'api' => [            'driver' => 'token',            'provider' => 'users',        ],        'admin_wxuser' => [            'driver' => 'session',            'provider' => 'admin_wxusers',        ],    ],    /*    |--------------------------------------------------------------------------    | User Providers    |--------------------------------------------------------------------------    |    | All authentication drivers have a user provider. This defines how the    | users are actually retrieved out of your database or other storage    | mechanisms used by this application to persist your user's data.    |    | If you have multiple user tables or models you may configure multiple    | sources which represent each model / table. These sources may then    | be assigned to any extra authentication guards you have defined.    |    | Supported: "database", "eloquent"    |    */    'providers' => [        'users' => [            'driver' => 'eloquent',            'model' => App\Models\User::class,        ],        'admins' => [            'driver' => 'eloquent',            'model' => App\Models\Admin::class,        ],        'threes' => [ //第三方用户            'driver' => 'eloquent',            'model' => App\Models\ThreeUser::class,        ],        'admin_wxusers' => [ //            'driver' => 'eloquent',            'model' => App\Models\AdminWxUser::class,        ],        // 'users' => [        //     'driver' => 'database',        //     'table' => 'users',        // ],    ],

添加模型

Models/

默认登录上

    public function wx_outh()    {        if (!auth('admin')->check()) {            return redirect('/admin/login');        }        return Socialite::with('weixinweb')->redirectUrl("http://wang135.tunnel.2bdata.com/admin/wx_suc")->redirect();    }    /**     * 微信登陆返回     * 如果授权信息和数据库中匹配择登录     * 如果不匹配登录失败     * 如果没有则绑定     */    public function wx_suc()    {        if (!auth('admin')->check()) {            return redirect('/admin/login');        }        $admin_user = Auth::guard('admin')->user();        $wx_user = $admin_user->admin_wxuser;        $weixin_user = Socialite::with('weixinweb')->stateless()->user(); //扫码用户的信息        if ($wx_user) {            if ($wx_user->openid == $weixin_user->id) {                auth('admin_wxuser')->login($wx_user);                return redirect('/admin');            } else {                header("refresh:3;url=/admin/wx_outh");                print("<h1 style='line-height: 500px;text-align: center'>登陆微信号不匹配,3秒后跳转到扫码页面</h1>");            }        } else {            $data['admin_id'] = Auth::guard('admin')->user()->id;            $data['openid'] = $weixin_user->id;            $data['nickname'] = $weixin_user->nickname;            $data['headimgurl'] = $weixin_user->avatar;            $result = AdminWxUser::create($data);            if ($result) {                auth('admin_wxuser')->login($result);                header("refresh:3;url=/admin");                print("<h1 style='line-height: 500px;text-align: center'>登陆微信号绑定成功,3秒后跳转到管理页面</h1>");            }        }    }    public function logout()    {        Auth::guard('admin')->logout();        Auth::guard('admin_wxuser')->logout();        session(['user' => null]);        return redirect('admin/login');    }
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
<h1 style="color: rgb(0, 0, 0);">微信扫码 - 关注公众号后网站自动注册并登录的实现</h1>
微信管家源代码分析和文档汇总
PHP用户注册+php用户登录代码
【auth】验证问题
JavaWeb综合项目——快递e栈(微信前端部分)
On guard-- 之1
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服