File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -25,29 +25,39 @@ $ php think jwt:make
2525
26263 . Token 生成
2727``` php
28- use xiaodi\Jwt;
28+ use xiaodi\Facade\ Jwt;
2929
30- public function login(Jwt $jwt )
30+ public function login()
3131{
3232 //...登录判断逻辑
3333
34- $token = $jwt->getToken();
34+ return json([
35+ 'token' => Jwt::token(['uid' => 1]),
36+ 'token_type' => Jwt::type(),
37+ 'expires_in' => Jwt::ttl()
38+ ]);
3539}
3640```
3741
38424 . Token 验证(手动)
3943``` php
40- use xiaodi\Jwt;
44+ use xiaodi\Facade\Jwt;
45+ use xiaodi\Exception\HasLoggedException;
46+ use xiaodi\Exception\TokenAlreadyEexpired;
4147
4248class User {
4349
44- public function test(Jwt $jwt )
50+ public function test()
4551 {
4652 try {
47- $jwt->verify($token);
48- } catch (\Exception $e) {
49- var_dump($e->getMessage());
53+ Jwt::verify($token);
54+ } catch (HasLoggedException $e) {
55+ // 已在其它终端登录
56+ } catch (TokenAlreadyEexpired $e) {
57+ // Token已过期
5058 }
59+
60+ // 验证成功
5161 }
5262}
5363
You can’t perform that action at this time.
0 commit comments