1234567891011121314151617181920212223242526272829303132333435363738 |
- <?php
- namespace app\common\util;
- class Encryption
- {
-
- public function createToken(int $id): string
- {
- $expireDays = 7;
-
- $time = (time() + 86400 * $expireDays);
- $signKey = env('TOKEN_KEY');
- $sign = md5($signKey . $id . $time);
- return base64_encode($sign . "|" . $id . "|" . $time);
- }
-
- public function getToken(): mixed
- {
- $token = null;
- if (!$token) {
- $token = request()->header("token");
- }
- if (!$token) {
- $token = input("token");
- }
- return $token;
- }
- }
|