* 获取令牌剩余有效时间(小时) * @param {string} token - JWT令牌 * @returns {number} 剩余小时数,-1表示无效令牌
(token)
| 114 | */ |
| 115 | getTokenRemainingHours(token) { |
| 116 | const decoded = this.validateToken(token) |
| 117 | if (!decoded) return -1 |
| 118 | |
| 119 | const now = Math.floor(Date.now() / 1000) |
| 120 | const remainingSeconds = decoded.exp - now |
| 121 | return Math.max(0, Math.round(remainingSeconds / 3600)) |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * 刷新单个账户的令牌 |
| 126 | * @param {Object} account - 账户对象 {email, password, token, expires} |
no test coverage detected