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
{ {
@ -34,7 +36,7 @@ class Index extends Base
$arr = []; $arr = [];
$arr1 = []; $arr1 = [];
$arr2 = []; $arr2 = [];
$arr3 = ['king'=>'best']; $arr3 = ['king' => 'best'];
//$arr = array_merge($arr1, $arr2, $arr3); //$arr = array_merge($arr1, $arr2, $arr3);
var_dump($arr); var_dump($arr);
} }
@ -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));
} }

@ -24,4 +24,4 @@ RuKl50Jye0GY6wCZeKw/pn1a+X2So4lr6WBcZ9xHPjscCOTbdYoIjQ15fI+P2NsS
4rRNqzkCgYARGIA5qZMfDX1ogTGQZ1ghF3vRiPpRkEdNgoAOEfV9kAC8f55a8t6i 4rRNqzkCgYARGIA5qZMfDX1ogTGQZ1ghF3vRiPpRkEdNgoAOEfV9kAC8f55a8t6i
8sKM/vUVAj8bvV1W/xUaVMKEh06wI5z4uBUj5R+8wuWNKSrCv6TG/Znq62A/AGwe 8sKM/vUVAj8bvV1W/xUaVMKEh06wI5z4uBUj5R+8wuWNKSrCv6TG/Znq62A/AGwe
hUlY+Em75lKV7Yn2ZbW6VT05l3zV/sIQhm5Xld98JFCqxCmkx08WXw== hUlY+Em75lKV7Yn2ZbW6VT05l3zV/sIQhm5Xld98JFCqxCmkx08WXw==
-----END RSA PRIVATE KEY----- -----END RSA PRIVATE KEY-----

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