Skip to content

Commit 5cd8fa4

Browse files
authored
Update README.md
1 parent 3ffb15d commit 5cd8fa4

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

README.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,39 @@ $ php think jwt:make
2525

2626
3. 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

3842
4. Token 验证(手动)
3943
```php
40-
use xiaodi\Jwt;
44+
use xiaodi\Facade\Jwt;
45+
use xiaodi\Exception\HasLoggedException;
46+
use xiaodi\Exception\TokenAlreadyEexpired;
4147

4248
class 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

0 commit comments

Comments
 (0)