author:咔咔
wechat:fangkangfk
微信公衆号:PHP初學者必看
如有圖檔問題不顯示,請轉移至公衆号檢視
文章位址:https://mp.weixin.qq.com/s/YdbZwruySpGEP-V7VhZDLQ
在上篇文章中我們講了使用微信公衆号的原生接口來實作微信登入擷取使用者資訊。
這篇文章主要是實作使用Easywechat來實作微信授權擷取使用者資訊
github位址:https://github.com/overtrue/laravel-wechat
easywechat文檔位址:https://www.easywechat.com/docs/master/integration
安裝Easywechat,注意自己的版本

laravel檢視自己的架構版本号指令
php artisan --version
查詢這個後我們在進行Easywechat的安裝
# Laravel < 5.8 composer require "overtrue/laravel-wechat:~4.0" # Laravel >= 5.8 composer 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 中添加路由中間件
然後添加路由測試