WapAuthMiddleware.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace App\Http\Middleware;
  3. use App\Exceptions\WapException;
  4. use App\Servers\CommonServer;
  5. use App\Servers\MemberServer;
  6. use App\Servers\WeixinServer;
  7. use Closure;
  8. class WapAuthMiddleware
  9. {
  10. /**
  11. * Handle an incoming request.
  12. *
  13. * @param \Illuminate\Http\Request $request
  14. * @param \Closure $next
  15. * @return mixed
  16. */
  17. public function handle($request, Closure $next)
  18. {
  19. // $request->session()->put('sadsads',['sadsa'=>'sasada']);
  20. // $request->session()->save();
  21. // dd( session()->all());
  22. //验证会员授权信息
  23. $clientRoute = request()->route()->getName();
  24. $is_wx=CommonServer::creatServer()->isWeixin();
  25. if (!in_array($clientRoute, ['member.wx_info','notify.shop_order']) && $is_wx) {
  26. $login_info=session('login_info');
  27. if(empty($login_info)){
  28. $wx_info = WeixinServer::creatServer()->authorize();
  29. if(!empty($wx_info)){
  30. $login_info = MemberServer::creatServer()->setWxOpen($wx_info);
  31. if(empty($login_info)){
  32. throw new WapException('登陆信息错误');
  33. }
  34. session()->put('login_info',$login_info);
  35. session()->save();
  36. }else{
  37. throw new WapException('微信信息获取失败');
  38. }
  39. }
  40. }
  41. return $next($request);
  42. }
  43. }