|
|
<?php
include __DIR__ . "/../vendor/autoload.php";
use \Firebase\JWT\JWT;
$key = "73937393";
$privateKey = <<<EOD -----BEGIN RSA PRIVATE KEY----- MIICXgIBAAKBgQDsldu7vayXD7RE5HEMsvlz/tkq36gBgY1Yz+R9dkZWNDdQTTFm O2tWFwBvYRx5Nv/CtR1Nl2+pb/Nd6WrWzs9FR7P84nixA+vfzQjqTIlQViO0vB/a gWa2nk5N4e0dsQ7kDr3+7/w1DeFsMlRBDvSHMsdmlNSFDFB6+MVrC93dRQIDAQAB AoGBALhxeJZcIDLA7oSLKEuDOJEjDQGszhkmfCDSKstZKyrHmJwFIk8WYe8DDbbH meAybaDJfGfieQ46lhwP/tgq8VEM7m/bhkhksXHTuKmPGfr53uev9Rp1+TKG1vFW 2c8MFMrDg3ZNy8lAfZmhIWUP9ietU5o836d0/3vJ+nBeSZwhAkEA+0luT5ijhfh4 Jim81h0yKJFOeg/gjdHtefAWyruAGHZEKz+yLNTPJN0bjPtQAOqSr/Hjt9MmxzPa HJ0DuvvgbQJBAPEF1mYmqmpBZTDc2zjOTXzVRsNO/bBcx/q9GkQydn/7BV6Dqr9Y cgJV49CWcbZBHLkCxyidKDvZBzTh0b/vWTkCQH3AsLianXLk9lO63WqVb82Hcit5 mJnAbcRxFybbkG4teU3fcW4oDYXYNPpnphDfUwtD1P7gZ26XD1b0aLKBbD0CQQC3 sCY9Rfyc7GgNfFTLD1e46uZ6VUo8zglPDC3niboMQahO5vQLzoFdTE5Km03gg/E7 A2X7iwKt0fKPGAd+SxDpAkEA6OG77IL8cjrlZKk4ilTCz8rkF4CtZWbDLi1IF40i jaGlSLvVowHDywtjT8tYfpIH7HI55KS3gj88qAaF38qfRA== -----END RSA PRIVATE KEY----- EOD;
$publicKey = <<<EOD -----BEGIN PUBLIC KEY----- MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDsldu7vayXD7RE5HEMsvlz/tkq 36gBgY1Yz+R9dkZWNDdQTTFmO2tWFwBvYRx5Nv/CtR1Nl2+pb/Nd6WrWzs9FR7P8 4nixA+vfzQjqTIlQViO0vB/agWa2nk5N4e0dsQ7kDr3+7/w1DeFsMlRBDvSHMsdm lNSFDFB6+MVrC93dRQIDAQAB -----END PUBLIC KEY----- EOD;
$payload = [ 'id' => 'backend', 'basePath' => dirname(__DIR__), 'controllerNamespace' => 'backend\controllers', 'bootstrap' => ['log'], 'components' => [ 'assetManager' => [ 'baseUrl' => '@web' . (getenv('KUBERNETES_NAMESPACE') ? '/' . getenv('KUBERNETES_NAMESPACE') : '') . '/assets' ], 'request' => [ 'parsers' => [ 'application/json' => 'yii\web\JsonParser', ], 'csrfParam' => '_csrf-api', ], 'user' => [ 'identityClass' => 'backend\models\User', 'enableAutoLogin' => true, 'identityCookie' => ['name' => '_identity-backend', 'httpOnly' => true], ], 'session' => [ // this is the name of the session cookie used for login on the app
'name' => 'backend', ], 'log' => [ 'traceLevel' => 1, 'targets' => [ [ 'class' => 'yii\log\FileTarget', 'levels' => ['error', 'warning'], ], [ 'class' => 'yii\log\FileTarget', 'levels' => ['info', 'error'], 'categories' => ['imagetest'], 'logFile' => '@app/runtime/logs/imagetest.log', 'logVars' => [], 'exportInterval' => 1, 'prefix' => function ($message) { } ], [ 'class' => 'yii\log\FileTarget', 'levels' => ['error', 'warning', 'info'], 'categories' => ['refund_log'], 'logFile' => '@app/runtime/logs/refund_log.log', 'logVars' => [], 'exportInterval' => 1, 'prefix' => function ($message) { } ], [ 'class' => 'yii\log\FileTarget', 'levels' => ['error', 'warning', 'info'], 'categories' => ['obj'], 'logFile' => '@app/runtime/logs/obj.log', 'logVars' => [], 'exportInterval' => 1, 'prefix' => function ($message) { } ], ], ], 'errorHandler' => [ 'errorAction' => 'site/error', ], 'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => getenv('KUBERNETES_NAMESPACE') ? [ getenv('KUBERNETES_NAMESPACE') . '/<rule:[\S-]+>' => '<rule>' ] : [], ], 'goods' => ['class' => 'goods\goods\logic\goods\GoodsManager'], ], 'as access' => [ 'class' => 'iron\components\AccessControl', 'allowActions' => [ 'site/catch-permission', ] ], 'params' => [ 'assetManager' => [ 'baseUrl' => '@web' . (getenv('KUBERNETES_NAMESPACE') ? '/' . getenv('KUBERNETES_NAMESPACE') : '') . '/assets' ], 'request' => [ 'parsers' => [ 'application/json' => 'yii\web\JsonParser', ], 'csrfParam' => '_csrf-api', ], 'user' => [ 'identityClass' => 'backend\models\User', 'enableAutoLogin' => true, 'identityCookie' => ['name' => '_identity-backend', 'httpOnly' => true], ], 'session' => [ // this is the name of the session cookie used for login on the app
'name' => 'backend', ], 'log' => [ 'traceLevel' => 1, 'targets' => [ [ 'class' => 'yii\log\FileTarget', 'levels' => ['error', 'warning'], ], [ 'class' => 'yii\log\FileTarget', 'levels' => ['info', 'error'], 'categories' => ['imagetest'], 'logFile' => '@app/runtime/logs/imagetest.log', 'logVars' => [], 'exportInterval' => 1, 'prefix' => function ($message) { } ], [ 'class' => 'yii\log\FileTarget', 'levels' => ['error', 'warning', 'info'], 'categories' => ['refund_log'], 'logFile' => '@app/runtime/logs/refund_log.log', 'logVars' => [], 'exportInterval' => 1, 'prefix' => function ($message) { } ], [ 'class' => 'yii\log\FileTarget', 'levels' => ['error', 'warning', 'info'], 'categories' => ['obj'], 'logFile' => '@app/runtime/logs/obj.log', 'logVars' => [], 'exportInterval' => 1, 'prefix' => function ($message) { } ], ], ], 'errorHandler' => [ 'errorAction' => 'site/error', ], 'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => getenv('KUBERNETES_NAMESPACE') ? [ getenv('KUBERNETES_NAMESPACE') . '/<rule:[\S-]+>' => '<rule>' ] : [], ], 'goods' => ['class' => 'goods\goods\logic\goods\GoodsManager'], ], ];
$jwt = JWT::encode($payload, $privateKey, 'RS256'); echo strlen($jwt) . "\n"; echo "Encode:\n" . print_r($jwt, true) . "\n";
$decoded = JWT::decode($jwt, $publicKey, array('RS256'));
$decoded_array = (array) $decoded; echo "Decode:\n" . print_r($decoded_array, true) . "\n";
|