Create API route and update match page for recruitment, resource linkage, and mentor consultant features #VERCEL_SKIP Co-authored-by: null <4804959+fnvtk@users.noreply.github.com>
96 lines
2.6 KiB
TypeScript
96 lines
2.6 KiB
TypeScript
import { type NextRequest, NextResponse } from "next/server"
|
|
import crypto from "crypto"
|
|
|
|
// 存客宝API配置
|
|
const CKB_CONFIG = {
|
|
apiKey: "fyngh-ecy9h-qkdae-epwd5-rz6kd",
|
|
apiUrl: "https://ckbapi.quwanzhi.com/v1/api/scenarios",
|
|
}
|
|
|
|
// 生成签名
|
|
function generateSign(apiKey: string, timestamp: number): string {
|
|
const signStr = `${apiKey}${timestamp}`
|
|
return crypto.createHash("md5").update(signStr).digest("hex")
|
|
}
|
|
|
|
// 不同场景的source和tags配置
|
|
const SCENARIO_CONFIG: Record<string, { source: string; tags: string }> = {
|
|
team: {
|
|
source: "卡若创业实验-切片团队招募",
|
|
tags: "切片团队,团队招募,创业合作",
|
|
},
|
|
resource: {
|
|
source: "卡若创业实验-资源对接",
|
|
tags: "资源对接,资源群,商业合作",
|
|
},
|
|
mentor: {
|
|
source: "卡若创业实验-导师顾问",
|
|
tags: "导师顾问,创业指导,商业咨询",
|
|
},
|
|
}
|
|
|
|
export async function POST(request: NextRequest) {
|
|
try {
|
|
const body = await request.json()
|
|
const { phone, name, scenario, remark } = body
|
|
|
|
// 验证必填参数
|
|
if (!phone) {
|
|
return NextResponse.json({ success: false, message: "手机号不能为空" }, { status: 400 })
|
|
}
|
|
|
|
if (!scenario || !SCENARIO_CONFIG[scenario]) {
|
|
return NextResponse.json({ success: false, message: "无效的场景类型" }, { status: 400 })
|
|
}
|
|
|
|
// 生成时间戳和签名
|
|
const timestamp = Math.floor(Date.now() / 1000)
|
|
const sign = generateSign(CKB_CONFIG.apiKey, timestamp)
|
|
|
|
// 获取场景配置
|
|
const config = SCENARIO_CONFIG[scenario]
|
|
|
|
// 构建请求体
|
|
const requestBody = {
|
|
apiKey: CKB_CONFIG.apiKey,
|
|
sign,
|
|
timestamp,
|
|
phone,
|
|
name: name || "",
|
|
source: config.source,
|
|
remark: remark || `来自${config.source}`,
|
|
tags: config.tags,
|
|
}
|
|
|
|
// 调用存客宝API
|
|
const response = await fetch(CKB_CONFIG.apiUrl, {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify(requestBody),
|
|
})
|
|
|
|
const result = await response.json()
|
|
|
|
if (response.ok && result.code === 0) {
|
|
return NextResponse.json({
|
|
success: true,
|
|
message: "提交成功,我们会尽快与您联系",
|
|
data: result.data,
|
|
})
|
|
} else {
|
|
return NextResponse.json(
|
|
{
|
|
success: false,
|
|
message: result.message || "提交失败,请稍后重试",
|
|
},
|
|
{ status: 400 },
|
|
)
|
|
}
|
|
} catch (error) {
|
|
console.error("存客宝API调用失败:", error)
|
|
return NextResponse.json({ success: false, message: "服务器错误,请稍后重试" }, { status: 500 })
|
|
}
|
|
}
|