1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <?php
- namespace App\Http\Middleware;
- use App\Exceptions\WapException;
- use App\Servers\CommonServer;
- use App\Servers\MemberServer;
- use App\Servers\WeixinServer;
- use Closure;
- class WapAuthMiddleware
- {
- /**
- * Handle an incoming request.
- *
- * @param \Illuminate\Http\Request $request
- * @param \Closure $next
- * @return mixed
- */
- public function handle($request, Closure $next)
- {
- // $request->session()->put('sadsads',['sadsa'=>'sasada']);
- // $request->session()->save();
- // dd( session()->all());
- //验证会员授权信息
- $clientRoute = request()->route()->getName();
- $is_wx=CommonServer::creatServer()->isWeixin();
- if (!in_array($clientRoute, ['member.wx_info','notify.shop_order']) && $is_wx) {
- $login_info=session('login_info');
- if(empty($login_info)){
- $wx_info = WeixinServer::creatServer()->authorize();
- if(!empty($wx_info)){
- $login_info = MemberServer::creatServer()->setWxOpen($wx_info);
- if(empty($login_info)){
- throw new WapException('登陆信息错误');
- }
- session()->put('login_info',$login_info);
- session()->save();
- }else{
- throw new WapException('微信信息获取失败');
- }
- }
- }
- return $next($request);
- }
- }
|