|
@@ -0,0 +1,72 @@
|
|
|
|
+<?php
|
|
|
|
+/**
|
|
|
|
+ * Created by PhpStorm.
|
|
|
|
+ * User: Administrator
|
|
|
|
+ * Date: 2019-06-05
|
|
|
|
+ * Time: 18:30
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+namespace App\Http\Middleware;
|
|
|
|
+
|
|
|
|
+use App\Traits\ShopInfoTrait;
|
|
|
|
+use Closure;
|
|
|
|
+use Tymon\JWTAuth\Exceptions\JWTException;
|
|
|
|
+use Tymon\JWTAuth\Exceptions\TokenExpiredException;
|
|
|
|
+use Tymon\JWTAuth\Exceptions\TokenInvalidException;
|
|
|
|
+use Tymon\JWTAuth\Facades\JWTAuth;
|
|
|
|
+
|
|
|
|
+class VerifyShopMiddleware {
|
|
|
|
+ use ShopInfoTrait;
|
|
|
|
+ /**
|
|
|
|
+ * Handle an incoming request.
|
|
|
|
+ *
|
|
|
|
+ * @param \Illuminate\Http\Request $request
|
|
|
|
+ * @param \Closure $next
|
|
|
|
+ * @return mixed
|
|
|
|
+ */
|
|
|
|
+ public function handle($request, Closure $next)
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ $token = JWTAuth::decode(JWTAuth::getToken());
|
|
|
|
+ if(!empty($token)){
|
|
|
|
+ if($token['type'] == 2){
|
|
|
|
+ $shop = Shop::where(['shop_id'=>$token['shop']->shop_id])->first();
|
|
|
|
+ if($shop->status == 0){
|
|
|
|
+ $error = [
|
|
|
|
+ 'message' => '商户已禁用,禁止操作',
|
|
|
|
+ 'code' => 401,
|
|
|
|
+ ];
|
|
|
|
+ return response()->json($error);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //$data = JWTAuth::decode($token);
|
|
|
|
+ } catch (TokenExpiredException $e) {
|
|
|
|
+ $error = [
|
|
|
|
+ 'message' => 'Token is Expired',
|
|
|
|
+ 'code' => 401,
|
|
|
|
+ ];
|
|
|
|
+ return response()->json($error);
|
|
|
|
+ } catch (TokenInvalidException $e) {
|
|
|
|
+ $error = [
|
|
|
|
+ 'message' => $e->getMessage(),
|
|
|
|
+ 'code' => 401,
|
|
|
|
+ ];
|
|
|
|
+ return response()->json($error);
|
|
|
|
+ } catch (JWTException $e) {
|
|
|
|
+ $error = [
|
|
|
|
+ 'message' => $e->getMessage(),
|
|
|
|
+ 'code' => 401,
|
|
|
|
+ ];
|
|
|
|
+ return response()->json($error);
|
|
|
|
+ }catch (\Exception $e){
|
|
|
|
+ $error = [
|
|
|
|
+ 'message' => $e->getMessage(),
|
|
|
|
+ 'code' => 401,
|
|
|
|
+ ];
|
|
|
|
+ return response()->json($error);
|
|
|
|
+ }
|
|
|
|
+ return $next($request);
|
|
|
|
+ }
|
|
|
|
+}
|