You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

206 lines
7.2 KiB

  1. <?php
  2. include __DIR__ . "/../vendor/autoload.php";
  3. use \Firebase\JWT\JWT;
  4. $key = "73937393";
  5. $privateKey = <<<EOD
  6. -----BEGIN RSA PRIVATE KEY-----
  7. MIICXgIBAAKBgQDsldu7vayXD7RE5HEMsvlz/tkq36gBgY1Yz+R9dkZWNDdQTTFm
  8. O2tWFwBvYRx5Nv/CtR1Nl2+pb/Nd6WrWzs9FR7P84nixA+vfzQjqTIlQViO0vB/a
  9. gWa2nk5N4e0dsQ7kDr3+7/w1DeFsMlRBDvSHMsdmlNSFDFB6+MVrC93dRQIDAQAB
  10. AoGBALhxeJZcIDLA7oSLKEuDOJEjDQGszhkmfCDSKstZKyrHmJwFIk8WYe8DDbbH
  11. meAybaDJfGfieQ46lhwP/tgq8VEM7m/bhkhksXHTuKmPGfr53uev9Rp1+TKG1vFW
  12. 2c8MFMrDg3ZNy8lAfZmhIWUP9ietU5o836d0/3vJ+nBeSZwhAkEA+0luT5ijhfh4
  13. Jim81h0yKJFOeg/gjdHtefAWyruAGHZEKz+yLNTPJN0bjPtQAOqSr/Hjt9MmxzPa
  14. HJ0DuvvgbQJBAPEF1mYmqmpBZTDc2zjOTXzVRsNO/bBcx/q9GkQydn/7BV6Dqr9Y
  15. cgJV49CWcbZBHLkCxyidKDvZBzTh0b/vWTkCQH3AsLianXLk9lO63WqVb82Hcit5
  16. mJnAbcRxFybbkG4teU3fcW4oDYXYNPpnphDfUwtD1P7gZ26XD1b0aLKBbD0CQQC3
  17. sCY9Rfyc7GgNfFTLD1e46uZ6VUo8zglPDC3niboMQahO5vQLzoFdTE5Km03gg/E7
  18. A2X7iwKt0fKPGAd+SxDpAkEA6OG77IL8cjrlZKk4ilTCz8rkF4CtZWbDLi1IF40i
  19. jaGlSLvVowHDywtjT8tYfpIH7HI55KS3gj88qAaF38qfRA==
  20. -----END RSA PRIVATE KEY-----
  21. EOD;
  22. $publicKey = <<<EOD
  23. -----BEGIN PUBLIC KEY-----
  24. MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDsldu7vayXD7RE5HEMsvlz/tkq
  25. 36gBgY1Yz+R9dkZWNDdQTTFmO2tWFwBvYRx5Nv/CtR1Nl2+pb/Nd6WrWzs9FR7P8
  26. 4nixA+vfzQjqTIlQViO0vB/agWa2nk5N4e0dsQ7kDr3+7/w1DeFsMlRBDvSHMsdm
  27. lNSFDFB6+MVrC93dRQIDAQAB
  28. -----END PUBLIC KEY-----
  29. EOD;
  30. $payload = [
  31. 'id' => 'backend',
  32. 'basePath' => dirname(__DIR__),
  33. 'controllerNamespace' => 'backend\controllers',
  34. 'bootstrap' => ['log'],
  35. 'components' => [
  36. 'assetManager' => [
  37. 'baseUrl' => '@web' . (getenv('KUBERNETES_NAMESPACE') ? '/' . getenv('KUBERNETES_NAMESPACE') : '') . '/assets'
  38. ],
  39. 'request' => [
  40. 'parsers' => [
  41. 'application/json' => 'yii\web\JsonParser',
  42. ],
  43. 'csrfParam' => '_csrf-api',
  44. ],
  45. 'user' => [
  46. 'identityClass' => 'backend\models\User',
  47. 'enableAutoLogin' => true,
  48. 'identityCookie' => ['name' => '_identity-backend', 'httpOnly' => true],
  49. ],
  50. 'session' => [
  51. // this is the name of the session cookie used for login on the app
  52. 'name' => 'backend',
  53. ],
  54. 'log' => [
  55. 'traceLevel' => 1,
  56. 'targets' => [
  57. [
  58. 'class' => 'yii\log\FileTarget',
  59. 'levels' => ['error', 'warning'],
  60. ],
  61. [
  62. 'class' => 'yii\log\FileTarget',
  63. 'levels' => ['info', 'error'],
  64. 'categories' => ['imagetest'],
  65. 'logFile' => '@app/runtime/logs/imagetest.log',
  66. 'logVars' => [],
  67. 'exportInterval' => 1,
  68. 'prefix' => function ($message) {
  69. }
  70. ],
  71. [
  72. 'class' => 'yii\log\FileTarget',
  73. 'levels' => ['error', 'warning', 'info'],
  74. 'categories' => ['refund_log'],
  75. 'logFile' => '@app/runtime/logs/refund_log.log',
  76. 'logVars' => [],
  77. 'exportInterval' => 1,
  78. 'prefix' => function ($message) {
  79. }
  80. ],
  81. [
  82. 'class' => 'yii\log\FileTarget',
  83. 'levels' => ['error', 'warning', 'info'],
  84. 'categories' => ['obj'],
  85. 'logFile' => '@app/runtime/logs/obj.log',
  86. 'logVars' => [],
  87. 'exportInterval' => 1,
  88. 'prefix' => function ($message) {
  89. }
  90. ],
  91. ],
  92. ],
  93. 'errorHandler' => [
  94. 'errorAction' => 'site/error',
  95. ],
  96. 'urlManager' => [
  97. 'enablePrettyUrl' => true,
  98. 'showScriptName' => false,
  99. 'rules' =>
  100. getenv('KUBERNETES_NAMESPACE') ? [
  101. getenv('KUBERNETES_NAMESPACE') . '/<rule:[\S-]+>' => '<rule>'
  102. ] : [],
  103. ],
  104. 'goods' => ['class' => 'goods\goods\logic\goods\GoodsManager'],
  105. ],
  106. 'as access' => [
  107. 'class' => 'iron\components\AccessControl',
  108. 'allowActions' => [
  109. 'site/catch-permission',
  110. ]
  111. ],
  112. 'params' => [
  113. 'assetManager' => [
  114. 'baseUrl' => '@web' . (getenv('KUBERNETES_NAMESPACE') ? '/' . getenv('KUBERNETES_NAMESPACE') : '') . '/assets'
  115. ],
  116. 'request' => [
  117. 'parsers' => [
  118. 'application/json' => 'yii\web\JsonParser',
  119. ],
  120. 'csrfParam' => '_csrf-api',
  121. ],
  122. 'user' => [
  123. 'identityClass' => 'backend\models\User',
  124. 'enableAutoLogin' => true,
  125. 'identityCookie' => ['name' => '_identity-backend', 'httpOnly' => true],
  126. ],
  127. 'session' => [
  128. // this is the name of the session cookie used for login on the app
  129. 'name' => 'backend',
  130. ],
  131. 'log' => [
  132. 'traceLevel' => 1,
  133. 'targets' => [
  134. [
  135. 'class' => 'yii\log\FileTarget',
  136. 'levels' => ['error', 'warning'],
  137. ],
  138. [
  139. 'class' => 'yii\log\FileTarget',
  140. 'levels' => ['info', 'error'],
  141. 'categories' => ['imagetest'],
  142. 'logFile' => '@app/runtime/logs/imagetest.log',
  143. 'logVars' => [],
  144. 'exportInterval' => 1,
  145. 'prefix' => function ($message) {
  146. }
  147. ],
  148. [
  149. 'class' => 'yii\log\FileTarget',
  150. 'levels' => ['error', 'warning', 'info'],
  151. 'categories' => ['refund_log'],
  152. 'logFile' => '@app/runtime/logs/refund_log.log',
  153. 'logVars' => [],
  154. 'exportInterval' => 1,
  155. 'prefix' => function ($message) {
  156. }
  157. ],
  158. [
  159. 'class' => 'yii\log\FileTarget',
  160. 'levels' => ['error', 'warning', 'info'],
  161. 'categories' => ['obj'],
  162. 'logFile' => '@app/runtime/logs/obj.log',
  163. 'logVars' => [],
  164. 'exportInterval' => 1,
  165. 'prefix' => function ($message) {
  166. }
  167. ],
  168. ],
  169. ],
  170. 'errorHandler' => [
  171. 'errorAction' => 'site/error',
  172. ],
  173. 'urlManager' => [
  174. 'enablePrettyUrl' => true,
  175. 'showScriptName' => false,
  176. 'rules' =>
  177. getenv('KUBERNETES_NAMESPACE') ? [
  178. getenv('KUBERNETES_NAMESPACE') . '/<rule:[\S-]+>' => '<rule>'
  179. ] : [],
  180. ],
  181. 'goods' => ['class' => 'goods\goods\logic\goods\GoodsManager'],
  182. ],
  183. ];
  184. $jwt = JWT::encode($payload, $privateKey, 'RS256');
  185. echo strlen($jwt) . "\n";
  186. echo "Encode:\n" . print_r($jwt, true) . "\n";
  187. $decoded = JWT::decode($jwt, $publicKey, array('RS256'));
  188. $decoded_array = (array) $decoded;
  189. echo "Decode:\n" . print_r($decoded_array, true) . "\n";