Files
MBTI_wang/api/scripts/mint_jwt_for_smoke.js
卡若 ce55c48c64 feat: 同步今日小程序与后台迭代版本
集中提交今日 API、管理端、小程序与部署文档调整,确保 Gitea 主分支与本地最新开发版本一致。

Made-with: Cursor
2026-04-20 11:07:55 +08:00

31 lines
972 B
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env node
/**
* 生成与 JwtService::generateToken 同格式的 token签名段为 hex仅供本机冒烟。
* 读取 api/.env 中的 JWT_SECRET。
*/
const crypto = require('crypto')
const fs = require('fs')
const path = require('path')
const envPath = path.join(__dirname, '..', '.env')
let secret = 'mbti_jwt_secret_key_2024_change_in_production'
try {
const raw = fs.readFileSync(envPath, 'utf8')
const m = raw.match(/JWT_SECRET\s*=\s*(\S+)/)
if (m) secret = m[1].trim()
} catch (_) {}
const header = Buffer.from(JSON.stringify({ typ: 'JWT', alg: 'HS256' })).toString('base64')
const now = Math.floor(Date.now() / 1000)
const payload = Buffer.from(
JSON.stringify({
userId: 1,
user_id: 1,
source: 'wechat',
exp: now + 3600,
iat: now,
})
).toString('base64')
const sig = crypto.createHmac('sha256', secret).update(header + '.' + payload).digest('hex')
process.stdout.write(header + '.' + payload + '.' + sig + '\n')