diff --git a/application/index/controller/Index.php b/application/index/controller/Index.php index 8611df5..cb27b00 100644 --- a/application/index/controller/Index.php +++ b/application/index/controller/Index.php @@ -3,6 +3,8 @@ namespace app\index\controller; use app\common\controller\Base; +use Firebase\JWT\JWT; +use king\Tools; class Index extends Base { @@ -34,7 +36,7 @@ class Index extends Base $arr = []; $arr1 = []; $arr2 = []; - $arr3 = ['king'=>'best']; + $arr3 = ['king' => 'best']; //$arr = array_merge($arr1, $arr2, $arr3); var_dump($arr); } @@ -48,4 +50,36 @@ class Index extends Base } return json_encode($this->request->method()); } + + public function login() + { + + if ($this->request->isPost()) { + $username = 'king'; + $password = '123456'; + + $in_username = input('username', '', 'htmlspecialchars'); + $in_password = input('password', '', 'htmlspecialchars'); + + if ($username == $in_username && $password == $in_password) { + $payload = [ + 'exp' => time() + 3600, + 'iat' => time(), + 'jti' => Tools::aes($username), + ]; + $privateKey = openssl_pkey_get_private(file_get_contents('../key/private.key')); + $token = JWT::encode($payload, $privateKey, 'RS256'); + return $token; + } + } + } + + public function info() + { + $token = getallheaders()['Authorization']; + $privateKey = openssl_pkey_get_private(file_get_contents('../key/private.key')); + $publicKey = openssl_get_publickey(file_get_contents('../key/public.key')); + var_dump(JWT::decode($token, $publicKey, ['RS256'])); + var_dump(Tools::aes('it8jwp62HHlavuRM2trmIw==', 'decrypt')); + } } diff --git a/composer.phar b/composer.phar new file mode 100644 index 0000000..b324b82 Binary files /dev/null and b/composer.phar differ diff --git a/extend/Tools.php b/extend/king/Tools.php similarity index 85% rename from extend/Tools.php rename to extend/king/Tools.php index d820598..991b846 100644 --- a/extend/Tools.php +++ b/extend/king/Tools.php @@ -9,7 +9,7 @@ namespace king; class Tools { - function aes($data, $method = 'encrypt', $key = '', $iv = '') + public static function aes($data, $method = 'encrypt', $key = '', $iv = '') { $key = $key ?: 'cTFbUKEMWHzP4yeRWpaXZf98NLY902IkxJ4XOuQIq1c='; $iv = $iv ?: 'Bqa1wCAKcFwFMsYF'; @@ -21,7 +21,7 @@ class Tools return false; } - function uuid() + public static function uuid() { return bin2hex(openssl_random_pseudo_bytes(32)); } diff --git a/key/private.key b/key/private.key index 142fd6c..8279671 100644 --- a/key/private.key +++ b/key/private.key @@ -24,4 +24,4 @@ RuKl50Jye0GY6wCZeKw/pn1a+X2So4lr6WBcZ9xHPjscCOTbdYoIjQ15fI+P2NsS 4rRNqzkCgYARGIA5qZMfDX1ogTGQZ1ghF3vRiPpRkEdNgoAOEfV9kAC8f55a8t6i 8sKM/vUVAj8bvV1W/xUaVMKEh06wI5z4uBUj5R+8wuWNKSrCv6TG/Znq62A/AGwe hUlY+Em75lKV7Yn2ZbW6VT05l3zV/sIQhm5Xld98JFCqxCmkx08WXw== ------END RSA PRIVATE KEY----- +-----END RSA PRIVATE KEY----- \ No newline at end of file diff --git a/key/public.key b/key/public.key index e854384..9e7b5af 100644 Binary files a/key/public.key and b/key/public.key differ diff --git a/public/.htaccess b/public/.htaccess index bb81406..b15960c 100644 --- a/public/.htaccess +++ b/public/.htaccess @@ -4,7 +4,7 @@ RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f - RewriteRule ^(.*)$ index.php?/$1 [QSA,PT] + RewriteRule ^(.*)$ index.php/$1 [QSA,PT] RewriteCond %{HTTP_USER_AGENT} Mobile* [NC] RewriteRule index.php mobile.php/$1 [QSA,PT,L]