composer安装 composer require firebase/php-jwt $id, "iss" => env('TOKEN.iss'),//签发组织 "aud" => env('TOKEN.aud'), //签发作者` "iat" => $time, "nbf" => $time, "exp" => $expire ); $jwt = JWTUtil::encode($token, $key); return success('生成秘钥', $jwt); } public function verifyjwt($jwt) { // $jwt = input("jwt"); $key = md5(env('TOKEN.key', 'yxw')); //jwt的签发密钥,验证token的时候需要用到 try { $jwtAuth = json_encode(JWTUtil::decode($jwt, $key, array("HS256"))); $authInfo = json_decode($jwtAuth, true); if (!$authInfo['user_id']) { return fail('未找到用户'); } return success('ok'); } catch (ExpiredException $e) { return fail('token过期'); } catch (Exception $e) { return fail('错误信息', $e->getMessage()); } } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)