OfficialCheck.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace App\Http\Middleware;
  3. use Closure;
  4. use Illuminate\Support\Facades\Auth;
  5. /**
  6. * 公众号检查,获取支付openid
  7. * Class OfficialCheck
  8. * @package App\Http\Middleware
  9. * Auth Zhong
  10. * Date 2019/2/22
  11. */
  12. class OfficialCheck
  13. {
  14. /**
  15. * OfficialCheck constructor.
  16. */
  17. public function __construct()
  18. {
  19. }
  20. /**
  21. * Handle an incoming request.
  22. *
  23. * @param \Illuminate\Http\Request $request
  24. * @param \Closure $next
  25. * @return mixed
  26. */
  27. public function handle($request, Closure $next)
  28. {
  29. if (is_weixin() && config('aix.system.pay.wechat.is_on') == 1) {
  30. if (!$request->session()->has('wechat_pay_openid')) {
  31. if ($request->route()->getName() != 'mobile.auth.thirdlogin.official.openid') {
  32. session(['wechat_pay_redirect_url' => $request->fullUrl()]);
  33. session(['wechat_pay_state' => time()]);
  34. $wechat_url = "https://open.weixin.qq.com/connect/oauth2/authorize?"
  35. . "appid=" . config('aix.system.pay.wechat.appid')
  36. . "&redirect_uri=" . urlencode(route('mobile.auth.thirdlogin.official.openid'))
  37. . "&response_type=code&scope=snsapi_base&state=" . session('wechat_pay_state') . "#wechat_redirect";
  38. return redirect($wechat_url);
  39. }
  40. }
  41. }
  42. return $next($request);
  43. }
  44. }