在上篇文章中我们讲了使用微信公众号的原生接口来实现微信登录获取用户信息。
这篇文章主要是实现使用Easywechat来实现微信授权获取用户信息
github地址:https://github.com/overtrue/laravel-wechat
easywechat文档地址:https://www.easywechat.com/docs/master/integration
安装Easywechat,注意自己的版本

laravel查看自己的框架版本号命令
php artisan --version

查询这个后我们在进行Easywechat的安装
# Laravel < 5.8composer require "overtrue/laravel-wechat:~4.0"# Laravel >= 5.8composer require "overtrue/laravel-wechat:~5.0"

安装完之后需要创建配置文件
php artisan vendor:publish --provider="Overtrue\LaravelWeChat\ServiceProvider"

然后可以在路由文件中输出app()->getBindings();打印出所绑定的所有服务;这些服务都是绑定在Contrants中的binging属性中,你会发现在里面可以看到有wechat的信息;证明wechat引用成功

先在根据config/wechat.php中的配置文件配置好微信参数内容

然后测试
地址栏地址是域名+blog/public/index.php/weChat

这样就OK了

下来使用中间件实现
添加中间件的配置在 app/Http/Kernel.php 中添加路由中间件

然后添加路由测试


本文分享自微信公众号 - PHP初学者必看(PHP0022)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。
来源:oschina
链接:https://my.oschina.net/u/3828348/blog/4505554