lmxdawn / php-jwt
jwt package for thinkphp5.0
This package's canonical repository appears to be gone and the package has been frozen as a result.
Installs: 1 020
Dependents: 0
Suggesters: 0
Security: 0
Stars: 18
Watchers: 2
Forks: 2
Open Issues: 0
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2023-03-04 18:54:29 UTC
README
登陆认证、web api接口调用 token
安装
composer require lmxdawn/php-jwt
示例
$key = "example_key"; $time = time(); //var_dump($time);exit; $token = array( "iss" => "http://example.org",//该JWT的签发者 "aud" => "http://example.com",//接收该JWT的一方 "sub" => "xxx@example.com",//该JWT所面向的用户 "iat" => $time,//在什么时候签发的 "exp" => $time,// 什么时候过期,这里是一个Unix时间戳 ); echo '<pre>'; $jwt = \lmxdawn\jwt\JWT::encode($token, $key,'HS256'); try{ $decoded = \lmxdawn\jwt\JWT::decode($jwt, $key, array('HS256')); var_dump($decoded);exit; }catch (Exception $exception){ echo '失败'; } exit; print_r($decoded); $decoded_array = (array) $decoded; /** * 您可以添加一个余地来考虑当存在倍之间的时钟偏差,最好不超过几分钟 */ \lmxdawn\jwt\JWT::$leeway = 60; // $leeway in seconds $decoded = \lmxdawn\jwt\JWT::decode($jwt, $key, array('HS256')); print_r($decoded);