// * This source file is subject to the license under the project that is bundled. // */ //namespace App\Kernel\Jwt; // //use App\Model\User; //use Firebase\JWT\JWT as JwtSdk; //use Hyperf\Contract\ConfigInterface; //use Hyperf\Di\Annotation\Inject; //use Youyao\Framework\Logger\LoggerApp; // //class Jwt //{ // /** // * @Inject // * @var ConfigInterface // */ // private $config; // // public function generate(User $user) # 数据表 // { // $payload = [ // 'iss' => 'youyao-management', // 'aud' => 'youyao-employees', // 'iat' => time(), // 'exp' => time() + $this->config->get('jwt.token_expires'), // 'nbf' => time(), // 'sub' => $user->getAttribute('id'), // ]; // try { // return JwtSdk::encode($payload, $this->config->get('jwt.key')); // } catch (\Exception $e) { // LoggerApp::error($e->getMessage(), $e->getTrace()); // return false; // } // } // // public function decode(string $token) // { // try { // return (array) JwtSdk::decode($token, $this->config->get('jwt.key'), ['HS256']); // } catch (\Exception $e) { // LoggerApp::error($e->getMessage(), $e->getTrace()); // return false; // } // } //}