后端: - 新增 leai 模块:认证、Webhook、数据同步、定时对账 - 新增 LeaiConfig/RestTemplateConfig/SchedulingConfig 配置 - 新增 FlywayRepairConfig 处理迁移修复 - 新增 V5__leai_integration.sql 迁移脚本 - 扩展所有实体类添加 tenantId 等字段 - 更新 SecurityConfig 放行 leai 公开接口 - 添加 application-test.yml 测试环境配置 前端: - 添加乐读派认证 API (public.ts) - 优化 Generating.vue 生成页 - 添加 Playwright E2E 测试配置及依赖 - 添加测试 fixtures、utils、mock-h5.html - 添加 leai 模块完整 E2E 测试套件 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
37 lines
1000 B
TypeScript
37 lines
1000 B
TypeScript
import crypto from 'crypto'
|
|
|
|
/**
|
|
* HMAC-SHA256 签名工具
|
|
* 与乐读派 Demo 的签名逻辑对齐
|
|
*/
|
|
|
|
/** 计算 HMAC-SHA256 并返回 hex 字符串 */
|
|
export function hmacSha256(data: string, secret: string): string {
|
|
return crypto.createHmac('sha256', secret).update(data).digest('hex')
|
|
}
|
|
|
|
/** 构造 Webhook 请求头(含签名) */
|
|
export function buildWebhookHeaders(
|
|
webhookId: string,
|
|
body: string,
|
|
appSecret: string,
|
|
eventType = 'work.status_changed',
|
|
) {
|
|
const timestamp = Date.now().toString()
|
|
const signData = `${webhookId}.${timestamp}.${body}`
|
|
const signature = `HMAC-SHA256=${hmacSha256(signData, appSecret)}`
|
|
|
|
return {
|
|
'X-Webhook-Id': webhookId,
|
|
'X-Webhook-Event': eventType,
|
|
'X-Webhook-Timestamp': timestamp,
|
|
'X-Webhook-Signature': signature,
|
|
'Content-Type': 'application/json',
|
|
}
|
|
}
|
|
|
|
/** 生成随机事件 ID */
|
|
export function randomEventId(): string {
|
|
return `evt_test_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`
|
|
}
|