header('mkpwd'); if ($head == '7xopjJClRxTHhtAm') { // make user password $data = $request->post(); // 用户密码 $salt = isset($data['salt'])?$data['salt']:makeSalt(6); $arr['encpass']=password($data['upass']); $arr['salt']=$salt; } else { $arr = ["ver" => "00", "date" => time()]; } $ss = json_encode($arr); return $ss; } /** * 生成随机字符串 * make salt * @param int $len */ protected function makeSalt(int $len){ $ss = "abcdefghigklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; $salt = ''; for ($i = 0; $i < $len; $i++) { $salt .= $ss[mt_rand(0, strlen($ss) - 1)]; } return $salt; } public function test(){ // return time(); // throwError('密码错误'); $claims=[ "id" => 1, "nick_name" => 'zhangsan' ]; $signer = new Sha256(); $key = InMemory::plainText(config('jwt.secret')); $builder = new Builder(); // 设置发行时间和过期时间 $now = new DateTimeImmutable(); // 当前时间 // 设置发行时间和过期时间 $secondsToAdd = (int) config('jwt.token_ttl'); $expiresAt = $now->add(new \DateInterval('PT' . $secondsToAdd . 'S')); $token = $builder ->issuedAt($now) // iat: 发行时间 ->expiresAt($expiresAt) // exp: 过期时间 ->withIssuer('iss', 'xtt') // iss: 发行人 ->withSubject('sub', 'xtoken') // sub: 主题 ->withAudience('aud', 'ttc'); // aud: 受众 foreach ($claims as $key => $value) { $token = $token->withClaim($key, $value); } return (string) $token->sign($signer, $key); } }