modified: application/index/controller/Index.php

new file:   composer.phar
	renamed:    extend/Tools.php -> extend/king/Tools.php
	modified:   key/private.key
	modified:   key/public.key
	modified:   public/.htaccess
master
fengyuexingzi 8 years ago
parent d7157b0071
commit 70aa2f593d

@ -3,6 +3,8 @@
namespace app\index\controller; namespace app\index\controller;
use app\common\controller\Base; use app\common\controller\Base;
use Firebase\JWT\JWT;
use king\Tools;
class Index extends Base class Index extends Base
{ {
@ -48,4 +50,36 @@ class Index extends Base
} }
return json_encode($this->request->method()); 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'));
}
} }

Binary file not shown.

@ -9,7 +9,7 @@
namespace king; namespace king;
class Tools class Tools
{ {
function aes($data, $method = 'encrypt', $key = '', $iv = '') public static function aes($data, $method = 'encrypt', $key = '', $iv = '')
{ {
$key = $key ?: 'cTFbUKEMWHzP4yeRWpaXZf98NLY902IkxJ4XOuQIq1c='; $key = $key ?: 'cTFbUKEMWHzP4yeRWpaXZf98NLY902IkxJ4XOuQIq1c=';
$iv = $iv ?: 'Bqa1wCAKcFwFMsYF'; $iv = $iv ?: 'Bqa1wCAKcFwFMsYF';
@ -21,7 +21,7 @@ class Tools
return false; return false;
} }
function uuid() public static function uuid()
{ {
return bin2hex(openssl_random_pseudo_bytes(32)); return bin2hex(openssl_random_pseudo_bytes(32));
} }

Binary file not shown.

@ -4,7 +4,7 @@
RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [QSA,PT] RewriteRule ^(.*)$ index.php/$1 [QSA,PT]
RewriteCond %{HTTP_USER_AGENT} Mobile* [NC] RewriteCond %{HTTP_USER_AGENT} Mobile* [NC]
RewriteRule index.php mobile.php/$1 [QSA,PT,L] RewriteRule index.php mobile.php/$1 [QSA,PT,L]

Loading…
Cancel
Save