| 12345678910111213141516171819202122232425262728293031323334353637 | 
							- <?php
 
- namespace app\common\controller;
 
- use app\common\exception\CatchException;
 
- use think\facade\Log;
 
- trait JwtAuthorizedTrait
 
- {
 
-     
 
-     protected $payload;
 
-     public function initialize()
 
-     {
 
-         parent::initialize();
 
-         
 
-         $jwt = $this->request->header('Authorization');
 
-         if (!$jwt) {
 
-             throw new CatchException("请登录", 600);
 
-         }
 
-         
 
-         $jwt = str_replace('Bearer ', '', $jwt);
 
-         Log::debug("尝试解析Jwt: " . var_export($jwt, true));
 
-         $this->payload = $this->decodeJwt($jwt);
 
-         
 
-         if (method_exists($this, 'init')) {
 
-             $this->init();
 
-         }
 
-     }
 
- }
 
 
  |